2022-05-14 18:49:45 +00:00
|
|
|
import { albumInfoService, artistInfoService, httpService } from '@/services'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
|
|
interface SongInfoResponse {
|
|
|
|
artist_info: ArtistInfo,
|
|
|
|
album_info: AlbumInfo,
|
|
|
|
youtube: {
|
|
|
|
items: YouTubeVideo[],
|
|
|
|
nextPageToken: string
|
|
|
|
},
|
|
|
|
lyrics: string
|
|
|
|
}
|
|
|
|
|
2022-05-06 10:28:02 +00:00
|
|
|
export const songInfoService = {
|
|
|
|
fetch: async (song: Song) => {
|
2022-04-15 14:24:30 +00:00
|
|
|
if (!song.infoRetrieved) {
|
2022-05-06 10:28:02 +00:00
|
|
|
const {
|
|
|
|
lyrics,
|
|
|
|
artist_info: artistInfo,
|
|
|
|
album_info: albumInfo,
|
|
|
|
youtube
|
|
|
|
} = await httpService.get<SongInfoResponse>(`song/${song.id}/info`)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
|
|
song.lyrics = lyrics
|
2022-05-06 10:28:02 +00:00
|
|
|
artistInfo && artistInfoService.merge(song.artist, artistInfo)
|
|
|
|
albumInfo && albumInfoService.merge(song.album, albumInfo)
|
2022-04-15 14:24:30 +00:00
|
|
|
song.youtube = youtube
|
|
|
|
song.infoRetrieved = true
|
|
|
|
}
|
|
|
|
|
|
|
|
return song
|
|
|
|
}
|
|
|
|
}
|