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) {
|
func (a *playlistArtworkReader) Reader(ctx context.Context) (io.ReadCloser, string, error) {
|
||||||
ff := []sourceFunc{
|
ff := []sourceFunc{
|
||||||
a.fromGeneratedTile(ctx),
|
a.fromGeneratedTiledCover(ctx),
|
||||||
fromAlbumPlaceholder(),
|
fromAlbumPlaceholder(),
|
||||||
}
|
}
|
||||||
return selectImageReader(ctx, a.artID, ff...)
|
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) {
|
return func() (io.ReadCloser, string, error) {
|
||||||
tiles, err := a.loadTiles(ctx)
|
tiles, err := a.loadTiles(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -28,7 +28,8 @@ func selectImageReader(ctx context.Context, artID model.ArtworkID, extractFuncs
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
r, path, err := f()
|
r, path, err := f()
|
||||||
if r != nil {
|
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
|
return r, path, nil
|
||||||
}
|
}
|
||||||
log.Trace(ctx, "Failed trying to extract artwork", "artID", artID, "source", f, "elapsed", time.Since(start), err)
|
log.Trace(ctx, "Failed trying to extract artwork", "artID", artID, "source", f, "elapsed", time.Since(start), err)
|
||||||
|
|
|
@ -4,24 +4,29 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"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 (
|
var (
|
||||||
KindMediaFileArtwork = Kind{"mf"}
|
KindMediaFileArtwork = Kind{"mf", "media_file"}
|
||||||
KindArtistArtwork = Kind{"ar"}
|
KindArtistArtwork = Kind{"ar", "artist"}
|
||||||
KindAlbumArtwork = Kind{"al"}
|
KindAlbumArtwork = Kind{"al", "album"}
|
||||||
KindPlaylistArtwork = Kind{"pl"}
|
KindPlaylistArtwork = Kind{"pl", "playlist"}
|
||||||
)
|
)
|
||||||
|
|
||||||
var artworkKindList = []string{
|
var artworkKindMap = map[string]Kind{
|
||||||
KindMediaFileArtwork.prefix,
|
KindMediaFileArtwork.prefix: KindMediaFileArtwork,
|
||||||
KindArtistArtwork.prefix,
|
KindArtistArtwork.prefix: KindArtistArtwork,
|
||||||
KindAlbumArtwork.prefix,
|
KindAlbumArtwork.prefix: KindAlbumArtwork,
|
||||||
KindPlaylistArtwork.prefix,
|
KindPlaylistArtwork.prefix: KindPlaylistArtwork,
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtworkID struct {
|
type ArtworkID struct {
|
||||||
|
@ -45,13 +50,14 @@ func ParseArtworkID(id string) (ArtworkID, error) {
|
||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
return ArtworkID{}, errors.New("invalid artwork id")
|
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")
|
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 {
|
func MustParseArtworkID(id string) ArtworkID {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
"github.com/navidrome/navidrome/utils"
|
"github.com/navidrome/navidrome/utils"
|
||||||
"github.com/navidrome/navidrome/utils/slice"
|
"github.com/navidrome/navidrome/utils/slice"
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// refresher is responsible for rolling up mediafiles attributes into albums attributes,
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
r.album = map[string]struct{}{}
|
||||||
err = r.flushMap(ctx, r.artist, "artist", r.refreshArtists)
|
err = r.flushMap(ctx, r.artist, "artist", r.refreshArtists)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
r.album = map[string]struct{}{}
|
|
||||||
r.artist = map[string]struct{}{}
|
r.artist = map[string]struct{}{}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -67,11 +68,8 @@ func (r *refresher) flushMap(ctx context.Context, m map[string]struct{}, entity
|
||||||
if len(m) == 0 {
|
if len(m) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var ids []string
|
|
||||||
for id := range m {
|
ids := maps.Keys(m)
|
||||||
ids = append(ids, id)
|
|
||||||
delete(m, id)
|
|
||||||
}
|
|
||||||
chunks := utils.BreakUpStringSlice(ids, 100)
|
chunks := utils.BreakUpStringSlice(ids, 100)
|
||||||
for _, chunk := range chunks {
|
for _, chunk := range chunks {
|
||||||
err := refresh(ctx, chunk...)
|
err := refresh(ctx, chunk...)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue