get info about genere from musicbrainz in info

This commit is contained in:
2026-05-20 22:22:18 +02:00
parent f520cc8913
commit 0a7849ebfa
3 changed files with 68 additions and 7 deletions

View File

@@ -6,8 +6,11 @@ import (
"os"
"path/filepath"
"regexp"
"slices"
"sort"
"strings"
"git.kapelle.org/niklas/ripsort/internal/clients/musicbrainz"
"github.com/dhowden/tag"
)
@@ -21,6 +24,7 @@ type Metadata struct {
Comment *string
ISRC *string
Date *string
Genre []string
SpotifyID *string
}
@@ -61,6 +65,7 @@ func readGenericAudioTags(filePath string) (*Metadata, error) {
Track: track,
TotalTracks: totalTracks,
Comment: &comment,
Genre: []string{m.Genre()},
}
commentToSpotifyid(info)
@@ -110,3 +115,39 @@ func commentToSpotifyid(m *Metadata) {
m.SpotifyID = &id
}
func SearchForGenre(mbc *musicbrainz.MusicBrainzClient, m *Metadata) ([]string, error) {
if m.ISRC == nil {
return []string{}, nil
}
res, err := mbc.SearchByISRC(*m.ISRC, musicbrainz.SearchOptions{})
if err != nil {
return []string{}, err
}
if len(res.Recordings) == 0 {
return []string{}, nil
}
allTags := []musicbrainz.Tag{}
for _, rec := range res.Recordings {
allTags = append(allTags, rec.Tags...)
}
sort.Slice(allTags[:], func(i int, j int) bool {
return allTags[i].Count > allTags[j].Count
})
allTags = slices.CompactFunc(allTags, func(lhs, rhs musicbrainz.Tag) bool {
return lhs.Name == rhs.Name
})
finalTags := []string{}
for _, tag := range allTags {
finalTags = append(finalTags, tag.Name)
}
return finalTags, nil
}