Last active
September 12, 2019 17:08
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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