async fetchList (id) { const res = await this.api.playlistItems.list({ part: 'snippet,contentDetails', maxResults: 50, playlistId: id }).catch((err) => { console.log('[error] Something bad happened.') console.log('[error-info]', err) throw {code: -1, msg: 'Something bad happened.'} }) const items = res.data.items const songList = [] console.log('[info] List length: ' + items.length) for (const item of items) { var id = item.snippet.resourceId.videoId var song_data = await this.fetchVideo(id).catch((err) => { if(err.code < 0) throw err }) if(song_data) { songList.push(song_data) } } console.log('[info] Finish retrieving list.') return songList }
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); }
const ytData = await youtube.playlistItems.list({ part: 'id,snippet', playlistId,