mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
Some refactor, log message changes
This commit is contained in:
parent
1324a16fc5
commit
5564f00838
4 changed files with 31 additions and 26 deletions
|
@ -44,13 +44,13 @@ func (a *playlistArtworkReader) LastUpdated() time.Time {
|
|||
|
||||
func (a *playlistArtworkReader) Reader(ctx context.Context) (io.ReadCloser, string, error) {
|
||||
ff := []sourceFunc{
|
||||
a.fromGeneratedTile(ctx),
|
||||
a.fromGeneratedTiledCover(ctx),
|
||||
fromAlbumPlaceholder(),
|
||||
}
|
||||
return selectImageReader(ctx, a.artID, ff...)
|
||||
}
|
||||
|
||||
func (a *playlistArtworkReader) fromGeneratedTile(ctx context.Context) sourceFunc {
|
||||
func (a *playlistArtworkReader) fromGeneratedTiledCover(ctx context.Context) sourceFunc {
|
||||
return func() (io.ReadCloser, string, error) {
|
||||
tiles, err := a.loadTiles(ctx)
|
||||
if err != nil {
|
||||
|
|
|
@ -28,7 +28,8 @@ func selectImageReader(ctx context.Context, artID model.ArtworkID, extractFuncs
|
|||
start := time.Now()
|
||||
r, path, err := f()
|
||||
if r != nil {
|
||||
log.Trace(ctx, "Found artwork", "artID", artID, "path", path, "source", f, "elapsed", time.Since(start))
|
||||
msg := fmt.Sprintf("Found %s artwork", artID.Kind)
|
||||
log.Debug(ctx, msg, "artID", artID, "path", path, "source", f, "elapsed", time.Since(start))
|
||||
return r, path, nil
|
||||
}
|
||||
log.Trace(ctx, "Failed trying to extract artwork", "artID", artID, "source", f, "elapsed", time.Since(start), err)
|
||||
|
|
|
@ -4,24 +4,29 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
type Kind struct{ prefix string }
|
||||
type Kind struct {
|
||||
prefix string
|
||||
name string
|
||||
}
|
||||
|
||||
func (k Kind) String() string {
|
||||
return k.name
|
||||
}
|
||||
|
||||
var (
|
||||
KindMediaFileArtwork = Kind{"mf"}
|
||||
KindArtistArtwork = Kind{"ar"}
|
||||
KindAlbumArtwork = Kind{"al"}
|
||||
KindPlaylistArtwork = Kind{"pl"}
|
||||
KindMediaFileArtwork = Kind{"mf", "media_file"}
|
||||
KindArtistArtwork = Kind{"ar", "artist"}
|
||||
KindAlbumArtwork = Kind{"al", "album"}
|
||||
KindPlaylistArtwork = Kind{"pl", "playlist"}
|
||||
)
|
||||
|
||||
var artworkKindList = []string{
|
||||
KindMediaFileArtwork.prefix,
|
||||
KindArtistArtwork.prefix,
|
||||
KindAlbumArtwork.prefix,
|
||||
KindPlaylistArtwork.prefix,
|
||||
var artworkKindMap = map[string]Kind{
|
||||
KindMediaFileArtwork.prefix: KindMediaFileArtwork,
|
||||
KindArtistArtwork.prefix: KindArtistArtwork,
|
||||
KindAlbumArtwork.prefix: KindAlbumArtwork,
|
||||
KindPlaylistArtwork.prefix: KindPlaylistArtwork,
|
||||
}
|
||||
|
||||
type ArtworkID struct {
|
||||
|
@ -45,13 +50,14 @@ func ParseArtworkID(id string) (ArtworkID, error) {
|
|||
if len(parts) != 2 {
|
||||
return ArtworkID{}, errors.New("invalid artwork id")
|
||||
}
|
||||
if !slices.Contains(artworkKindList, parts[0]) {
|
||||
if kind, ok := artworkKindMap[parts[0]]; !ok {
|
||||
return ArtworkID{}, errors.New("invalid artwork kind")
|
||||
} else {
|
||||
return ArtworkID{
|
||||
Kind: kind,
|
||||
ID: parts[1],
|
||||
}, nil
|
||||
}
|
||||
return ArtworkID{
|
||||
Kind: Kind{parts[0]},
|
||||
ID: parts[1],
|
||||
}, nil
|
||||
}
|
||||
|
||||
func MustParseArtworkID(id string) ArtworkID {
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/navidrome/navidrome/model"
|
||||
"github.com/navidrome/navidrome/utils"
|
||||
"github.com/navidrome/navidrome/utils/slice"
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
// refresher is responsible for rolling up mediafiles attributes into albums attributes,
|
||||
|
@ -52,11 +53,11 @@ func (r *refresher) flush(ctx context.Context) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.album = map[string]struct{}{}
|
||||
err = r.flushMap(ctx, r.artist, "artist", r.refreshArtists)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.album = map[string]struct{}{}
|
||||
r.artist = map[string]struct{}{}
|
||||
return nil
|
||||
}
|
||||
|
@ -67,11 +68,8 @@ func (r *refresher) flushMap(ctx context.Context, m map[string]struct{}, entity
|
|||
if len(m) == 0 {
|
||||
return nil
|
||||
}
|
||||
var ids []string
|
||||
for id := range m {
|
||||
ids = append(ids, id)
|
||||
delete(m, id)
|
||||
}
|
||||
|
||||
ids := maps.Keys(m)
|
||||
chunks := utils.BreakUpStringSlice(ids, 100)
|
||||
for _, chunk := range chunks {
|
||||
err := refresh(ctx, chunk...)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue