fetching from object not from source

This commit is contained in:
Hazel Noack
2025-10-09 12:23:10 +02:00
parent e9d1d20c63
commit 4eab2bb874
2 changed files with 23 additions and 8 deletions

View File

@@ -100,11 +100,7 @@ func interpretCommand(command string, store musicObjectStore) (musicObjectStore,
current := currentMusicObjects[index]
if len(current.GetSources()) <= 0 {
return store, errors.New("selected object has no sources to download")
}
currentMusicObjects, err = plugin.FetchList(current.GetSources()[0])
currentMusicObjects, err = plugin.FetchList(current)
if err != nil {
return store, err
}

View File

@@ -99,7 +99,7 @@ func compileSource(source data.Source) (data.Source, error) {
return source, errors.New("couldn't find corresponding object source on " + sourceType.Name + " for " + source.Url)
}
func Fetch(source data.Source) (data.MusicObject, error) {
func FetchSource(source data.Source) (data.MusicObject, error) {
// the fetch function without the post processing of the music objects
source, err := compileSource(source)
if err != nil {
@@ -147,10 +147,29 @@ func Fetch(source data.Source) (data.MusicObject, error) {
return nil, nil
}
func FetchList(source data.Source) ([]data.MusicObject, error) {
func Fetch(musicObject data.MusicObject) (data.MusicObject, error) {
sources := musicObject.GetSources()
if len(sources) <= 0 {
return musicObject, errors.New("didn't find a source for object")
}
for _, source := range sources {
newMusicObject, err := FetchSource(source)
if err != nil {
return musicObject, err
}
musicObject = musicObject.Merge(newMusicObject)
}
return musicObject, nil
}
func FetchList(musicObject data.MusicObject) ([]data.MusicObject, error) {
res := []data.MusicObject{}
musicObject, err := Fetch(source)
musicObject, err := Fetch(musicObject)
if err != nil {
return res, err
}