YouTube.js
YouTube.js copied to clipboard
Check if duration exists
This prevents the following for live and upcoming videos:
{text: 'N/A', seconds: NaN}
Please fix the type error.
The issue can be reproduced by adding a live video to the Watch Later playlist:
const VIDEO_ID = "jfKfPfyJRdk";
const PLAYLIST_ID = "WL";
await yt.playlist.addVideos(PLAYLIST_ID, [VIDEO_ID]);
const playlist = await yt.getPlaylist(PLAYLIST_ID);
for (const item of playlist.items) {
if (item.type === "PlaylistVideo" && item.id === VIDEO_ID) {
console.log(`Duration of video ${VIDEO_ID}`, item.duration);
break;
}
}