From e79e364ff9a8b847348320d1b5da8a6255486f53 Mon Sep 17 00:00:00 2001 From: Hazel Noack Date: Thu, 9 Oct 2025 12:35:00 +0200 Subject: [PATCH] removed function fetch list --- internal/cli/shell.go | 4 ++-- internal/data/song.go | 39 ++++++++++++++++++++++++++++++++++ internal/plugin/interface.go | 35 ------------------------------ internal/plugin/plugin_test.go | 10 ++++----- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/internal/cli/shell.go b/internal/cli/shell.go index ee68cca..ed37b4a 100644 --- a/internal/cli/shell.go +++ b/internal/cli/shell.go @@ -100,12 +100,12 @@ func interpretCommand(command string, store musicObjectStore) (musicObjectStore, current := currentMusicObjects[index] - currentMusicObjects, err = plugin.FetchList(current) + fetched, err := plugin.Fetch(current) if err != nil { return store, err } - return append(store, currentMusicObjects), nil + return append(store, fetched.Related()), nil } // search in every other case diff --git a/internal/data/song.go b/internal/data/song.go index 341a3d5..2733670 100644 --- a/internal/data/song.go +++ b/internal/data/song.go @@ -11,6 +11,7 @@ type MusicObject interface { Compile() MusicObject GetIndices() []string Merge(other MusicObject) MusicObject + Related() []MusicObject } func dedupeMusicObjects[T MusicObject](inputMusicObjects []T) []T { @@ -71,6 +72,20 @@ type Song struct { Sources []Source } +func (m Song) Related() []MusicObject { + res := []MusicObject{} + + for _, a := range m.Artists { + res = append(res, a) + } + if m.Album.Name != "" { + res = append(res, m.Album) + } + + res = append(res, m) + return res +} + func (m Song) GetSources() []Source { return m.Sources } @@ -127,6 +142,20 @@ type Album struct { Sources []Source } +func (m Album) Related() []MusicObject { + res := []MusicObject{} + + for _, a := range m.Artists { + res = append(res, a) + } + res = append(res, m) + for _, a := range m.Songs { + res = append(res, a) + } + + return res +} + func (m Album) GetSources() []Source { return m.Sources } @@ -183,6 +212,16 @@ type Artist struct { Sources []Source } +func (m Artist) Related() []MusicObject { + res := []MusicObject{m} + + for _, a := range m.Albums { + res = append(res, a) + } + + return res +} + func (m Artist) GetSources() []Source { return m.Sources } diff --git a/internal/plugin/interface.go b/internal/plugin/interface.go index 4cf8bd0..02f389a 100644 --- a/internal/plugin/interface.go +++ b/internal/plugin/interface.go @@ -166,41 +166,6 @@ func Fetch(musicObject data.MusicObject) (data.MusicObject, error) { return musicObject, nil } -func FetchList(musicObject data.MusicObject) ([]data.MusicObject, error) { - res := []data.MusicObject{} - - musicObject, err := Fetch(musicObject) - if err != nil { - return res, err - } - - if a, ok := musicObject.(data.Song); ok { - for _, ar := range a.Artists { - res = append(res, ar) - } - if a.Album.Name != "" { - res = append(res, a.Album, a) - } - } else if a, ok := musicObject.(data.Album); ok { - for _, ar := range a.Artists { - res = append(res, ar) - } - res = append(res, a) - for _, s := range a.Songs { - res = append(res, s) - } - } else if a, ok := musicObject.(data.Artist); ok { - res = append(res, a) - for _, al := range a.Albums { - res = append(res, al) - } - } else { - res = append(res, musicObject) - } - - return res, nil -} - type SearchConfig struct { IgnoreErrors bool } diff --git a/internal/plugin/plugin_test.go b/internal/plugin/plugin_test.go index 317b633..2850db1 100644 --- a/internal/plugin/plugin_test.go +++ b/internal/plugin/plugin_test.go @@ -87,7 +87,7 @@ func TestRegister(t *testing.T) { func TestFetchSong(t *testing.T) { RegisterPlugin(&MusifyTest{}) - s, err := Fetch(data.Source{ + s, err := FetchSource(data.Source{ Url: "https://musify.club/track/linkin-park-in-the-end-3058", }) @@ -108,7 +108,7 @@ func TestFetchSong(t *testing.T) { func TestFetchAlbum(t *testing.T) { RegisterPlugin(&MusifyTest{}) - a, err := Fetch(data.Source{ + a, err := FetchSource(data.Source{ Url: "https://musify.club/release/linkin-park-hybrid-theory-2000-188", }) @@ -129,7 +129,7 @@ func TestFetchAlbum(t *testing.T) { func TestFetchArtist(t *testing.T) { RegisterPlugin(&MusifyTest{}) - a, err := Fetch(data.Source{ + a, err := FetchSource(data.Source{ Url: "https://musify.club/artist/linkin-park-5", }) @@ -150,7 +150,7 @@ func TestFetchArtist(t *testing.T) { func TestFetchWrongUrl(t *testing.T) { RegisterPlugin(&MusifyTest{}) - _, err := Fetch(data.Source{ + _, err := FetchSource(data.Source{ Url: "https://musify.club/", }) @@ -162,7 +162,7 @@ func TestFetchWrongUrl(t *testing.T) { func TestNonExistentSourceType(t *testing.T) { RegisterPlugin(&MusifyTest{}) - _, err := Fetch(data.Source{ + _, err := FetchSource(data.Source{ Url: "https://musify.club/", SourceType: &data.SourceType{ Name: "doesn't exist",