fix(scanner): drop releasedate from the default album PID

Only some formats set releasedate from the year tag: M4A (©day) and WMA (WM/Year) do, by their specs, while MP3/FLAC files with the same DATE do not. With releasedate in the default album PID, albums that mix formats split in two (#6467).

Remove releasedate from the default album PID instead of removing the ©day and WM/Year aliases, so M4A/WMA files keep their release date. The PID joins all its fields, so changing the spec changes every album ID. To keep existing IDs, a migration pins the old default as the album PID override of every library already scanned with it. New libraries use the new default. Users can clear the override to regroup a library, which triggers the existing full rescan that moves album annotations.

Editions of one album that differ only by release date, with no MusicBrainz album ID or albumversion, now merge, as most MP3/FLAC editions already do.
This commit is contained in:
Deluan committed 2026-11-17 14:46:03 -05:00
1 parent 587700a757
commit 525ed9ed28
8 files changed
+29 -51

No files matched your search

+1 -1
View File
@@ -157,7 +157,7 @@ const (
const (
//DefaultAlbumPID = "album_legacy"
DefaultAlbumPID = "musicbrainz_albumid|albumartistid,album,albumversion,releasedate"
DefaultAlbumPID = "musicbrainz_albumid|albumartistid,album,albumversion"
DefaultTrackPID = "musicbrainz_trackid|albumid,discnumber,tracknumber,title"
)
@@ -1,43 +0,0 @@
package migrations
import (
"context"
"database/sql"
"github.com/navidrome/navidrome/conf"
"github.com/pressly/goose/v3"
)
func init() {
goose.AddMigrationContext(upRegroupMp4AsfAlbums, downRegroupMp4AsfAlbums)
}
// The raw ©day (MP4) and WM/Year (ASF) tags were releasedate aliases, so those files got a release date
// that MP3/FLAC files with the same DATE did not, and mixed-format albums split (#6467). With the aliases
// removed, album IDs that hash the release date change for these files. Clearing scanned_pid_album makes
// the scanner treat the library as having a changed PID: it rescans it in full and moves the annotations.
func upRegroupMp4AsfAlbums(ctx context.Context, tx *sql.Tx) error {
// A custom releasedate mapping replaces the default aliases, so the change does not apply
if tc, ok := conf.Server().Tags["releasedate"]; ok && (tc.Ignore || len(tc.Aliases) > 0) {
return nil
}
// album_legacy also appends the release date to the album ID
res, err := tx.ExecContext(ctx, `
update library set scanned_pid_album = ''
where (coalesce(nullif(pid_album, ''), ?1) like '%releasedate%' or lower(coalesce(nullif(pid_album, ''), ?1)) = 'album_legacy')
and id in (
select distinct library_id from media_file
where suffix in ('m4a', 'm4b', 'm4p', 'm4r', 'm4v', 'mp4', 'wma', 'asf')
)`, conf.Server().PID.Album)
if err != nil {
return err
}
if n, _ := res.RowsAffected(); n > 0 {
notice(ctx, tx, "Libraries with M4A or WMA files will be rescanned in full, to fix albums split by file format")
}
return nil
}
func downRegroupMp4AsfAlbums(context.Context, *sql.Tx) error {
return nil
}
@@ -0,0 +1,11 @@
-- +goose Up
-- +goose StatementBegin
-- The default album PID no longer has releasedate. Libraries scanned with the old default keep it,
-- so their album IDs do not change.
update library set pid_album = 'musicbrainz_albumid|albumartistid,album,albumversion,releasedate'
where pid_album = ''
and lower(scanned_pid_album) = 'musicbrainz_albumid|albumartistid,album,albumversion,releasedate';
-- +goose StatementEnd
-- +goose Down
SELECT 1;
+2 -3
View File
@@ -47,8 +47,7 @@ var _ = Describe("ToMediaFile", func() {
Expect(byFolder.PID).ToNot(Equal(byTags.PID))
})
// TagLib reports the year of M4A and WMA files as DATE, like MP3 and FLAC, and also
// sends the raw atom/attribute. The raw one must not become a release date (#6467).
// TagLib sends the M4A/WMA year as DATE and as the raw atom, which is a release date alias
DescribeTable("gives the same album ID to tracks of one album in different formats",
func(formatYearTag string) {
albumTags := model.RawTags{"ALBUM": {"Hello"}, "ALBUMARTIST": {"Adele"}, "DATE": {"2022"}}
@@ -59,7 +58,7 @@ var _ = Describe("ToMediaFile", func() {
other := toMediaFile(otherTags)
Expect(other.AlbumID).To(Equal(mp3.AlbumID))
Expect(other.Year).To(Equal(2022))
Expect(other.ReleaseDate).To(Equal("2022"))
},
Entry("M4A", "©day"),
Entry("WMA", "WM/Year"),
+1 -1
View File
@@ -124,7 +124,7 @@ main:
aliases: [ tdrc, date, recordingdate, icrd, record date ]
type: date
releasedate:
aliases: [ tdrl, releasedate, year ]
aliases: [ tdrl, releasedate, ©day, wm/year, year ]
type: date
catalognumber:
aliases: [ txxx:catalognumber, catalognumber, ----:com.apple.itunes:catalognumber, wm/catalogno ]
+1 -1
View File
@@ -457,7 +457,7 @@ The scanner's behavior can be customized through several configuration settings
| Setting | Description | Default |
|-------------|---------------------------------------------------------------------|---------------------------------------------------------------------|
| `PID.Track` | Format for track persistent IDs (critical for tracking moved files) | "musicbrainz_trackid\|albumid,discnumber,tracknumber,title" |
| `PID.Album` | Format for album persistent IDs (affects album grouping) | "musicbrainz_albumid\|albumartistid,album,albumversion,releasedate" |
| `PID.Album` | Format for album persistent IDs (affects album grouping) | "musicbrainz_albumid\|albumartistid,album,albumversion" |
These options can be set in the Navidrome configuration file (e.g., `navidrome.toml`) or via environment variables with the `ND_` prefix (e.g., `ND_SCANNER_ENABLED=false`). For environment variables, dots in option names are replaced with underscores.
+12 -1
View File
@@ -511,7 +511,18 @@ var _ = Describe("Scanner", Ordered, func() {
})
})
It("should import as two distinct albums", func() {
It("should import as one album with the default album PID", func() {
Expect(runScanner(ctx, true)).To(Succeed())
albums, err := ds.Album().GetAll(ctx)
Expect(err).ToNot(HaveOccurred())
Expect(albums).To(HaveLen(1))
})
It("should import as two distinct albums when the album PID has releasedate", func() {
conf.Update(func(c *conf.Options) {
c.PID.Album = "musicbrainz_albumid|albumartistid,album,albumversion,releasedate"
})
Expect(runScanner(ctx, true)).To(Succeed())
albums, err := ds.Album().GetAll(ctx, model.QueryOptions{Sort: "release_date"})
+1 -1
View File
@@ -32,7 +32,7 @@ const defaultConfig = {
listenBrainzEnabled: true,
enableExternalServices: true,
enableCoverAnimation: true,
pidAlbum: 'musicbrainz_albumid|albumartistid,album,albumversion,releasedate', // See consts.DefaultAlbumPID
pidAlbum: 'musicbrainz_albumid|albumartistid,album,albumversion', // See consts.DefaultAlbumPID
pidTrack: 'musicbrainz_trackid|albumid,discnumber,tracknumber,title', // See consts.DefaultTrackPID
enableNowPlaying: true,
playbackReportIntervalMs: 60000,