From eccf34c6f2e9af1f610e691d4b42635d98cbbdc0 Mon Sep 17 00:00:00 2001 From: Deluan Date: Sat, 29 Mar 2025 13:40:50 -0400 Subject: [PATCH] rename external metadata -wip Signed-off-by: Deluan --- cmd/wire_gen.go | 9 +++++---- core/artwork/artwork.go | 6 +++--- core/artwork/reader_album.go | 5 +++-- core/artwork/reader_artist.go | 5 +++-- core/artwork/sources.go | 6 +++--- core/extdata/extdata_suite_test.go | 17 +++++++++++++++++ core/{ => extdata}/external_metadata.go | 2 +- core/{ => extdata}/external_metadata_test.go | 2 +- core/wire_providers.go | 3 ++- server/subsonic/api.go | 5 +++-- 10 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 core/extdata/extdata_suite_test.go rename core/{ => extdata}/external_metadata.go (99%) rename core/{ => extdata}/external_metadata_test.go (99%) diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go index e5e72bf4f..7e3e6208b 100644 --- a/cmd/wire_gen.go +++ b/cmd/wire_gen.go @@ -14,6 +14,7 @@ import ( "github.com/navidrome/navidrome/core/agents/lastfm" "github.com/navidrome/navidrome/core/agents/listenbrainz" "github.com/navidrome/navidrome/core/artwork" + "github.com/navidrome/navidrome/core/extdata" "github.com/navidrome/navidrome/core/ffmpeg" "github.com/navidrome/navidrome/core/metrics" "github.com/navidrome/navidrome/core/playback" @@ -66,7 +67,7 @@ func CreateSubsonicAPIRouter(ctx context.Context) *subsonic.Router { fileCache := artwork.GetImageCache() fFmpeg := ffmpeg.New() agentsAgents := agents.GetAgents(dataStore) - externalMetadata := core.NewExternalMetadata(dataStore, agentsAgents) + externalMetadata := extdata.NewExternalMetadata(dataStore, agentsAgents) artworkArtwork := artwork.NewArtwork(dataStore, fileCache, fFmpeg, externalMetadata) transcodingCache := core.GetTranscodingCache() mediaStreamer := core.NewMediaStreamer(dataStore, fFmpeg, transcodingCache) @@ -90,7 +91,7 @@ func CreatePublicRouter() *public.Router { fileCache := artwork.GetImageCache() fFmpeg := ffmpeg.New() agentsAgents := agents.GetAgents(dataStore) - externalMetadata := core.NewExternalMetadata(dataStore, agentsAgents) + externalMetadata := extdata.NewExternalMetadata(dataStore, agentsAgents) artworkArtwork := artwork.NewArtwork(dataStore, fileCache, fFmpeg, externalMetadata) transcodingCache := core.GetTranscodingCache() mediaStreamer := core.NewMediaStreamer(dataStore, fFmpeg, transcodingCache) @@ -134,7 +135,7 @@ func CreateScanner(ctx context.Context) scanner.Scanner { fileCache := artwork.GetImageCache() fFmpeg := ffmpeg.New() agentsAgents := agents.GetAgents(dataStore) - externalMetadata := core.NewExternalMetadata(dataStore, agentsAgents) + externalMetadata := extdata.NewExternalMetadata(dataStore, agentsAgents) artworkArtwork := artwork.NewArtwork(dataStore, fileCache, fFmpeg, externalMetadata) cacheWarmer := artwork.NewCacheWarmer(artworkArtwork, fileCache) broker := events.GetBroker() @@ -150,7 +151,7 @@ func CreateScanWatcher(ctx context.Context) scanner.Watcher { fileCache := artwork.GetImageCache() fFmpeg := ffmpeg.New() agentsAgents := agents.GetAgents(dataStore) - externalMetadata := core.NewExternalMetadata(dataStore, agentsAgents) + externalMetadata := extdata.NewExternalMetadata(dataStore, agentsAgents) artworkArtwork := artwork.NewArtwork(dataStore, fileCache, fFmpeg, externalMetadata) cacheWarmer := artwork.NewCacheWarmer(artworkArtwork, fileCache) broker := events.GetBroker() diff --git a/core/artwork/artwork.go b/core/artwork/artwork.go index 3570dd7b4..af462356e 100644 --- a/core/artwork/artwork.go +++ b/core/artwork/artwork.go @@ -8,7 +8,7 @@ import ( "time" "github.com/navidrome/navidrome/consts" - "github.com/navidrome/navidrome/core" + "github.com/navidrome/navidrome/core/extdata" "github.com/navidrome/navidrome/core/ffmpeg" "github.com/navidrome/navidrome/log" "github.com/navidrome/navidrome/model" @@ -24,7 +24,7 @@ type Artwork interface { GetOrPlaceholder(ctx context.Context, id string, size int, square bool) (io.ReadCloser, time.Time, error) } -func NewArtwork(ds model.DataStore, cache cache.FileCache, ffmpeg ffmpeg.FFmpeg, em core.ExternalMetadata) Artwork { +func NewArtwork(ds model.DataStore, cache cache.FileCache, ffmpeg ffmpeg.FFmpeg, em extdata.ExternalMetadata) Artwork { return &artwork{ds: ds, cache: cache, ffmpeg: ffmpeg, em: em} } @@ -32,7 +32,7 @@ type artwork struct { ds model.DataStore cache cache.FileCache ffmpeg ffmpeg.FFmpeg - em core.ExternalMetadata + em extdata.ExternalMetadata } type artworkReader interface { diff --git a/core/artwork/reader_album.go b/core/artwork/reader_album.go index f1ed9b63c..42957200b 100644 --- a/core/artwork/reader_album.go +++ b/core/artwork/reader_album.go @@ -12,6 +12,7 @@ import ( "github.com/Masterminds/squirrel" "github.com/navidrome/navidrome/conf" "github.com/navidrome/navidrome/core" + "github.com/navidrome/navidrome/core/extdata" "github.com/navidrome/navidrome/core/ffmpeg" "github.com/navidrome/navidrome/model" ) @@ -19,14 +20,14 @@ import ( type albumArtworkReader struct { cacheKey a *artwork - em core.ExternalMetadata + em extdata.ExternalMetadata album model.Album updatedAt *time.Time imgFiles []string rootFolder string } -func newAlbumArtworkReader(ctx context.Context, artwork *artwork, artID model.ArtworkID, em core.ExternalMetadata) (*albumArtworkReader, error) { +func newAlbumArtworkReader(ctx context.Context, artwork *artwork, artID model.ArtworkID, em extdata.ExternalMetadata) (*albumArtworkReader, error) { al, err := artwork.ds.Album(ctx).Get(artID.ID) if err != nil { return nil, err diff --git a/core/artwork/reader_artist.go b/core/artwork/reader_artist.go index e910ef93e..ae813ae60 100644 --- a/core/artwork/reader_artist.go +++ b/core/artwork/reader_artist.go @@ -14,6 +14,7 @@ import ( "github.com/Masterminds/squirrel" "github.com/navidrome/navidrome/conf" "github.com/navidrome/navidrome/core" + "github.com/navidrome/navidrome/core/extdata" "github.com/navidrome/navidrome/log" "github.com/navidrome/navidrome/model" "github.com/navidrome/navidrome/utils/str" @@ -22,13 +23,13 @@ import ( type artistReader struct { cacheKey a *artwork - em core.ExternalMetadata + em extdata.ExternalMetadata artist model.Artist artistFolder string imgFiles []string } -func newArtistReader(ctx context.Context, artwork *artwork, artID model.ArtworkID, em core.ExternalMetadata) (*artistReader, error) { +func newArtistReader(ctx context.Context, artwork *artwork, artID model.ArtworkID, em extdata.ExternalMetadata) (*artistReader, error) { ar, err := artwork.ds.Artist(ctx).Get(artID.ID) if err != nil { return nil, err diff --git a/core/artwork/sources.go b/core/artwork/sources.go index f89708255..730ef0f28 100644 --- a/core/artwork/sources.go +++ b/core/artwork/sources.go @@ -17,7 +17,7 @@ import ( "github.com/dhowden/tag" "github.com/navidrome/navidrome/consts" - "github.com/navidrome/navidrome/core" + "github.com/navidrome/navidrome/core/extdata" "github.com/navidrome/navidrome/core/ffmpeg" "github.com/navidrome/navidrome/log" "github.com/navidrome/navidrome/model" @@ -157,7 +157,7 @@ func fromAlbumPlaceholder() sourceFunc { return r, consts.PlaceholderAlbumArt, nil } } -func fromArtistExternalSource(ctx context.Context, ar model.Artist, em core.ExternalMetadata) sourceFunc { +func fromArtistExternalSource(ctx context.Context, ar model.Artist, em extdata.ExternalMetadata) sourceFunc { return func() (io.ReadCloser, string, error) { imageUrl, err := em.ArtistImage(ctx, ar.ID) if err != nil { @@ -168,7 +168,7 @@ func fromArtistExternalSource(ctx context.Context, ar model.Artist, em core.Exte } } -func fromAlbumExternalSource(ctx context.Context, al model.Album, em core.ExternalMetadata) sourceFunc { +func fromAlbumExternalSource(ctx context.Context, al model.Album, em extdata.ExternalMetadata) sourceFunc { return func() (io.ReadCloser, string, error) { imageUrl, err := em.AlbumImage(ctx, al.ID) if err != nil { diff --git a/core/extdata/extdata_suite_test.go b/core/extdata/extdata_suite_test.go new file mode 100644 index 000000000..2cf408efc --- /dev/null +++ b/core/extdata/extdata_suite_test.go @@ -0,0 +1,17 @@ +package extdata + +import ( + "testing" + + "github.com/navidrome/navidrome/log" + "github.com/navidrome/navidrome/tests" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestExternalData(t *testing.T) { + tests.Init(t, false) + log.SetLevel(log.LevelFatal) + RegisterFailHandler(Fail) + RunSpecs(t, "ExternalData Suite") +} diff --git a/core/external_metadata.go b/core/extdata/external_metadata.go similarity index 99% rename from core/external_metadata.go rename to core/extdata/external_metadata.go index 9ccebd5f4..47119d481 100644 --- a/core/external_metadata.go +++ b/core/extdata/external_metadata.go @@ -1,4 +1,4 @@ -package core +package extdata import ( "context" diff --git a/core/external_metadata_test.go b/core/extdata/external_metadata_test.go similarity index 99% rename from core/external_metadata_test.go rename to core/extdata/external_metadata_test.go index b8c050bd8..2753b2a2c 100644 --- a/core/external_metadata_test.go +++ b/core/extdata/external_metadata_test.go @@ -1,4 +1,4 @@ -package core +package extdata import ( "context" diff --git a/core/wire_providers.go b/core/wire_providers.go index 6f9d326ec..67f8fb645 100644 --- a/core/wire_providers.go +++ b/core/wire_providers.go @@ -3,6 +3,7 @@ package core import ( "github.com/google/wire" "github.com/navidrome/navidrome/core/agents" + "github.com/navidrome/navidrome/core/extdata" "github.com/navidrome/navidrome/core/ffmpeg" "github.com/navidrome/navidrome/core/metrics" "github.com/navidrome/navidrome/core/playback" @@ -13,11 +14,11 @@ var Set = wire.NewSet( NewMediaStreamer, GetTranscodingCache, NewArchiver, - NewExternalMetadata, NewPlayers, NewShare, NewPlaylists, agents.GetAgents, + extdata.NewExternalMetadata, ffmpeg.New, scrobbler.GetPlayTracker, playback.GetInstance, diff --git a/server/subsonic/api.go b/server/subsonic/api.go index dfa945086..f2877f517 100644 --- a/server/subsonic/api.go +++ b/server/subsonic/api.go @@ -12,6 +12,7 @@ import ( "github.com/navidrome/navidrome/conf" "github.com/navidrome/navidrome/core" "github.com/navidrome/navidrome/core/artwork" + "github.com/navidrome/navidrome/core/extdata" "github.com/navidrome/navidrome/core/playback" "github.com/navidrome/navidrome/core/scrobbler" "github.com/navidrome/navidrome/log" @@ -35,7 +36,7 @@ type Router struct { streamer core.MediaStreamer archiver core.Archiver players core.Players - externalMetadata core.ExternalMetadata + externalMetadata extdata.ExternalMetadata playlists core.Playlists scanner scanner.Scanner broker events.Broker @@ -45,7 +46,7 @@ type Router struct { } func New(ds model.DataStore, artwork artwork.Artwork, streamer core.MediaStreamer, archiver core.Archiver, - players core.Players, externalMetadata core.ExternalMetadata, scanner scanner.Scanner, broker events.Broker, + players core.Players, externalMetadata extdata.ExternalMetadata, scanner scanner.Scanner, broker events.Broker, playlists core.Playlists, scrobbler scrobbler.PlayTracker, share core.Share, playback playback.PlaybackServer, ) *Router { r := &Router{