mirror of
https://github.com/koel/koel
synced 2025-01-09 11:18:44 +00:00
35 lines
822 B
JavaScript
35 lines
822 B
JavaScript
import { http } from '.'
|
|
import { event } from '../utils'
|
|
import router from '../router'
|
|
|
|
export const youtube = {
|
|
/**
|
|
* Search for YouTube videos related to a song.
|
|
*
|
|
* @param {Object} song
|
|
*/
|
|
searchVideosRelatedToSong (song) {
|
|
if (!song.youtube) {
|
|
song.youtube = {}
|
|
}
|
|
|
|
const pageToken = song.youtube.nextPageToken || ''
|
|
return new Promise((resolve, reject) => {
|
|
http.get(`youtube/search/song/${song.id}?pageToken=${pageToken}`, ({ data }) => {
|
|
song.youtube.nextPageToken = data.nextPageToken
|
|
song.youtube.items.push(...data.items)
|
|
resolve()
|
|
}, error => reject(error))
|
|
})
|
|
},
|
|
|
|
/**
|
|
* Play a YouTube video.
|
|
*
|
|
* @param {string} id The video ID
|
|
*/
|
|
play (id) {
|
|
event.emit('youtube:play', id)
|
|
router.go('youtube')
|
|
}
|
|
}
|