very slim skelleton for downloading
This commit is contained in:
@@ -189,3 +189,76 @@ func Search(search string, config SearchConfig) ([]data.MusicObject, error) {
|
|||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type downloadState struct {
|
||||||
|
artist *data.Artist
|
||||||
|
album *data.Album
|
||||||
|
song *data.Song
|
||||||
|
}
|
||||||
|
|
||||||
|
var variousArtist = data.Artist{
|
||||||
|
Name: "VariousArtist",
|
||||||
|
}.Compile().(data.Artist)
|
||||||
|
|
||||||
|
var variousAlbum = data.Album{
|
||||||
|
Name: "VariousAlbum",
|
||||||
|
}.Compile().(data.Album)
|
||||||
|
|
||||||
|
func downloadSong(song data.Song, state downloadState) {}
|
||||||
|
|
||||||
|
func Download(musicObject data.MusicObject, statesInput ...downloadState) {
|
||||||
|
state := downloadState{}
|
||||||
|
if len(statesInput) > 0 {
|
||||||
|
state = statesInput[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
musicObject = musicObject.Compile()
|
||||||
|
|
||||||
|
if song, ok := musicObject.(data.Song); ok {
|
||||||
|
state.song = &song
|
||||||
|
|
||||||
|
if state.artist == nil {
|
||||||
|
if len(song.Artists) > 0 {
|
||||||
|
state.artist = &song.Artists[0]
|
||||||
|
} else {
|
||||||
|
state.artist = &variousArtist
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if state.album == nil {
|
||||||
|
if song.Album.Name != "" {
|
||||||
|
state.album = &song.Album
|
||||||
|
} else {
|
||||||
|
state.album = &variousAlbum
|
||||||
|
}
|
||||||
|
}
|
||||||
|
downloadSong(song, state)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if album, ok := musicObject.(data.Album); ok {
|
||||||
|
state.album = &album
|
||||||
|
|
||||||
|
if state.artist == nil {
|
||||||
|
if len(album.Artists) > 0 {
|
||||||
|
state.artist = &album.Artists[0]
|
||||||
|
} else {
|
||||||
|
state.artist = &variousArtist
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, song := range album.Songs {
|
||||||
|
Download(song, state)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if artist, ok := musicObject.(data.Artist); ok {
|
||||||
|
state.artist = &artist
|
||||||
|
|
||||||
|
for _, album := range artist.Albums {
|
||||||
|
Download(album, state)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user