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
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:
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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"})
|
||||
|
||||
Reference in New Issue
Block a user