simple-youtube-api
simple-youtube-api copied to clipboard
Videos from playlists have no duration object
Explanation
Any video from a playlist does not include the duration object or the durationSeconds variable.
Reproduction
- Get a playlist
- Get its videos
- Try and get duration
- Returns
undefined(or-1if using durationSeconds)
Example
const YouTube = require('simple-youtube-api');
const yt = new YouTube(process.env.yt);
yt.getVideo('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
.then(vid => {
console.log(`This video's duration is ${vid.duration.minutes}:${vid.duration.seconds}, which is ${vid.durationSeconds} in seconds.`);
})
.catch(console.error);
yt.getPlaylist('https://www.youtube.com/playlist?list=PLFMaGYddBw_Majo82Cdhc_QKFlxXDyL8E')
.then(pl => {
pl.getVideos()
.then(vids => {
const vid = vids[0];
console.log(`This playlist video's duration is ${vid.duration}, which is ${vid.durationSeconds} in seconds.`);
})
.catch(console.error);
})
.catch(console.error);
Running this will return:
This video's duration is 3:33, which is 213 in seconds.
This playlist video's duration is undefined, which is -1 in seconds.
can you check what vids[0].full is equal to? i suspect that this is because you don't have a full video object
Returns false. ...why does it return without the full object, is that a limit of the API?
I believe this is just to save on data usage, but i could be wrong. To get the duration you need to do vids[0].fetch() then get the duration from the result of that
That's the current workaround I'm thinking of right now. What I'm trying to do though (get all videos from a playlist and save them to a queue, for a discord music bot) would require fetching every single video individually all at once, which will obviously hit the rate limit pretty quickly. Having this in the playlist object would very easily fix this problem.