Skip to content

Commit

Permalink
fix: fix age restricted videos
Browse files Browse the repository at this point in the history
closes #803
  • Loading branch information
fent committed Dec 2, 2020
1 parent 3ced5ac commit 84d5118
Show file tree
Hide file tree
Showing 10 changed files with 17,399 additions and 1,724 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -146,7 +146,6 @@ ytdl cannot download videos that fall into the following
* Regionally restricted (requires a [proxy](example/proxy.js))
* Private (if you have access, requires [cookies](example/cookies.js))
* Rentals (if you have access, requires [cookies](example/cookies.js))
* Age restricted, requires [cookies](example/cookies.js))

Generated download links are valid for 6 hours, and may only be downloadable from the same IP address.

Expand Down
3 changes: 1 addition & 2 deletions lib/info.js
Expand Up @@ -42,8 +42,7 @@ const AGE_RESTRICTED_URLS = [
exports.getBasicInfo = async(id, options) => {
const retryOptions = Object.assign({}, miniget.defaultOptions, options.requestOptions);
const isValid = info =>
info.player_response && (utils.playError(info.player_response, ['LOGIN_REQUIRED']) ||
info.player_response.streamingData || isRental(info.player_response));
info.player_response && (info.player_response.streamingData || isRental(info.player_response));
let info = await pipeline([id, options], retryOptions, isValid, [
getJSONWatchPage,
getEmbedPage,
Expand Down
19 changes: 0 additions & 19 deletions test/download-test.js
Expand Up @@ -661,25 +661,6 @@ describe('Download video', () => {
});
});

describe('From an age restricted video', () => {
it('Stream emits an error', done => {
const id = 'LuZu9N53Vd0';
const scope = nock(id, 'age-restricted');
let stream = ytdl(id);
stream.on('error', err => {
scope.done();
assert.strictEqual(err.message, 'Sign in to confirm your age');
done();
});
stream.on('data', () => {
done(Error('should not emit `data`'));
});
stream.on('end', () => {
done(Error('should not emit `end`'));
});
});
});

describe('With no formats', () => {
it('Stream emits an error', done => {
const id = '_HSylqgVYQI';
Expand Down
16 changes: 16 additions & 0 deletions test/files/videos/age-restricted/embed.html

Large diffs are not rendered by default.

10,395 changes: 8,698 additions & 1,697 deletions test/files/videos/age-restricted/expected-info.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/files/videos/age-restricted/get_video_info

Large diffs are not rendered by default.

8,675 changes: 8,675 additions & 0 deletions test/files/videos/age-restricted/player_ias.vflset.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions test/files/videos/age-restricted/watch.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion test/info-test.js
Expand Up @@ -112,14 +112,15 @@ describe('ytdl.getInfo()', () => {
});

describe('From an age restricted video', () => {
it('Returns correct video metainfo', async() => {
it('Returns correct video metainfo with formats', async() => {
const expected = require('./files/videos/age-restricted/expected-info.json');
const id = 'LuZu9N53Vd0';
const scope = nock(id, 'age-restricted');
let info = await ytdl.getInfo(id);
scope.done();
assert.strictEqual(info.formats.length, expected.formats.length);
assert.ok(info.videoDetails.age_restricted);
assert.ok(info.formats.length);
});
});

Expand Down
2 changes: 2 additions & 0 deletions test/irl-test.js
Expand Up @@ -5,6 +5,8 @@ const ytdl = require('..');

const videos = {
'Regular video': 'mgOS64BF2eU',
'Age restricted': 'LuZu9N53Vd0',
'Embed domain restricted': 'B3eAMGXFw1o',
'No embed allowed': 'GFg8BP01F5Q',
Offensive: 'hCKDsjLt_qU',
'Live broadcast': '5qap5aO4i9A',
Expand Down

0 comments on commit 84d5118

Please sign in to comment.