APIs like Contenda often times only accept a YouTube VideoId. This snippet returns an array of just the VideoIds so you can wrap a for loop around and call whichever API you'd like!
const {google} = require('googleapis');
const apiKey = process.env.apiKey;
const playlistUrl = 'https://www.youtube.com/playlist?list=PLAYLIST_ID';
// Extract the playlist ID from the URL
const playlistId = playlistUrl.split('list=')[1];
// Function to get video IDs from a playlist
async function getPlaylistVideoIds(playlistId) {
const youtube = google.youtube({
version: 'v3',
auth: apiKey
})
const response = await youtube.playlistItems.list({
key: apiKey,
part: 'snippet',
maxResults: 50,
playlistId,
});
const videoIds = response.data.items.map(
(item) => item.snippet.resourceId.videoId
);
console.log(videoIds);
}
await getPlaylistVideoIds(playlistId);