Skip to content

Commit

Permalink
fix: properly check if video is age restricted
Browse files Browse the repository at this point in the history
  • Loading branch information
fent committed Nov 16, 2020
1 parent ea63582 commit d3a5a69
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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?/, '</script>');
Expand All @@ -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;
};
Expand Down
2 changes: 2 additions & 0 deletions test/info-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
Expand Down Expand Up @@ -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);
});
});
});
Expand Down

0 comments on commit d3a5a69

Please sign in to comment.