2022-09-15 09:07:25 +00:00
|
|
|
import { cache, http } from '@/services'
|
2022-04-15 14:24:30 +00:00
|
|
|
import { eventBus } from '@/utils'
|
|
|
|
import router from '@/router'
|
|
|
|
|
|
|
|
interface YouTubeSearchResult {
|
|
|
|
nextPageToken: string
|
2022-07-22 15:03:45 +00:00
|
|
|
items: YouTubeVideo[]
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2022-04-24 08:50:45 +00:00
|
|
|
export const youTubeService = {
|
2022-07-07 23:15:38 +00:00
|
|
|
searchVideosBySong: async (song: Song, nextPageToken: string) => {
|
2022-07-25 13:25:27 +00:00
|
|
|
return await cache.remember<YouTubeSearchResult>(
|
2022-07-07 23:15:38 +00:00
|
|
|
['youtube.search', song.id, nextPageToken],
|
2022-09-15 09:07:25 +00:00
|
|
|
async () => await http.get<YouTubeSearchResult>(
|
2022-07-07 23:15:38 +00:00
|
|
|
`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')
|
|
|
|
}
|
|
|
|
}
|