Skip to content

Instantly share code, notes, and snippets.

@dytroc
Created January 19, 2023 12:31
Show Gist options
  • Select an option

  • Save dytroc/d4bef81ae4b4157f0d8224730cc8e1d6 to your computer and use it in GitHub Desktop.

Select an option

Save dytroc/d4bef81ae4b4157f0d8224730cc8e1d6 to your computer and use it in GitHub Desktop.
Download all of the thumbnails of all YouTube videos of the selected channel
const axios = require('axios'); // `npm i axios` or `yarn add axios`
const fs = require('fs');
const apiKey = '(API KEY HERE)';
const channelId = '(CHANNEL ID HERE)';
async function getParams(extra) {
return (await axios.get(`https://youtube.googleapis.com/youtube/v3/search?part=snippet&channelId=${channelId}&maxResults=50&order=date&safeSearch=none&type=video&key=${apiKey}${extra}`)).data;
}
(async () => {
let extra = '';
do {
const result = await getParams(extra);
Promise.all(result.items.map(async ({ id: { videoId }, snippet: { publishedAt } }) => {
try {
const date = publishedAt.split('T')[0];
(await axios({ method: 'get', responseType: 'stream', url: `https://img.youtube.com/vi/${videoId}/maxresdefault.jpg` })).data.pipe(fs.createWriteStream(`thumbnails/${date}.png`));
} catch (error) {}
}));
extra = result.nextPageToken ? '&pageToken=' + result.nextPageToken : '';
} while (extra);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment