Log warning when artist has a MBID of Various Artists

This commit is contained in:
Deluan
2021-07-18 18:28:51 -04:00
parent e61cf3217d
commit 44e7502aef
5 changed files with 32 additions and 29 deletions
+21 -19
View File
@@ -7,8 +7,9 @@ import (
"regexp"
"strings"
"github.com/Masterminds/squirrel"
"github.com/navidrome/navidrome/consts"
"github.com/Masterminds/squirrel"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/utils"
@@ -59,31 +60,32 @@ func (e existsCond) ToSql() (string, []interface{}, error) {
return sql, args, err
}
func getMbzId(ctx context.Context, mbzIDS, entityName, name string) string {
ids := strings.Fields(mbzIDS)
func getMostFrequentMbzID(ctx context.Context, mbzIDs, entityName, name string) string {
ids := strings.Fields(mbzIDs)
if len(ids) == 0 {
return ""
}
if len(ids) == 1 {
return ids[0]
}
idCounts := map[string]int{}
for _, id := range ids {
if c, ok := idCounts[id]; ok {
idCounts[id] = c + 1
} else {
idCounts[id] = 1
}
}
var topKey string
var topId string
var topCount int
for k, v := range idCounts {
if v > topCount {
topKey = k
topCount = v
for _, id := range ids {
c := idCounts[id] + 1
idCounts[id] = c
if c > topCount {
topId = id
topCount = c
}
}
if len(idCounts) > 1 && name != consts.VariousArtists {
log.Warn(ctx, "Multiple MBIDs found for "+entityName, "name", name, "mbids", idCounts)
if name != consts.VariousArtists {
if topId == consts.VariousArtistsMbzId {
log.Warn(ctx, "Artist with mbid of Various Artists", "name", name, "mbid", topId)
} else {
log.Warn(ctx, "Multiple MBIDs found for "+entityName, "name", name, "mbids", idCounts)
}
}
return topKey
return topId
}