1- const urllib = require ( 'url' ) ;
1+ const { URL } = require ( 'url' ) ;
22const querystring = require ( 'querystring' ) ;
33const sax = require ( 'sax' ) ;
44const miniget = require ( 'miniget' ) ;
@@ -12,7 +12,7 @@ const sig = require('./sig');
1212const Cache = require ( './cache' ) ;
1313
1414
15- const VIDEO_URL = 'https://www.youtube.com/watch?v=' ;
15+ const BASE_URL = 'https://www.youtube.com/watch?v=' ;
1616
1717
1818// Cached for storing basic/full info.
@@ -80,7 +80,7 @@ exports.getBasicInfo = async(id, options) => {
8080 age_restricted : ! ! ( media && media . notice_url && AGE_RESTRICTED_URLS . some ( url => media . notice_url . includes ( url ) ) ) ,
8181
8282 // Give the standard link to the video.
83- video_url : VIDEO_URL + id ,
83+ video_url : BASE_URL + id ,
8484 storyboards : extras . getStoryboards ( info ) ,
8585 } ;
8686
@@ -116,7 +116,7 @@ const isNotYetBroadcasted = player_response => {
116116} ;
117117
118118
119- const getWatchHTMLURL = ( id , options ) => `${ VIDEO_URL + id } &hl=${ options . lang || 'en' } ` ;
119+ const getWatchHTMLURL = ( id , options ) => `${ BASE_URL + id } &hl=${ options . lang || 'en' } ` ;
120120const getWatchHTMLPageBody = ( id , options ) => {
121121 const url = getWatchHTMLURL ( id , options ) ;
122122 return exports . watchPageCache . getOrSet ( url , ( ) => miniget ( url , options . requestOptions ) . text ( ) ) ;
@@ -323,19 +323,13 @@ const INFO_HOST = 'www.youtube.com';
323323const INFO_PATH = '/get_video_info' ;
324324const VIDEO_EURL = 'https://youtube.googleapis.com/v/' ;
325325const getVideoInfoPage = async ( id , options ) => {
326- const url = urllib . format ( {
327- protocol : 'https' ,
328- host : INFO_HOST ,
329- pathname : INFO_PATH ,
330- query : {
331- video_id : id ,
332- eurl : VIDEO_EURL + id ,
333- ps : 'default' ,
334- gl : 'US' ,
335- hl : options . lang || 'en' ,
336- } ,
337- } ) ;
338- let body = await miniget ( url , options . requestOptions ) . text ( ) ;
326+ const url = new URL ( `https://${ INFO_HOST } ${ INFO_PATH } ` ) ;
327+ url . searchParams . set ( 'video_id' , id ) ;
328+ url . searchParams . set ( 'eurl' , VIDEO_EURL + id ) ;
329+ url . searchParams . set ( 'ps' , 'default' ) ;
330+ url . searchParams . set ( 'gl' , 'US' ) ;
331+ url . searchParams . set ( 'hl' , options . lang || 'en' ) ;
332+ let body = await miniget ( url . toString ( ) , options . requestOptions ) . text ( ) ;
339333 let info = querystring . parse ( body ) ;
340334 info . player_response = findPlayerResponse ( 'get_video_info' , info ) ;
341335 return info ;
@@ -378,7 +372,7 @@ exports.getInfo = async(id, options) => {
378372 if ( ! info . html5player ) {
379373 throw Error ( 'Unable to find html5player file' ) ;
380374 }
381- const html5player = urllib . resolve ( VIDEO_URL , info . html5player ) ;
375+ const html5player = new URL ( info . html5player , BASE_URL ) . toString ( ) ;
382376 funcs . push ( sig . decipherFormats ( info . formats , html5player , options ) ) ;
383377 }
384378 if ( hasManifest && info . player_response . streamingData . dashManifestUrl ) {
@@ -432,7 +426,7 @@ const getDashManifest = (url, options) => new Promise((resolve, reject) => {
432426 }
433427 } ;
434428 parser . onend = ( ) => { resolve ( formats ) ; } ;
435- const req = miniget ( urllib . resolve ( VIDEO_URL , url ) , options . requestOptions ) ;
429+ const req = miniget ( new URL ( url , BASE_URL ) . toString ( ) , options . requestOptions ) ;
436430 req . setEncoding ( 'utf8' ) ;
437431 req . on ( 'error' , reject ) ;
438432 req . on ( 'data' , chunk => { parser . write ( chunk ) ; } ) ;
@@ -448,8 +442,8 @@ const getDashManifest = (url, options) => new Promise((resolve, reject) => {
448442 * @returns {Promise<Array.<Object>> }
449443 */
450444const getM3U8 = async ( url , options ) => {
451- url = urllib . resolve ( VIDEO_URL , url ) ;
452- let body = await miniget ( url , options . requestOptions ) . text ( ) ;
445+ url = new URL ( url , BASE_URL ) ;
446+ let body = await miniget ( url . toString ( ) , options . requestOptions ) . text ( ) ;
453447 let formats = { } ;
454448 body
455449 . split ( '\n' )
0 commit comments