mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-08-02 17:18:36 +02:00
fix(reenrich): allow correcting stale release metadata
This commit is contained in:
@@ -43,6 +43,10 @@ type reEnrichRequest struct {
|
||||
DurationMs int64 `json:"duration_ms"`
|
||||
SearchOnline bool `json:"search_online"`
|
||||
UpdateFields []string `json:"update_fields,omitempty"`
|
||||
// ReplaceReleaseMetadata lets an explicit user re-enrich action repair a
|
||||
// stale album identity (for example, a playlist name stored as ALBUM).
|
||||
// Older callers keep the conservative mismatch-preservation behavior.
|
||||
ReplaceReleaseMetadata bool `json:"replace_release_metadata,omitempty"`
|
||||
}
|
||||
|
||||
// shouldUpdateField returns true if the given field group should be updated.
|
||||
@@ -92,10 +96,14 @@ func applyReEnrichTrackMetadata(req *reEnrichRequest, track ExtTrackMetadata) {
|
||||
return
|
||||
}
|
||||
|
||||
sameRelease := reEnrichSameRelease(req.AlbumName, track.AlbumName)
|
||||
albumMatches := reEnrichSameRelease(req.AlbumName, track.AlbumName)
|
||||
sameRelease := req.ReplaceReleaseMetadata || albumMatches
|
||||
if !sameRelease {
|
||||
GoLog("[ReEnrich] Candidate album %q differs from file album %q; keeping release identity (album, cover, positions, date)\n",
|
||||
track.AlbumName, req.AlbumName)
|
||||
} else if req.ReplaceReleaseMetadata && !albumMatches {
|
||||
GoLog("[ReEnrich] Candidate album %q differs from file album %q; replacing release identity as requested\n",
|
||||
track.AlbumName, req.AlbumName)
|
||||
}
|
||||
|
||||
if track.SpotifyID != "" {
|
||||
|
||||
@@ -405,6 +405,44 @@ func TestApplyReEnrichTrackMetadataKeepsReleaseIdentityOnAlbumMismatch(t *testin
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyReEnrichTrackMetadataReplacesStalePlaylistAlbumWhenRequested(t *testing.T) {
|
||||
req := reEnrichRequest{
|
||||
TrackName: "Song",
|
||||
ArtistName: "Artist",
|
||||
AlbumName: "Road Trip Playlist",
|
||||
CoverURL: "https://covers/playlist.jpg",
|
||||
TrackNumber: 42,
|
||||
ReleaseDate: "",
|
||||
ReplaceReleaseMetadata: true,
|
||||
}
|
||||
|
||||
applyReEnrichTrackMetadata(&req, ExtTrackMetadata{
|
||||
Name: "Song",
|
||||
Artists: "Artist",
|
||||
AlbumName: "Actual Album",
|
||||
AlbumArtist: "Artist",
|
||||
CoverURL: "https://covers/album.jpg",
|
||||
TrackNumber: 3,
|
||||
ReleaseDate: "2024-01-01",
|
||||
})
|
||||
|
||||
if req.AlbumName != "Actual Album" {
|
||||
t.Fatalf("album = %q, want actual album", req.AlbumName)
|
||||
}
|
||||
if req.AlbumArtist != "Artist" {
|
||||
t.Fatalf("album artist = %q", req.AlbumArtist)
|
||||
}
|
||||
if req.CoverURL != "https://covers/album.jpg" {
|
||||
t.Fatalf("cover = %q", req.CoverURL)
|
||||
}
|
||||
if req.TrackNumber != 3 {
|
||||
t.Fatalf("track number = %d", req.TrackNumber)
|
||||
}
|
||||
if req.ReleaseDate != "2024-01-01" {
|
||||
t.Fatalf("release date = %q", req.ReleaseDate)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectBestReEnrichTrackPrefersCandidateWithReleaseDate(t *testing.T) {
|
||||
req := reEnrichRequest{
|
||||
TrackName: "Song Title",
|
||||
|
||||
Reference in New Issue
Block a user