JSPF: Include full LB additional info in metadata

This commit is contained in:
Philipp Wolfer 2023-11-23 08:28:17 +01:00
parent 36cc41d05d
commit 68b2e649f0
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
3 changed files with 100 additions and 14 deletions

View file

@ -51,6 +51,48 @@ func (t Track) ArtistName() string {
return strings.Join(t.ArtistNames, ", ")
}
// Updates AdditionalInfo to have standard fields as defined by ListenBrainz
func (t *Track) FillAdditionalInfo() {
if t.AdditionalInfo == nil {
t.AdditionalInfo = make(AdditionalInfo, 5)
}
if t.RecordingMbid != "" {
t.AdditionalInfo["recording_mbid"] = t.RecordingMbid
}
if t.ReleaseGroupMbid != "" {
t.AdditionalInfo["release_group_mbid"] = t.ReleaseGroupMbid
}
if t.ReleaseMbid != "" {
t.AdditionalInfo["release_mbid"] = t.ReleaseMbid
}
if len(t.ArtistMbids) > 0 {
t.AdditionalInfo["artist_mbids"] = t.ArtistMbids
}
if len(t.WorkMbids) > 0 {
t.AdditionalInfo["work_mbids"] = t.WorkMbids
}
if t.ISRC != "" {
t.AdditionalInfo["isrc"] = t.ISRC
}
if t.TrackNumber != 0 {
t.AdditionalInfo["tracknumber"] = t.TrackNumber
}
if t.DiscNumber != 0 {
t.AdditionalInfo["discnumber"] = t.DiscNumber
}
if t.Duration != 0 {
rounded := t.Duration.Round(time.Second)
if t.Duration == rounded {
t.AdditionalInfo["duration"] = int64(t.Duration.Seconds())
} else {
t.AdditionalInfo["duration_ms"] = t.Duration.Milliseconds()
}
}
if len(t.Tags) > 0 {
t.AdditionalInfo["tags"] = t.Tags
}
}
type Listen struct {
Track
ListenedAt time.Time