Skip to content

Commit

Permalink
feat: add videoDetails.description and videoDetails.thumbnails
Browse files Browse the repository at this point in the history
this adds deprecation warnings to `videoDetails.shortDescription` and
`videoDetails.thumbnail`
  • Loading branch information
fent committed Dec 18, 2020
1 parent bf8fa4a commit 8a35d7a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
19 changes: 18 additions & 1 deletion lib/info-extras.js
Expand Up @@ -181,7 +181,6 @@ exports.getRelatedVideos = info => {
verified: isVerified(details.ownerBadges),

[Symbol.toPrimitive]() {
// eslint-disable-next-line no-console
console.warn(`\`relatedVideo.author\` will be removed in a near future release, ` +
`use \`relatedVideo.author.name\` instead.`);
return video.author.name;
Expand Down Expand Up @@ -248,3 +247,21 @@ exports.getDislikes = info => {
return null;
}
};

/**
* Cleans up a few fields on `videoDetails`.
*
* @param {Object} videoDetails
* @returns {Object}
*/
exports.cleanVideoDetails = videoDetails => {
videoDetails.thumbnails = videoDetails.thumbnail.thumbnails;
delete videoDetails.thumbnail;
utils.deprecate(videoDetails, 'thumbnail', { thumbnails: videoDetails.thumbnails },
'videoDetails.thumbnail.thumbnails', 'videoDetails.thumbnails');
videoDetails.description = videoDetails.shortDescription || getText(videoDetails.description);
delete videoDetails.shortDescription;
utils.deprecate(videoDetails, 'shortDescription', videoDetails.description,
'videoDetails.shortDescription', 'videoDetails.description');
return videoDetails;
};
4 changes: 2 additions & 2 deletions lib/info.js
Expand Up @@ -77,10 +77,10 @@ exports.getBasicInfo = async(id, options) => {
video_url: VIDEO_URL + id,
};

info.videoDetails = Object.assign({},
info.videoDetails = extras.cleanVideoDetails(Object.assign({},
info.player_response && info.player_response.microformat &&
info.player_response.microformat.playerMicroformatRenderer,
info.player_response && info.player_response.videoDetails, additional);
info.player_response && info.player_response.videoDetails, additional));

return info;
};
Expand Down
1 change: 0 additions & 1 deletion lib/utils.js
Expand Up @@ -131,7 +131,6 @@ exports.playError = (player_response, statuses, ErrorType = Error) => {
exports.deprecate = (obj, prop, value, oldPath, newPath) => {
Object.defineProperty(obj, prop, {
get: () => {
// eslint-disable-next-line no-console
console.warn(`\`${oldPath}\` will be removed in a near future release, ` +
`use \`${newPath}\` instead.`);
return value;
Expand Down
4 changes: 2 additions & 2 deletions test/basic-info-test.js
Expand Up @@ -19,7 +19,7 @@ describe('ytdl.getBasicInfo()', () => {
});
let info = await ytdl.getBasicInfo(id);
scope.done();
assert.ok(info.videoDetails.shortDescription.length);
assert.ok(info.videoDetails.description.length);
assert.strictEqual(info.formats.length, expected.formats.length);
});

Expand Down Expand Up @@ -76,7 +76,7 @@ describe('ytdl.getBasicInfo()', () => {
player: false,
});
let info1 = await ytdl.getBasicInfo(id);
assert.ok(info1.videoDetails.shortDescription.length);
assert.ok(info1.videoDetails.description.length);
assert.strictEqual(info1.formats.length, expected.formats.length);
let info2 = await ytdl.getBasicInfo(id);
scope.done();
Expand Down
3 changes: 2 additions & 1 deletion typings/index.d.ts
Expand Up @@ -191,14 +191,15 @@ declare module 'ytdl-core' {
uploadDate: string;
}

interface MoreVideoDetails extends Omit<VideoDetails, 'author'>, Omit<MicroformatRenderer, 'title' | 'description'> {
interface MoreVideoDetails extends Omit<VideoDetails, 'author' | 'thumbnail' | 'shortDescription'>, Omit<MicroformatRenderer, 'title' | 'description'> {
published: number;
video_url: string;
age_restricted: boolean;
likes?: number;
dislikes?: number;
media: Media;
author: Author;
thumbnails: thumbnail[];
}

interface videoInfo {
Expand Down

0 comments on commit 8a35d7a

Please sign in to comment.