2022-04-24 08:50:45 +00:00
|
|
|
import { httpService } from '@/services'
|
2022-04-15 14:24:30 +00:00
|
|
|
import { eventBus } from '@/utils'
|
|
|
|
import router from '@/router'
|
|
|
|
|
|
|
|
interface YouTubeSearchResult {
|
|
|
|
nextPageToken: string
|
2022-04-24 08:50:45 +00:00
|
|
|
items: Array<Record<string, any>>
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2022-04-24 08:50:45 +00:00
|
|
|
export const youTubeService = {
|
2022-04-15 14:24:30 +00:00
|
|
|
searchVideosRelatedToSong: async (song: Song, nextPageToken: string): Promise<YouTubeSearchResult> => {
|
2022-04-24 08:50:45 +00:00
|
|
|
return await httpService.get<YouTubeSearchResult>(`youtube/search/song/${song.id}?pageToken=${nextPageToken}`)
|
2022-04-15 14:24:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
play: (video: YouTubeVideo): void => {
|
|
|
|
eventBus.emit('PLAY_YOUTUBE_VIDEO', {
|
|
|
|
id: video.id.videoId,
|
|
|
|
title: video.snippet.title
|
|
|
|
})
|
|
|
|
|
|
|
|
router.go('youtube')
|
|
|
|
}
|
|
|
|
}
|