@@ -6,10 +6,9 @@ import ModalActions from './../components/Modal/actions';
66import torrentActions from './../actions/torrentActions' ;
77import Promise from 'bluebird' ;
88import _ from 'lodash' ;
9- import ytdl from 'youtube-dl ' ;
9+ import sources from './../components/Player/utils/sources.js ' ;
1010import ytdlSupported from './../components/Player/utils/ytdl-extractor' ;
1111import plugins from './plugins' ;
12- import ls from 'local-storage' ;
1312
1413module . exports = ( inputvalue ) => {
1514 return new Promise ( ( resolve , reject ) => {
@@ -60,36 +59,24 @@ module.exports = (inputvalue) => {
6059 } ) , 1000 ) ;
6160 } else {
6261 // try youtube-dl with it, use media scanner as a fallback
63- var ytdlArgs = [ '-g' ] ;
64-
65- if ( ls ( 'ytdlQuality' ) < 4 ) {
66- var qualities = [ 360 , 480 , 720 , 1080 ] ;
67- ytdlArgs . push ( '-f' ) ;
68- ytdlArgs . push ( '[height <=? ' + qualities [ ls ( 'ytdlQuality' ) ] + ']' ) ;
69- }
70-
71- var video = ytdl ( parsed . url , ytdlArgs ) ;
72-
73- video . on ( 'error' , function ( err ) {
74- ModalActions . close ( ) ;
75- console . log ( 'ytdl ending error' ) ;
76- reject ( new Error ( 'Error: Invalid URL' ) ) ;
77- } ) ;
78-
79- video . on ( 'info' , function ( info ) {
62+ sources . youtubeDL ( parsed . url , function ( info ) {
8063 if ( info . url ) {
8164 ModalActions . close ( ) ;
8265 console . log ( info ) ;
8366 PlayerActions . addPlaylist ( [ {
8467 originalURL : inputvalue ,
85- uri : parsed . url ,
68+ uri : info . url ,
8669 youtubeDL : true ,
8770 image : info . thumbnail ,
8871 title : info . fulltitle
8972 } ] ) ;
9073 resolve ( parsed . url ) ;
9174 } else parseLinks ( plugin && plugin . checkFor ? plugin : null ) ;
92- } ) ;
75+ } , function ( err ) {
76+ ModalActions . close ( ) ;
77+ console . log ( 'ytdl ending error' ) ;
78+ reject ( new Error ( 'Error: Invalid URL' ) ) ;
79+ } )
9380 }
9481
9582 }
@@ -110,26 +97,22 @@ module.exports = (inputvalue) => {
11097 if ( perfectMatch || ytdlSupported ( parsed . url ) ) {
11198 // a perfect match or a youtube-dl regex match should be
11299 // sent directly to youtube-dl for processing
113- var video = ytdl ( parsed . url , [ '-g' ] ) ;
114-
115- video . on ( 'error' , function ( err ) {
116- parseLinks ( plugin && plugin . checkFor ? plugin : null ) ;
117- } ) ;
118-
119- video . on ( 'info' , function ( info ) {
100+ sources . youtubeDL ( parsed . url , function ( info ) {
120101 if ( info . url ) {
121102 ModalActions . close ( ) ;
122103 console . log ( info ) ;
123104 PlayerActions . addPlaylist ( [ {
124105 originalURL : inputvalue ,
125- uri : parsed . url ,
106+ uri : info . url ,
126107 youtubeDL : true ,
127108 image : info . thumbnail ,
128109 title : info . fulltitle
129110 } ] ) ;
130111 resolve ( parsed . url ) ;
131112 } else parseLinks ( plugin && plugin . checkFor ? plugin : null ) ;
132- } ) ;
113+ } , function ( err ) {
114+ parseLinks ( plugin && plugin . checkFor ? plugin : null ) ;
115+ } )
133116
134117 } else {
135118 parseLinks ( plugin && plugin . checkFor ? plugin : null ) ;
0 commit comments