diff --git a/lib/info-extras.js b/lib/info-extras.js index cd2d75cf..0c3cb84b 100644 --- a/lib/info-extras.js +++ b/lib/info-extras.js @@ -268,9 +268,10 @@ exports.getDislikes = info => { * Cleans up a few fields on `videoDetails`. * * @param {Object} videoDetails + * @param {Object} info * @returns {Object} */ -exports.cleanVideoDetails = videoDetails => { +exports.cleanVideoDetails = (videoDetails, info) => { videoDetails.thumbnails = videoDetails.thumbnail.thumbnails; delete videoDetails.thumbnail; utils.deprecate(videoDetails, 'thumbnail', { thumbnails: videoDetails.thumbnails }, @@ -279,6 +280,11 @@ exports.cleanVideoDetails = videoDetails => { delete videoDetails.shortDescription; utils.deprecate(videoDetails, 'shortDescription', videoDetails.description, 'videoDetails.shortDescription', 'videoDetails.description'); + + // Use more reliable `lengthSeconds` from `playerMicroformatRenderer`. + videoDetails.lengthSeconds = + info.player_response.microformat && + info.player_response.microformat.playerMicroformatRenderer.lengthSeconds; return videoDetails; }; diff --git a/lib/info.js b/lib/info.js index befb5d1b..67a58f91 100644 --- a/lib/info.js +++ b/lib/info.js @@ -87,7 +87,7 @@ exports.getBasicInfo = async(id, options) => { 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), info); return info; }; diff --git a/test/basic-info-test.js b/test/basic-info-test.js index 5d0ab56c..c8f79738 100644 --- a/test/basic-info-test.js +++ b/test/basic-info-test.js @@ -195,6 +195,18 @@ describe('ytdl.getBasicInfo()', () => { }); }); + describe('From the longest video uploaded', () => { + it('Gets correct `lengthSeconds`', async() => { + const id = 'TceijYjxdrQ'; + const scope = nock(id, 'longest-upload'); + let info = await ytdl.getBasicInfo(id); + scope.done(); + assert.ok(info); + assert.ok(info.videoDetails); + assert.equal(info.videoDetails.lengthSeconds, '805000'); + }); + }); + describe('With cookie headers', () => { const id = '_HSylqgVYQI'; describe('`x-youtube-identity-token` given', () => { diff --git a/test/files/refresh.js b/test/files/refresh.js index 7b58f3d3..d090a793 100644 --- a/test/files/refresh.js +++ b/test/files/refresh.js @@ -107,6 +107,11 @@ const videos = [ basicInfo: true, saveInfo: true, }, + { + id: 'TceijYjxdrQ', + type: 'longest-upload', + basicInfo: true, + }, ]; diff --git a/test/files/videos/longest-upload/watch.html b/test/files/videos/longest-upload/watch.html new file mode 100644 index 00000000..903c4417 --- /dev/null +++ b/test/files/videos/longest-upload/watch.html @@ -0,0 +1,67 @@ +Longest YouTube video!! - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new features
\ No newline at end of file