async fetchVideo (id) { const res = await this.api.videos.list({ part: 'snippet,contentDetails', id: id }).catch((err) => { console.log('[error] Something bad happened.') console.log('[error-info]', err) throw {code: -1, msg: 'Something bad happened.'} }) if (res.data.items.length == 0) { throw {code: 2, msg: 'Song cannot be accessed.'} } var title = res.data.items[0].snippet.title var url = 'https://youtu.be/' + id var duration = res.data.items[0].contentDetails.duration var song_data = { id: id, title: title, url: url, duration: duration } return song_data }
youtube.videos.list({ part: 'liveStreamingDetails', id: targetVideos.map((targetVideo) => targetVideo.yt_video_key).join(','), hl: 'ja', fields: 'items(id,liveStreamingDetails)', maxResults: 50, }) .then((ytResult) => { // Sanity check for YouTube respons contents if (!ytResult.data || !ytResult.data.items) { return Promise.reject(new GenericError('Invalid YouTube response', ytResult)); } // Return video list only return ytResult.data.items; }) .catch((err) => { // Log error information log.error('videoStatusAPI() YouTube fetch error', { error: err.toString(), videoKeys: targetVideos.map((targetVideo) => targetVideo.yt_video_key), }); // Return so that loop will not continue, and this call has no items returned return null; })
youtube.videos.list({ part: 'snippet,status,contentDetails,liveStreamingDetails', id: targetVideos.map((targetVideo) => targetVideo.yt_video_key), hl: 'ja', fields: 'items(id,snippet,contentDetails,status/embeddable,liveStreamingDetails)', maxResults: 50, // keep at 50, not VIDEOS_MAX_QUERY }) .then((ytResult) => { // Sanity check for YouTube respons contents if (!ytResult.data || !ytResult.data.items) { return Promise.reject(new GenericError('Invalid YouTube response', ytResult)); } // Return video list only return ytResult.data.items; }) .catch((err) => { // Log error information log.error('videoInfoAPI() YouTube fetch error', { error: err.toString(), videoKeys: targetVideos.map((targetVideo) => targetVideo.yt_video_key), }); // Return so that loop will not continue, and this call has no items returned return null; })