From 8a35d7aa4a0382771ed2df634e83186b66312564 Mon Sep 17 00:00:00 2001 From: fent <933490+fent@users.noreply.github.com> Date: Thu, 17 Dec 2020 20:03:04 -0700 Subject: [PATCH] feat: add `videoDetails.description` and `videoDetails.thumbnails` this adds deprecation warnings to `videoDetails.shortDescription` and `videoDetails.thumbnail` --- lib/info-extras.js | 19 ++++++++++++++++++- lib/info.js | 4 ++-- lib/utils.js | 1 - test/basic-info-test.js | 4 ++-- typings/index.d.ts | 3 ++- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/info-extras.js b/lib/info-extras.js index 2d70f218..766556cf 100644 --- a/lib/info-extras.js +++ b/lib/info-extras.js @@ -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; @@ -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; +}; diff --git a/lib/info.js b/lib/info.js index 2e183545..254bb54e 100644 --- a/lib/info.js +++ b/lib/info.js @@ -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; }; diff --git a/lib/utils.js b/lib/utils.js index f336890a..f17179c8 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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; diff --git a/test/basic-info-test.js b/test/basic-info-test.js index 60c4b541..2f6e87ff 100644 --- a/test/basic-info-test.js +++ b/test/basic-info-test.js @@ -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); }); @@ -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(); diff --git a/typings/index.d.ts b/typings/index.d.ts index 86c2d9bf..0cb425fa 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -191,7 +191,7 @@ declare module 'ytdl-core' { uploadDate: string; } - interface MoreVideoDetails extends Omit, Omit { + interface MoreVideoDetails extends Omit, Omit { published: number; video_url: string; age_restricted: boolean; @@ -199,6 +199,7 @@ declare module 'ytdl-core' { dislikes?: number; media: Media; author: Author; + thumbnails: thumbnail[]; } interface videoInfo {