mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-26 18:27:09 +01:00
feat(artwork): advertise album art for tracks whose embedded cover is the album's
Most albums embed the same picture in every track, so clients requesting per-track cover art (mf- ids) download and cache the same image once per song. This change hashes the embedded picture at scan time (XXH3 of the bytes, the same digest the artwork pipeline uses) and stores it on media_file.embed_art_hash. ToAlbum stores the hash of the track it already picks as the album's embedded cover (EmbedArtPath) on album.embed_art_hash. A new MediaFile.HasOwnCoverArt replaces the scattered "HasCoverArt && EnableMediaFileCoverArt" checks: a track whose hash equals its album's now returns the disc/album artwork id from CoverArtID, so the Subsonic, Jellyfin and native responses point every matching song at one cached image. Serving a stale mf- URL follows the same rule, so what is advertised and what is served agree. Tracks with a different embedded picture (compilations, per-track art) keep their own ids. Rows scanned before this change have an empty hash and keep the previous behavior until a full scan; no config option is added. The album hash is hydrated onto tracks with one batched PK lookup per page, only when the page has hashed tracks. BestImageIndex is exported from core/artwork so the scanner hashes the same picture the resolver serves.
This commit is contained in:
parent
1ceb25c6c1
commit
af984bc817
21 changed files with 280 additions and 82 deletions
|
|
@ -224,8 +224,7 @@ func SongToBaseItem(mf model.MediaFile, fields Fields) BaseItemDto {
|
|||
}
|
||||
|
||||
func embeddedArtPending(mf model.MediaFile) bool {
|
||||
return mf.HasCoverArt && conf.Server.EnableMediaFileCoverArt &&
|
||||
mf.ImageHash == "" && !mf.ItemImage.ImageAbsent
|
||||
return mf.HasOwnCoverArt() && mf.ImageHash == "" && !mf.ItemImage.ImageAbsent
|
||||
}
|
||||
|
||||
// primaryImage never fakes a blurhash: clients key their cover cache on the value, which would
|
||||
|
|
|
|||
|
|
@ -542,6 +542,16 @@ var _ = Describe("mappers", func() {
|
|||
Expect(item.ImageTags).To(BeEmpty())
|
||||
Expect(item.AlbumPrimaryImageTag).To(Equal("0123456789abcdef"))
|
||||
})
|
||||
|
||||
It("falls back to the album when the track's picture is the album's embedded cover", func() {
|
||||
mf := model.MediaFile{ID: testID("mf-5"), AlbumID: testID("alb-1"), HasCoverArt: true,
|
||||
EmbedArtHash: "samepicxxxxxxxxx", AlbumEmbedArtHash: "samepicxxxxxxxxx"}
|
||||
mf.AlbumImage.ImageHash = "0123456789abcdef"
|
||||
|
||||
item := SongToBaseItem(mf, nil)
|
||||
Expect(item.ImageTags).To(BeEmpty())
|
||||
Expect(item.AlbumPrimaryImageTag).To(Equal("0123456789abcdef"))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("primary image tags", func() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue