async function getUploads(channel, auth) { const id = channel.snippet.resourceId.channelId; // get list of all channel uploads const channelInfo = await service.channels.list({ id, auth, part: 'contentDetails' }); // destructure the uploads playlist (all channel videos) const { contentDetails: { relatedPlaylists: { uploads } } } = channelInfo.data.items[0]; const { data: { items } } = await service.playlistItems.list({ playlistId: uploads, auth, part: 'snippet', maxResults: 50 // 50 is the max }); items.forEach(getNewVideos); }
batch.map((batchItems) => ( // Fetch data from YouTube youtube.channels.list({ part: 'snippet,contentDetails,statistics', id: batchItems, maxResults: 50, }) .then((ytResult) => { // Sanity check for YouTube respons contents if (!ytResult.data || !ytResult.data.items) { return Promise.reject(new GenericError('YouTube response error', ytResult)); } // Return the array of channel information within the response return ytResult.data.items; }) .catch((err) => { // Log error information, and the channels included in the API that failed log.error('channelInfo() YouTube fetch error', { error: err.toString(), batchItems, }); return []; }) ))