Skip to content

Instantly share code, notes, and snippets.

@yevhenorlov
Last active September 12, 2019 17:08
Show Gist options
  • Save yevhenorlov/9f1443deb59019a557db0b87d0ec532e to your computer and use it in GitHub Desktop.
Save yevhenorlov/9f1443deb59019a557db0b87d0ec532e to your computer and use it in GitHub Desktop.
get a map of titles and thumbnail urls from a youtube playlist (up to 50 results)
const axios = require('axios')
async function getYoutubePlaylistSnippets({ APIKey, playlistId }) {
const playlistItemsUrl = 'https://www.googleapis.com/youtube/v3/playlistItems'
const {
data: { items }
} = await axios.get(playlistItemsUrl, {
params: { playlistId, part: 'snippet', maxResults: 50, key: APIKey }
})
return items
}
function getTitleUrlMap(items) {
return items.reduce((acc, el) => {
const { url } = el.snippet.thumbnails.medium
const { title } = el.snippet
acc[title] = url
return acc
}, {})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment