From d3a5a69c59b3a7c12b04e52a1d589c65ed7359ed Mon Sep 17 00:00:00 2001 From: fent <933490+fent@users.noreply.github.com> Date: Mon, 16 Nov 2020 01:50:57 -0700 Subject: [PATCH] fix: properly check if video is age restricted --- lib/info.js | 8 +++++--- test/info-test.js | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/info.js b/lib/info.js index 55ca6813..cbd2827e 100644 --- a/lib/info.js +++ b/lib/info.js @@ -122,7 +122,7 @@ const pipeline = async(args, retryOptions, isValid, endpoints) => { let info; for (let func of endpoints) { try { - const newInfo = await retryFunc(func, args, retryOptions); + const newInfo = await retryFunc(func, args.concat([info]), retryOptions); if (newInfo.player_response) { newInfo.player_response.videoDetails = assign( info && info.player_response && info.player_response.videoDetails, @@ -270,7 +270,7 @@ const getJSONWatchPage = async(id, options) => { */ const EMBED_URL = 'https://www.youtube.com/embed/'; const getEmbedURL = (id, options) => `${EMBED_URL + id}?hl=${options.lang || 'en'}`; -const getEmbedPage = async(id, options) => { +const getEmbedPage = async(id, options, watchPageInfo) => { const embedUrl = getEmbedURL(id, options); let body = await miniget(embedUrl, options.requestOptions).text(); let jsonStr = utils.between(body, /(['"])PLAYER_(CONFIG|VARS)\1:\s?/, ''); @@ -280,7 +280,9 @@ const getEmbedPage = async(id, options) => { let config = parseJSON('embed config', utils.cutAfterJSON(jsonStr)); let info = config.args || config; info.player_response = findPlayerResponse('embed `player_response`', info); - info.player_response.videoDetails = Object.assign({}, info.player_response.videoDetails, { age_restricted: true }); + info.player_response.videoDetails = Object.assign({}, info.player_response.videoDetails, { + age_restricted: watchPageInfo && !!utils.playError(watchPageInfo.player_response, ['LOGIN_REQUIRED']), + }); info.html5player = getHTML5player(body); return info; }; diff --git a/test/info-test.js b/test/info-test.js index 77d926be..c00827e4 100644 --- a/test/info-test.js +++ b/test/info-test.js @@ -409,6 +409,7 @@ describe('ytdl.getInfo()', () => { assert.ok(info.html5player); assert.ok(info.formats.length); assert.ok(info.formats[0].url); + assert.ok(!info.videoDetails.age_restricted); }); }); }); @@ -441,6 +442,7 @@ describe('ytdl.getInfo()', () => { assert.ok(info.html5player); assert.ok(info.formats.length); assert.ok(info.formats[0].url); + assert.ok(!info.videoDetails.age_restricted); }); }); });