Move alternative tag names mapping to metadata
This commit is contained in:
@@ -16,10 +16,9 @@ import (
|
||||
"github.com/navidrome/navidrome/log"
|
||||
)
|
||||
|
||||
type ParsedTags = map[string][]string
|
||||
|
||||
type Extractor interface {
|
||||
Parse(files ...string) (map[string]ParsedTags, error)
|
||||
CustomMappings() ParsedTags
|
||||
}
|
||||
|
||||
var extractors = map[string]Extractor{}
|
||||
@@ -49,6 +48,7 @@ func Extract(files ...string) (map[string]Tags, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
tags = tags.Map(p.CustomMappings())
|
||||
result[filePath] = Tags{
|
||||
filePath: filePath,
|
||||
fileInfo: fileInfo,
|
||||
@@ -59,10 +59,27 @@ func Extract(files ...string) (map[string]Tags, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type ParsedTags map[string][]string
|
||||
|
||||
func (p ParsedTags) Map(customMappings ParsedTags) ParsedTags {
|
||||
if customMappings == nil {
|
||||
return p
|
||||
}
|
||||
for tagName, alternatives := range customMappings {
|
||||
for _, altName := range alternatives {
|
||||
if altValue, ok := p[altName]; ok {
|
||||
p[tagName] = append(p[tagName], altValue...)
|
||||
delete(p, altName)
|
||||
}
|
||||
}
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
type Tags struct {
|
||||
filePath string
|
||||
fileInfo os.FileInfo
|
||||
tags map[string][]string
|
||||
tags ParsedTags
|
||||
}
|
||||
|
||||
// Common tags
|
||||
@@ -92,6 +109,7 @@ func (t Tags) Bpm() int { return (int)(math.Round(t.getFloat("tbpm", "
|
||||
func (t Tags) HasPicture() bool { return t.getFirstTagValue("has_picture") != "" }
|
||||
|
||||
// MusicBrainz Identifiers
|
||||
|
||||
func (t Tags) MbzReleaseTrackID() string {
|
||||
return t.getMbzID("musicbrainz_releasetrackid", "musicbrainz release track id")
|
||||
}
|
||||
@@ -148,10 +166,10 @@ func (t Tags) getAllTagValues(tagNames ...string) []string {
|
||||
return values
|
||||
}
|
||||
|
||||
func (t Tags) getSortTag(originalTag string, tagNamess ...string) string {
|
||||
func (t Tags) getSortTag(originalTag string, tagNames ...string) string {
|
||||
formats := []string{"sort%s", "sort_%s", "sort-%s", "%ssort", "%s_sort", "%s-sort"}
|
||||
all := []string{originalTag}
|
||||
for _, tag := range tagNamess {
|
||||
for _, tag := range tagNames {
|
||||
for _, format := range formats {
|
||||
name := fmt.Sprintf(format, tag)
|
||||
all = append(all, name)
|
||||
|
||||
Reference in New Issue
Block a user