From 4eab2bb874e42f405337b1c07ea81117aa5f4f8e Mon Sep 17 00:00:00 2001 From: Hazel Noack Date: Thu, 9 Oct 2025 12:23:10 +0200 Subject: [PATCH] fetching from object not from source --- internal/cli/shell.go | 6 +----- internal/plugin/interface.go | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/internal/cli/shell.go b/internal/cli/shell.go index 52f7a6b..ee68cca 100644 --- a/internal/cli/shell.go +++ b/internal/cli/shell.go @@ -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 } diff --git a/internal/plugin/interface.go b/internal/plugin/interface.go index 4190cee..4cf8bd0 100644 --- a/internal/plugin/interface.go +++ b/internal/plugin/interface.go @@ -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 }