Skip to content

Commit

Permalink
[Player] Adds duration to videos from YouTube playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeyaworski committed Oct 8, 2023
1 parent b1687cb commit 518323f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/commands/player/youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,24 @@ export async function parseYoutubePlaylistFromApi(playlistUrl: string): Promise<
});
numPagesFetched += 1;
nextPageToken = res.data.nextPageToken;
const youtubeResults: { link: string, title: string }[] = res.data.items
interface Result {
link: string,
details: VideoDetails,
}
const youtubeResults: Result[] = res.data.items
.filter((item: IntentionalAny) => item.snippet?.resourceId?.kind === 'youtube#video')
.map((item: IntentionalAny) => ({
link: `https://youtube.com/watch?v=${item.snippet?.resourceId.videoId}`,
title: item.snippet?.title,
details: {
title: item.snippet?.title,
duration: undefined, // TODO: The duration is not available in this API endpoint, so we have to get it elsewhere
},
}));
tracks.push(...youtubeResults.map(({ link, title }) => new Track({
tracks.push(...youtubeResults.map(({ link, details }) => new Track({

Check warning on line 118 in src/commands/player/youtube.ts

View workflow job for this annotation

GitHub Actions / test

'details' is defined but never used
link,
variant: TrackVariant.YOUTUBE_VOD,
details: {
title,
},
// TODO: Temporarily commented out until we write an alternate way to get the video duration
// details,
})));
} while (nextPageToken && numPagesFetched < MAX_YT_PLAYLIST_PAGE_FETCHES);

Expand All @@ -134,6 +140,7 @@ export async function parseYoutubePlaylist(playlistUrl: string): Promise<Track[]
variant: TrackVariant.YOUTUBE_VOD,
details: video.title ? {
title: video.title,
duration: video.duration,
} : undefined,
}));
}
Expand Down

0 comments on commit 518323f

Please sign in to comment.