fixed pointer issue
This commit is contained in:
@@ -2,6 +2,7 @@ package plugin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"gitea.elara.ws/Hazel/music-kraken/internal/common"
|
||||
@@ -163,7 +164,7 @@ func Fetch(musicObject data.MusicObject) (data.MusicObject, error) {
|
||||
musicObject = musicObject.Merge(newMusicObject)
|
||||
}
|
||||
|
||||
return musicObject, nil
|
||||
return musicObject.Compile(), nil
|
||||
}
|
||||
|
||||
type SearchConfig struct {
|
||||
@@ -204,15 +205,21 @@ var variousAlbum = data.Album{
|
||||
Name: "VariousAlbum",
|
||||
}.Compile().(data.Album)
|
||||
|
||||
func downloadSong(song data.Song, state downloadState) {}
|
||||
func downloadSong(song data.Song, state downloadState) error {
|
||||
fmt.Println("downloading: " + song.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func Download(musicObject data.MusicObject, statesInput ...downloadState) {
|
||||
func Download(musicObject data.MusicObject, statesInput ...downloadState) []error {
|
||||
state := downloadState{}
|
||||
if len(statesInput) > 0 {
|
||||
state = statesInput[0]
|
||||
}
|
||||
|
||||
musicObject = musicObject.Compile()
|
||||
musicObject, err := Fetch(musicObject)
|
||||
if err != nil {
|
||||
return []error{err}
|
||||
}
|
||||
|
||||
if song, ok := musicObject.(data.Song); ok {
|
||||
state.song = &song
|
||||
@@ -232,8 +239,13 @@ func Download(musicObject data.MusicObject, statesInput ...downloadState) {
|
||||
state.album = &variousAlbum
|
||||
}
|
||||
}
|
||||
downloadSong(song, state)
|
||||
return
|
||||
|
||||
err := downloadSong(song, state)
|
||||
if err == nil {
|
||||
return []error{}
|
||||
} else {
|
||||
return []error{err}
|
||||
}
|
||||
}
|
||||
|
||||
if album, ok := musicObject.(data.Album); ok {
|
||||
@@ -247,18 +259,24 @@ func Download(musicObject data.MusicObject, statesInput ...downloadState) {
|
||||
}
|
||||
}
|
||||
|
||||
errList := []error{}
|
||||
for _, song := range album.Songs {
|
||||
Download(song, state)
|
||||
errList = append(errList, Download(song, state)...)
|
||||
}
|
||||
return
|
||||
return errList
|
||||
}
|
||||
|
||||
if artist, ok := musicObject.(data.Artist); ok {
|
||||
state.artist = &artist
|
||||
|
||||
errList := []error{}
|
||||
for _, album := range artist.Albums {
|
||||
Download(album, state)
|
||||
errList = append(errList, Download(album, state)...)
|
||||
}
|
||||
return
|
||||
return errList
|
||||
}
|
||||
|
||||
return []error{
|
||||
errors.New("music object not recognized"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user