Skip to content

Commit

Permalink
feat: add richThumbnails (animated thumbnails) to related videos (#850
Browse files Browse the repository at this point in the history
)

* Add rich thumbnail (animated thumbnail) to related videos

* Optimizations, corrected tests, added richThumbnail to refresh.js

* Properly check for richThumbnails
  • Loading branch information
Aasim-A committed Jan 1, 2021
1 parent 7b2efa3 commit bf06869
Show file tree
Hide file tree
Showing 8 changed files with 14,345 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/info-extras.js
Expand Up @@ -193,6 +193,9 @@ exports.getRelatedVideos = info => {
Math.floor(parseTimestamp(getText(details.lengthText)) / 1000) :
rvsParams && `${rvsParams.length_seconds}`,
thumbnails: details.thumbnail.thumbnails,
richThumbnails:
details.richThumbnail ?
details.richThumbnail.movingThumbnailRenderer.movingThumbnailDetails.thumbnails : [],
isLive: !!(details.badges && details.badges.find(b => b.metadataBadgeRenderer.label === 'LIVE NOW')),
};

Expand Down
6 changes: 6 additions & 0 deletions lib/info.js
Expand Up @@ -43,6 +43,12 @@ const AGE_RESTRICTED_URLS = [
*/
exports.getBasicInfo = async(id, options) => {
const retryOptions = Object.assign({}, miniget.defaultOptions, options.requestOptions);
options.requestOptions = Object.assign({}, options.requestOptions, {});
options.requestOptions.headers = Object.assign({},
{
// eslint-disable-next-line max-len
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Safari/537.36',
}, options.requestOptions.headers);
const validate = info => {
let playErr = utils.playError(info.player_response, ['ERROR'], UnrecoverableError);
let privateErr = privateVideoError(info.player_response);
Expand Down
36 changes: 36 additions & 0 deletions test/basic-info-test.js
Expand Up @@ -3,6 +3,8 @@ const assert = require('assert-diff');
const nock = require('./nock');
const miniget = require('miniget');

const DEFAULT_USER_AGENT =
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Safari/537.36';

describe('ytdl.getBasicInfo()', () => {
let minigetDefaults = miniget.defaultOptions;
Expand Down Expand Up @@ -83,6 +85,40 @@ describe('ytdl.getBasicInfo()', () => {
assert.strictEqual(info2, info1);
});
});

describe('With user-agent header', () => {
it('Uses default user-agent if no user-agent is provided', async() => {
const id = '_HSylqgVYQI';
const scope = nock(id, 'rich-thumbnails', {
headers: {
'User-Agent': DEFAULT_USER_AGENT,
},
watchHtml: false,
player: false,
});
await ytdl.getBasicInfo(id);
scope.done();
});

it('Uses provided user-agent instead of default', async() => {
const id = '_HSylqgVYQI';
const scope = nock(id, 'regular', {
headers: {
'User-Agent': 'yay',
},
watchHtml: false,
player: false,
});
await ytdl.getBasicInfo(id, {
requestOptions: {
headers: {
'User-Agent': 'yay',
},
},
});
scope.done();
});
});
});

describe('From a live video', () => {
Expand Down
7 changes: 7 additions & 0 deletions test/files/refresh.js
Expand Up @@ -89,6 +89,13 @@ const videos = [
type: 'no-likes-or-dislikes',
skip: ['get_video_info', /player/],
},
{
id: '_HSylqgVYQI',
type: 'rich-thumbnails',
basicInfo: true,
saveInfo: true,
skip: ['watch.html', /player/],
},
{
id: 'z2jeHsa0UG0',
type: 'private',
Expand Down

0 comments on commit bf06869

Please sign in to comment.