feat: scan and return track contributors
Release / Lint and test (push) Successful in 3m1s
Release / Run Release Please (push) Failing after 9s
Release / Build, tag, and publish Docker image (push) Has been skipped
Release / Notify IRC (push) Has been skipped
Release / Build binaries (386, linux) (push) Has been skipped
Release / Build binaries (386, windows) (push) Has been skipped
Release / Build binaries (amd64, darwin) (push) Has been skipped
Release / Build binaries (amd64, linux) (push) Has been skipped
Release / Build binaries (amd64, windows) (push) Has been skipped
Release / Build binaries (arm64, darwin) (push) Has been skipped
Release / Build binaries (arm64, linux) (push) Has been skipped

This commit is contained in:
sentriz
2026-04-23 18:42:29 +01:00
parent f55cc3fe43
commit 3964c04419
18 changed files with 509 additions and 197 deletions

No files matched your search

+55 -21
View File
@@ -54,19 +54,34 @@ func NewMock(opts url.Values) (*DB, error) {
}
func (db *DB) InsertBulkLeftMany(table string, head []string, left int, col []int) error {
if len(col) == 0 {
rows := make([][]any, len(col))
for i, c := range col {
rows[i] = []any{c}
}
return db.InsertBulkLeftManyRows(table, head, left, rows)
}
func (db *DB) InsertBulkLeftManyRows(table string, head []string, left int, rows [][]any) error {
if len(rows) == 0 {
return nil
}
var rows []string
var values []any
for _, c := range col {
rows = append(rows, "(?, ?)")
values = append(values, left, c)
tail := len(head) - 1
placeholder := "(?" + strings.Repeat(", ?", tail) + ")"
placeholders := make([]string, len(rows))
values := make([]any, 0, len(rows)*len(head))
for i, r := range rows {
if len(r) != tail {
return fmt.Errorf("row %d has %d values, expected %d", i, len(r), tail)
}
placeholders[i] = placeholder
values = append(values, left)
values = append(values, r...)
}
q := fmt.Sprintf("INSERT OR IGNORE INTO %q (%s) VALUES %s",
table,
strings.Join(head, ", "),
strings.Join(rows, ", "),
strings.Join(placeholders, ", "),
)
return db.Exec(q, values...).Error
}
@@ -211,20 +226,21 @@ type Track struct {
Filename string `gorm:"not null; unique_index:idx_folder_filename" sql:"default: null"`
FilenameUDec string `sql:"default: null"`
Album *Album
AlbumID int `gorm:"not null; unique_index:idx_folder_filename" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
Artists []*Artist `gorm:"many2many:track_artists"`
Genres []*Genre `gorm:"many2many:track_genres"`
Size int `sql:"default: null"`
Length int `sql:"default: null"`
Bitrate int `sql:"default: null"`
TagTitle string `sql:"default: null"`
TagTitleUDec string `sql:"default: null"`
TagTrackArtist string `sql:"default: null"`
TagTrackNumber int `sql:"default: null"`
TagDiscNumber int `sql:"default: null"`
TagBrainzID string `sql:"default: null"`
TagLyrics string `sql:"default: null"`
TagYear int `sql:"default: null"`
AlbumID int `gorm:"not null; unique_index:idx_folder_filename" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
Artists []*Artist `gorm:"many2many:track_artists"`
Contributors []*TrackContributor `gorm:"foreignkey:track_id"`
Genres []*Genre `gorm:"many2many:track_genres"`
Size int `sql:"default: null"`
Length int `sql:"default: null"`
Bitrate int `sql:"default: null"`
TagTitle string `sql:"default: null"`
TagTitleUDec string `sql:"default: null"`
TagTrackArtist string `sql:"default: null"`
TagTrackNumber int `sql:"default: null"`
TagDiscNumber int `sql:"default: null"`
TagBrainzID string `sql:"default: null"`
TagLyrics string `sql:"default: null"`
TagYear int `sql:"default: null"`
ReplayGainTrackGain float32
ReplayGainTrackPeak float32
@@ -404,6 +420,24 @@ type TrackArtist struct {
ArtistID int `gorm:"not null; unique_index:idx_track_id_artist_id" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
}
type ContributorRole string
const (
ContributorRoleComposer ContributorRole = "composer"
ContributorRoleLyricist ContributorRole = "lyricist"
ContributorRoleRemixer ContributorRole = "remixer"
ContributorRoleConductor ContributorRole = "conductor"
ContributorRoleProducer ContributorRole = "producer"
ContributorRoleArranger ContributorRole = "arranger"
)
type TrackContributor struct {
TrackID int `gorm:"not null; unique_index:idx_track_contributor" sql:"default: null; type:int REFERENCES tracks(id) ON DELETE CASCADE"`
ArtistID int `gorm:"not null; unique_index:idx_track_contributor" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
Role ContributorRole `gorm:"not null; unique_index:idx_track_contributor" sql:"default: null"`
Artist *Artist
}
type ArtistAppearances struct {
ArtistID int `gorm:"not null; unique_index:idx_artist_id_album_id" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
AlbumID int `gorm:"not null; unique_index:idx_artist_id_album_id" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"`
+5
View File
@@ -84,6 +84,7 @@ func (db *DB) Migrate(ctx MigrationContext) error {
construct(ctx, "202512021147", migrateAlbumAddIndexOnCreatedAt),
construct(ctx, "202601201000", migrateAddAlbumDiscTitles),
construct(ctx, "202602061800", migrateAddTrackYear),
construct(ctx, "202604231200", migrateAddTrackContributors),
}
return gormigrate.
@@ -881,6 +882,10 @@ func migrateAddAlbumDiscTitles(tx *gorm.DB, _ MigrationContext) error {
return tx.AutoMigrate(AlbumDiscTitle{}).Error
}
func migrateAddTrackContributors(tx *gorm.DB, _ MigrationContext) error {
return tx.AutoMigrate(TrackContributor{}).Error
}
func migrateAddTrackYear(tx *gorm.DB, _ MigrationContext) error {
step := tx.AutoMigrate(Track{})
if err := step.Error; err != nil {
+48
View File
@@ -485,6 +485,14 @@ func (s *Scanner) populateTrackAndArtists(tx *db.DB, st *State, i int, album *db
return fmt.Errorf("populate track artists: %w", err)
}
contributorIDs, err := populateTrackContributors(tx, track, trags)
if err != nil {
return fmt.Errorf("populate track contributors: %w", err)
}
if err := populateArtistAppearances(tx, album, contributorIDs); err != nil {
return fmt.Errorf("populate contributor appearances: %w", err)
}
// possible album level embedded covers come only from the first track
if i == 0 {
if err := populateAlbumEmbeddedCover(tx, s.scanEmbeddedCover, album, track, trprops); err != nil {
@@ -686,6 +694,46 @@ func populateAlbumArtists(tx *db.DB, album *db.Album, albumArtistIDs []int) erro
return nil
}
//nolint:gochecknoglobals
var contributorTagKeys = []struct {
keys []string
role db.ContributorRole
}{
{[]string{normtag.Remixers, normtag.Remixer}, db.ContributorRoleRemixer},
{[]string{normtag.Composers, normtag.Composer}, db.ContributorRoleComposer},
{[]string{normtag.Lyricists, normtag.Lyricist}, db.ContributorRoleLyricist},
{[]string{normtag.Conductors, normtag.Conductor}, db.ContributorRoleConductor},
{[]string{normtag.Producers, normtag.Producer}, db.ContributorRoleProducer},
{[]string{normtag.Arrangers, normtag.Arranger}, db.ContributorRoleArranger},
}
func populateTrackContributors(tx *db.DB, track *db.Track, trags tags.Tags) ([]int, error) {
if err := tx.Where("track_id=?", track.ID).Delete(db.TrackContributor{}).Error; err != nil {
return nil, fmt.Errorf("delete old track contributors: %w", err)
}
var rows [][]any
var artistIDs []int
for _, rk := range contributorTagKeys {
for _, name := range tags.FirstValues(trags, rk.keys...) {
if name == "" {
continue
}
artist, err := populateArtist(tx, name)
if err != nil {
return nil, fmt.Errorf("populate contributor artist: %w", err)
}
rows = append(rows, []any{artist.ID, string(rk.role)})
artistIDs = append(artistIDs, artist.ID)
}
}
if err := tx.InsertBulkLeftManyRows("track_contributors", []string{"track_id", "artist_id", "role"}, track.ID, rows); err != nil {
return nil, fmt.Errorf("insert bulk track contributors: %w", err)
}
return artistIDs, nil
}
func populateTrackArtists(tx *db.DB, track *db.Track, trackArtistIDs []int) error {
if err := tx.Where("track_id=?", track.ID).Delete(db.TrackArtist{}).Error; err != nil {
return fmt.Errorf("delete old track artists: %w", err)
+68
View File
@@ -461,6 +461,74 @@ func TestMultiFolderWithSharedArtist(t *testing.T) {
}
}
func TestTrackContributors(t *testing.T) {
t.Parallel()
m := mockfs.New(t)
m.AddTrack("artist-a/album-a/track-1.flac")
m.SetTags("artist-a/album-a/track-1.flac", func(tags *mockfs.TagInfo) {
normtag.Set(tags.Tags, normtag.Artist, "artist-a")
normtag.Set(tags.Tags, normtag.AlbumArtist, "artist-a")
normtag.Set(tags.Tags, normtag.Album, "album-a")
normtag.Set(tags.Tags, normtag.Title, "track-1")
normtag.Set(tags.Tags, normtag.Composers, "comp-a", "comp-b")
normtag.Set(tags.Tags, normtag.Remixer, "rem-a")
normtag.Set(tags.Tags, "LYRICIST", "lyr-a")
normtag.Set(tags.Tags, "PRODUCER", "prod-a")
})
m.ScanAndClean()
var track db.Track
require.NoError(t, m.DB().Preload("Contributors.Artist").Where("tag_title=?", "track-1").First(&track).Error)
type pair struct {
Role db.ContributorRole
Artist string
}
var got []pair
for _, c := range track.Contributors {
got = append(got, pair{Role: c.Role, Artist: c.Artist.Name})
}
assert.ElementsMatch(t, []pair{
{db.ContributorRoleComposer, "comp-a"},
{db.ContributorRoleComposer, "comp-b"},
{db.ContributorRoleRemixer, "rem-a"},
{db.ContributorRoleLyricist, "lyr-a"},
{db.ContributorRoleProducer, "prod-a"},
}, got)
// contributor artists should also show up on the album via artist_appearances
for _, name := range []string{"comp-a", "comp-b", "rem-a", "lyr-a", "prod-a"} {
var count int
require.NoError(t, m.DB().
Model(&db.ArtistAppearances{}).
Joins("JOIN artists ON artists.id=artist_appearances.artist_id").
Where("artists.name=?", name).
Count(&count).Error)
assert.Equal(t, 1, count, "expected %q in artist_appearances", name)
}
// re-scanning with a changed composer list should clear the stale row (comp-b)
// and add the new one (comp-c). other roles stay since their tags didn't change.
m.SetTags("artist-a/album-a/track-1.flac", func(tags *mockfs.TagInfo) {
normtag.Set(tags.Tags, normtag.Composers, "comp-a", "comp-c")
})
m.ScanAndClean()
require.NoError(t, m.DB().Preload("Contributors.Artist").Where("tag_title=?", "track-1").First(&track).Error)
got = got[:0]
for _, c := range track.Contributors {
got = append(got, pair{Role: c.Role, Artist: c.Artist.Name})
}
assert.ElementsMatch(t, []pair{
{db.ContributorRoleComposer, "comp-a"},
{db.ContributorRoleComposer, "comp-c"},
{db.ContributorRoleRemixer, "rem-a"},
{db.ContributorRoleLyricist, "lyr-a"},
{db.ContributorRoleProducer, "prod-a"},
}, got)
}
func TestSymlinkedAlbum(t *testing.T) {
t.Parallel()
m := mockfs.NewWithDirs(t, []string{"scan"})
+1
View File
@@ -44,6 +44,7 @@ func (c *Controller) ServeGetBookmarks(r *http.Request) *spec.Response {
Preload("Album").
Preload("Album.Artists").
Preload("Artists").
Preload("Contributors.Artist").
Find(&track, "id=?", bookmark.EntryID).
Error
if err != nil {
+8
View File
@@ -113,6 +113,7 @@ func (c *Controller) ServeGetAlbum(r *http.Request) *spec.Response {
return db.
Order("tracks.tag_disc_number, tracks.tag_track_number").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID)
}).
@@ -300,6 +301,7 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
Preload("Album.Artists").
Preload("Genres").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID)
switch {
@@ -479,6 +481,7 @@ func (c *Controller) ServeGetSongsByGenre(r *http.Request) *spec.Response {
Preload("Album").
Preload("Album.Artists").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
Offset(params.GetOrInt("offset", 0)).
@@ -564,6 +567,7 @@ func (c *Controller) ServeGetStarredTwo(r *http.Request) *spec.Response {
Preload("Album").
Preload("Album.Artists").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID)
if m := getMusicFolder(c.musicPaths, params); m != "" {
@@ -637,6 +641,7 @@ func (c *Controller) ServeGetTopSongs(r *http.Request) *spec.Response {
Where("artists.id=?", artist.ID).
Preload("Album").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
Group("tracks.id").
@@ -746,6 +751,7 @@ func getSimilarSongsFromTrack(c *Controller, id specid.ID, params params.Params,
Select("tracks.*").
Preload("Album").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
Where("tracks.tag_title IN (?)", similarTrackNames).
@@ -799,6 +805,7 @@ func getSimilarSongsFromArtist(c *Controller, id specid.ID, params params.Params
err = c.dbc.
Preload("Album").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
Joins("JOIN track_artists ON track_artists.track_id=tracks.id").
@@ -867,6 +874,7 @@ func getSimilarSongsFromAlbum(c *Controller, id specid.ID, params params.Params,
Select("tracks.*").
Preload("Album").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
Where("tracks.tag_title IN (?)", similarTrackNames).
+3 -1
View File
@@ -293,6 +293,7 @@ func (c *Controller) ServeGetSong(r *http.Request) *spec.Response {
Preload("Album").
Preload("Album.Artists").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
First(&track).
@@ -320,6 +321,7 @@ func (c *Controller) ServeGetRandomSongs(r *http.Request) *spec.Response {
Preload("Album").
Preload("Album.Artists").
Preload("Artists").
Preload("Contributors.Artist").
Preload("TrackStar", "user_id=?", user.ID).
Preload("TrackRating", "user_id=?", user.ID).
Joins("JOIN albums ON tracks.album_id=albums.id").
@@ -398,7 +400,7 @@ func (c *Controller) ServeJukebox(r *http.Request) *spec.Response { // nolint:go
switch id.Type {
case specid.Track:
var track db.Track
if err := c.dbc.Where("id=?", id.Value).Preload("Album").Preload("Album.Artists").Preload("Artists").Find(&track).Error; err != nil {
if err := c.dbc.Where("id=?", id.Value).Preload("Album").Preload("Album.Artists").Preload("Artists").Preload("Contributors.Artist").Find(&track).Error; err != nil {
return nil, fmt.Errorf("load track: %w", err)
}
ret = append(ret, spec.NewTrackByTags(&track, track.Album))
+27 -6
View File
@@ -3,7 +3,9 @@ package spec
import (
"cmp"
"path/filepath"
"slices"
"sort"
"strings"
"go.senan.xyz/gonic/db"
)
@@ -118,12 +120,8 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild {
ret.UserRating = t.TrackRating.Rating
}
sort.Slice(t.Artists, func(i, j int) bool {
return t.Artists[i].ID < t.Artists[j].ID
})
sort.Slice(album.Artists, func(i, j int) bool {
return album.Artists[i].ID < album.Artists[j].ID
})
slices.SortFunc(t.Artists, func(a, b *db.Artist) int { return cmp.Compare(a.ID, b.ID) })
slices.SortFunc(album.Artists, func(a, b *db.Artist) int { return cmp.Compare(a.ID, b.ID) })
switch {
case len(t.Artists) > 0:
@@ -145,6 +143,29 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild {
for _, a := range album.Artists {
ret.AlbumArtists = append(ret.AlbumArtists, &ArtistRef{ID: a.SID(), Name: a.Name})
}
slices.SortStableFunc(t.Contributors, func(a, b *db.TrackContributor) int {
return cmp.Or(
cmp.Compare(a.Role, b.Role),
cmp.Compare(a.ArtistID, b.ArtistID),
)
})
var composers []string
for _, c := range t.Contributors {
if c.Artist == nil {
continue
}
ret.Contributors = append(ret.Contributors, &Contributor{
Role: string(c.Role),
Artist: &ArtistRef{ID: c.Artist.SID(), Name: c.Artist.Name},
})
if c.Role == db.ContributorRoleComposer {
composers = append(composers, c.Artist.Name)
}
}
ret.DisplayComposer = strings.Join(composers, ", ")
if t.ReplayGainTrackGain != 0 || t.ReplayGainAlbumGain != 0 {
ret.ReplayGain = &ReplayGain{
TrackGain: t.ReplayGainTrackGain,
+9
View File
@@ -125,6 +125,12 @@ type GenreRef struct {
Name string `xml:"name,attr" json:"name"`
}
// https://opensubsonic.netlify.app/docs/responses/contributor/
type Contributor struct {
Role string `xml:"role,attr" json:"role"`
Artist *ArtistRef `xml:"artist" json:"artist"`
}
type DiscTitle struct {
Disc int `xml:"disc,attr" json:"disc"`
Title string `xml:"title,attr" json:"title"`
@@ -204,6 +210,9 @@ type TrackChild struct {
AlbumArtists []*ArtistRef `xml:"albumArtists" json:"albumArtists"`
AlbumDisplayArtist string `xml:"displayAlbumArtist,attr" json:"displayAlbumArtist"`
Contributors []*Contributor `xml:"contributors" json:"contributors"`
DisplayComposer string `xml:"displayComposer,attr" json:"displayComposer"`
Bitrate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
ContentType string `xml:"contentType,attr,omitempty" json:"contentType,omitempty"`
CoverID *specid.ID `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
+74 -74
View File
@@ -8,55 +8,17 @@
"albumList": {
"album": [
{
"id": "al-11",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-2",
"artists": null,
"displayArtist": "",
"title": "album-0",
"album": "album-0",
"parent": "al-10",
"isDir": true,
"coverArt": "al-11",
"name": "album-0",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-13",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-2",
"artists": null,
"displayArtist": "",
"title": "album-2",
"album": "album-2",
"parent": "al-10",
"isDir": true,
"coverArt": "al-13",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-7",
"id": "al-8",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-1",
"artists": null,
"displayArtist": "",
"title": "album-0",
"album": "album-0",
"title": "album-1",
"album": "album-1",
"parent": "al-6",
"isDir": true,
"coverArt": "al-7",
"name": "album-0",
"coverArt": "al-8",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
@@ -84,17 +46,17 @@
"discTitles": null
},
{
"id": "al-4",
"id": "al-11",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-0",
"artist": "artist-2",
"artists": null,
"displayArtist": "",
"title": "album-1",
"album": "album-1",
"parent": "al-2",
"title": "album-0",
"album": "album-0",
"parent": "al-10",
"isDir": true,
"coverArt": "al-4",
"name": "album-1",
"coverArt": "al-11",
"name": "album-0",
"songCount": 3,
"duration": 300,
"playCount": 0,
@@ -103,17 +65,17 @@
"discTitles": null
},
{
"id": "al-8",
"id": "al-7",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-1",
"artists": null,
"displayArtist": "",
"title": "album-1",
"album": "album-1",
"title": "album-0",
"album": "album-0",
"parent": "al-6",
"isDir": true,
"coverArt": "al-8",
"name": "album-1",
"coverArt": "al-7",
"name": "album-0",
"songCount": 3,
"duration": 300,
"playCount": 0,
@@ -140,25 +102,6 @@
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-12",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-2",
"artists": null,
"displayArtist": "",
"title": "album-1",
"album": "album-1",
"parent": "al-10",
"isDir": true,
"coverArt": "al-12",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-3",
"created": "2019-11-30T00:00:00Z",
@@ -177,6 +120,63 @@
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-4",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-0",
"artists": null,
"displayArtist": "",
"title": "album-1",
"album": "album-1",
"parent": "al-2",
"isDir": true,
"coverArt": "al-4",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-13",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-2",
"artists": null,
"displayArtist": "",
"title": "album-2",
"album": "album-2",
"parent": "al-10",
"isDir": true,
"coverArt": "al-13",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
},
{
"id": "al-12",
"created": "2019-11-30T00:00:00Z",
"artist": "artist-2",
"artists": null,
"displayArtist": "",
"title": "album-1",
"album": "album-1",
"parent": "al-10",
"isDir": true,
"coverArt": "al-12",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
"isCompilation": false,
"releaseTypes": [],
"discTitles": null
}
]
}
+83 -83
View File
@@ -8,79 +8,16 @@
"albumList2": {
"album": [
{
"id": "al-12",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"displayArtist": "artist-2",
"title": "album-1",
"album": "album-1",
"coverArt": "al-12",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
"genre": "Unknown Genre",
"genres": [{ "name": "Unknown Genre" }],
"year": 2021,
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
},
{
"id": "al-5",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"title": "album-2",
"album": "album-2",
"coverArt": "al-5",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"genre": "Unknown Genre",
"genres": [{ "name": "Unknown Genre" }],
"year": 2021,
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
},
{
"id": "al-9",
"id": "al-8",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"displayArtist": "artist-1",
"title": "album-2",
"album": "album-2",
"coverArt": "al-9",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"genre": "Unknown Genre",
"genres": [{ "name": "Unknown Genre" }],
"year": 2021,
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
},
{
"id": "al-3",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"title": "album-0",
"album": "album-0",
"coverArt": "al-3",
"name": "album-0",
"title": "album-1",
"album": "album-1",
"coverArt": "al-8",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
@@ -134,16 +71,16 @@
"discTitles": []
},
{
"id": "al-8",
"id": "al-3",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"displayArtist": "artist-1",
"title": "album-1",
"album": "album-1",
"coverArt": "al-8",
"name": "album-1",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"title": "album-0",
"album": "album-0",
"coverArt": "al-3",
"name": "album-0",
"songCount": 3,
"duration": 300,
"playCount": 0,
@@ -155,15 +92,15 @@
"discTitles": []
},
{
"id": "al-4",
"id": "al-12",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"artistId": "ar-3",
"artist": "artist-2",
"artists": [{ "id": "ar-3", "name": "artist-2" }],
"displayArtist": "artist-2",
"title": "album-1",
"album": "album-1",
"coverArt": "al-4",
"coverArt": "al-12",
"name": "album-1",
"songCount": 3,
"duration": 300,
@@ -195,6 +132,69 @@
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
},
{
"id": "al-9",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-2",
"artist": "artist-1",
"artists": [{ "id": "ar-2", "name": "artist-1" }],
"displayArtist": "artist-1",
"title": "album-2",
"album": "album-2",
"coverArt": "al-9",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"genre": "Unknown Genre",
"genres": [{ "name": "Unknown Genre" }],
"year": 2021,
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
},
{
"id": "al-5",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"title": "album-2",
"album": "album-2",
"coverArt": "al-5",
"name": "album-2",
"songCount": 3,
"duration": 300,
"playCount": 0,
"genre": "Unknown Genre",
"genres": [{ "name": "Unknown Genre" }],
"year": 2021,
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
},
{
"id": "al-4",
"created": "2019-11-30T00:00:00Z",
"artistId": "ar-1",
"artist": "artist-0",
"artists": [{ "id": "ar-1", "name": "artist-0" }],
"displayArtist": "artist-0",
"title": "album-1",
"album": "album-1",
"coverArt": "al-4",
"name": "album-1",
"songCount": 3,
"duration": 300,
"playCount": 0,
"genre": "Unknown Genre",
"genres": [{ "name": "Unknown Genre" }],
"year": 2021,
"isCompilation": false,
"releaseTypes": ["Album"],
"discTitles": []
}
]
}
@@ -33,6 +33,8 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -61,6 +63,8 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -89,6 +93,8 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -20,6 +20,8 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -48,6 +50,8 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -76,6 +80,8 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -17,6 +17,8 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-3",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -34,6 +36,8 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-4",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -51,6 +55,8 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-5",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
+40
View File
@@ -17,6 +17,8 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -47,6 +49,8 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -77,6 +81,8 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -107,6 +113,8 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-4",
@@ -137,6 +145,8 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-4",
@@ -167,6 +177,8 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-4",
@@ -197,6 +209,8 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-5",
@@ -227,6 +241,8 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-5",
@@ -257,6 +273,8 @@
"displayArtist": "artist-0",
"albumArtists": [{ "id": "ar-1", "name": "artist-0" }],
"displayAlbumArtist": "artist-0",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-5",
@@ -287,6 +305,8 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-7",
@@ -317,6 +337,8 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-7",
@@ -347,6 +369,8 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-7",
@@ -377,6 +401,8 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-8",
@@ -407,6 +433,8 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-8",
@@ -437,6 +465,8 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-8",
@@ -467,6 +497,8 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-9",
@@ -497,6 +529,8 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-9",
@@ -527,6 +561,8 @@
"displayArtist": "artist-1",
"albumArtists": [{ "id": "ar-2", "name": "artist-1" }],
"displayAlbumArtist": "artist-1",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-9",
@@ -557,6 +593,8 @@
"displayArtist": "artist-2",
"albumArtists": [{ "id": "ar-3", "name": "artist-2" }],
"displayAlbumArtist": "artist-2",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-11",
@@ -587,6 +625,8 @@
"displayArtist": "artist-2",
"albumArtists": [{ "id": "ar-3", "name": "artist-2" }],
"displayAlbumArtist": "artist-2",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-11",
+18
View File
@@ -14,6 +14,8 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-3",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -31,6 +33,8 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-4",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -48,6 +52,8 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-5",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -65,6 +71,8 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-7",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -82,6 +90,8 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-8",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -99,6 +109,8 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-9",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -116,6 +128,8 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-11",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -133,6 +147,8 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-12",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
@@ -150,6 +166,8 @@
"displayArtist": "",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"coverArt": "al-13",
"created": "2019-11-30T00:00:00Z",
"isDir": true,
+40
View File
@@ -17,6 +17,8 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -45,6 +47,8 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -73,6 +77,8 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-3",
@@ -101,6 +107,8 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-4",
@@ -129,6 +137,8 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-4",
@@ -157,6 +167,8 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-4",
@@ -185,6 +197,8 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-5",
@@ -213,6 +227,8 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-5",
@@ -241,6 +257,8 @@
"displayArtist": "artist-0",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-5",
@@ -269,6 +287,8 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-7",
@@ -297,6 +317,8 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-7",
@@ -325,6 +347,8 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-7",
@@ -353,6 +377,8 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-8",
@@ -381,6 +407,8 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-8",
@@ -409,6 +437,8 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-8",
@@ -437,6 +467,8 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-9",
@@ -465,6 +497,8 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-9",
@@ -493,6 +527,8 @@
"displayArtist": "artist-1",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-9",
@@ -521,6 +557,8 @@
"displayArtist": "artist-2",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-11",
@@ -549,6 +587,8 @@
"displayArtist": "artist-2",
"albumArtists": null,
"displayAlbumArtist": "",
"contributors": null,
"displayComposer": "",
"bitRate": 100,
"contentType": "audio/flac",
"coverArt": "al-11",
+12 -12
View File
@@ -33,6 +33,15 @@ const (
FallbackGenre = "Unknown Genre"
)
func FirstValues(p Tags, keys ...string) []string {
for _, k := range keys {
if v := normtag.Values(p, k); len(v) > 0 {
return v
}
}
return nil
}
func MustAlbum(p Tags) string {
if r := normtag.Get(p, normtag.Album); r != "" {
return r
@@ -48,10 +57,7 @@ func MustArtist(p Tags) string {
}
func MustArtists(p Tags) []string {
if r := normtag.Values(p, normtag.Artists); len(r) > 0 {
return r
}
if r := normtag.Values(p, normtag.Artist); len(r) > 0 {
if r := FirstValues(p, normtag.Artists, normtag.Artist); len(r) > 0 {
return r
}
return []string{FallbackArtist}
@@ -65,10 +71,7 @@ func MustAlbumArtist(p Tags) string {
}
func MustAlbumArtists(p Tags) []string {
if r := normtag.Values(p, normtag.AlbumArtists); len(r) > 0 {
return r
}
if r := normtag.Values(p, normtag.AlbumArtist); len(r) > 0 {
if r := FirstValues(p, normtag.AlbumArtists, normtag.AlbumArtist); len(r) > 0 {
return r
}
return []string{MustArtist(p)}
@@ -82,10 +85,7 @@ func MustGenre(p Tags) string {
}
func MustGenres(p Tags) []string {
if r := normtag.Values(p, normtag.Genres); len(r) > 0 {
return r
}
if r := normtag.Values(p, normtag.Genre); len(r) > 0 {
if r := FirstValues(p, normtag.Genres, normtag.Genre); len(r) > 0 {
return r
}
return []string{FallbackGenre}