2016-11-26 03:25:35 +00:00
|
|
|
import { http } from '.'
|
|
|
|
import { event } from '../utils'
|
|
|
|
import router from '../router'
|
2016-07-30 15:32:17 +00:00
|
|
|
|
|
|
|
export const youtube = {
|
|
|
|
/**
|
|
|
|
* Search for YouTube videos related to a song.
|
|
|
|
*
|
|
|
|
* @param {Object} song
|
|
|
|
* @param {Function} cb
|
|
|
|
*/
|
2016-11-26 03:25:35 +00:00
|
|
|
searchVideosRelatedToSong (song, cb = null) {
|
2016-07-30 15:32:17 +00:00
|
|
|
if (!song.youtube) {
|
2016-11-26 03:25:35 +00:00
|
|
|
song.youtube = {}
|
2016-07-30 15:32:17 +00:00
|
|
|
}
|
|
|
|
|
2016-11-26 03:25:35 +00:00
|
|
|
const pageToken = song.youtube.nextPageToken || ''
|
2016-07-30 15:32:17 +00:00
|
|
|
http.get(`youtube/search/song/${song.id}?pageToken=${pageToken}`).then(data => {
|
2016-11-26 03:25:35 +00:00
|
|
|
song.youtube.nextPageToken = data.nextPageToken
|
|
|
|
song.youtube.items.push(...data.items)
|
|
|
|
cb && cb()
|
|
|
|
})
|
2016-07-30 15:32:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Play a YouTube video.
|
|
|
|
*
|
|
|
|
* @param {string} id The video ID
|
|
|
|
*/
|
2016-11-26 03:25:35 +00:00
|
|
|
play (id) {
|
|
|
|
event.emit('youtube:play', id)
|
|
|
|
router.go('youtube')
|
|
|
|
}
|
|
|
|
}
|