mirror of
https://github.com/navidrome/navidrome.git
synced 2026-06-19 07:37:15 +00:00
refactor(scanner): wire buildArtists through computeArtistPID
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
"github.com/navidrome/navidrome/consts"
|
||||
"github.com/navidrome/navidrome/model"
|
||||
"github.com/navidrome/navidrome/model/id"
|
||||
"github.com/navidrome/navidrome/utils/str"
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
@@ -100,11 +101,15 @@ func (md Metadata) processPerformers(participants model.Participants, rolesMbzId
|
||||
subRole := titleCaser.String(performer.Key())
|
||||
|
||||
artist := model.Artist{
|
||||
ID: md.artistID(name),
|
||||
Name: name,
|
||||
OrderArtistName: str.SanitizeFieldForSortingNoArticle(name),
|
||||
MbzArtistID: md.getPerformerMbid(subRole, rolesMbzIdMap, roleIdx),
|
||||
}
|
||||
artist.ID = computeArtistPID(
|
||||
model.Participant{Artist: artist},
|
||||
conf.Server.PID.Artist,
|
||||
id.NewHash,
|
||||
)
|
||||
participants.AddWithSubRole(model.RolePerformer, subRole, artist)
|
||||
}
|
||||
}
|
||||
@@ -154,9 +159,7 @@ func (md Metadata) parseArtists(
|
||||
func (md Metadata) buildArtists(names, sorts, mbids []string) []model.Artist {
|
||||
var artists []model.Artist
|
||||
for i, name := range names {
|
||||
id := md.artistID(name)
|
||||
artist := model.Artist{
|
||||
ID: id,
|
||||
Name: name,
|
||||
OrderArtistName: str.SanitizeFieldForSortingNoArticle(name),
|
||||
}
|
||||
@@ -166,6 +169,12 @@ func (md Metadata) buildArtists(names, sorts, mbids []string) []model.Artist {
|
||||
if i < len(mbids) {
|
||||
artist.MbzArtistID = mbids[i]
|
||||
}
|
||||
// Compute ID from the participant fields we just populated so MBID/sort-based specs work.
|
||||
artist.ID = computeArtistPID(
|
||||
model.Participant{Artist: artist},
|
||||
conf.Server.PID.Artist,
|
||||
id.NewHash,
|
||||
)
|
||||
artists = append(artists, artist)
|
||||
}
|
||||
return artists
|
||||
|
||||
@@ -139,14 +139,6 @@ func getArtistPIDAttr(p model.Participant, attr string, hash hashFunc) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// artistID is kept temporarily as a thin wrapper so any in-progress callers
|
||||
// continue to compile; it will be removed once map_participants.go switches
|
||||
// to computeArtistPID directly (Task 4).
|
||||
func (md Metadata) artistID(name string) string {
|
||||
return computeArtistPID(model.Participant{Artist: model.Artist{Name: name}},
|
||||
conf.Server.PID.Artist, id.NewHash)
|
||||
}
|
||||
|
||||
func (md Metadata) mapTrackTitle() string {
|
||||
if title := md.String(model.TagTitle); title != "" {
|
||||
return title
|
||||
|
||||
@@ -381,4 +381,19 @@ var _ = Describe("computeArtistPID", func() {
|
||||
NotTo(Panic())
|
||||
})
|
||||
})
|
||||
|
||||
It("buildArtists produces the same Artist.ID as the legacy artistID() under default PID.Artist", func() {
|
||||
DeferCleanup(configtest.SetupConfig())
|
||||
conf.Server.PID.Artist = consts.DefaultArtistPID
|
||||
|
||||
name := "Some Artist"
|
||||
md := Metadata{}
|
||||
artists := md.buildArtists([]string{name}, nil, nil)
|
||||
|
||||
// Legacy result computed independently via the old "albumartistid" path:
|
||||
legacyMF := model.MediaFile{AlbumArtist: name}
|
||||
expected := computePID(legacyMF, Metadata{}, "albumartistid", false, id.NewHash)
|
||||
Expect(artists).To(HaveLen(1))
|
||||
Expect(artists[0].ID).To(Equal(expected))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user