feat(library): albums are filed under their album artist, and empty rows are tidied after a scan
release / go (push) Failing after 1m13s
release / web (push) Successful in 1m16s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m4s
release / android (push) Successful in 4m48s
release / Build signed APK (push) Successful in 5m13s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
release / go (push) Failing after 1m13s
release / web (push) Successful in 1m16s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m4s
release / android (push) Successful in 4m48s
release / Build signed APK (push) Successful in 5m13s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
The scanner read only the track artist, so a compilation tagged Various Artists, or an album with one featured-artist track, became one album per track artist. It now files the album under the album artist the file names (ALBUMARTIST / TPE2 / aART, with its MusicBrainz id), and each track keeps its own artist. Tag-read version 9 re-reads the library so existing tracks move back onto one album. A scan now ends by removing album rows no track points to, and artists left with no albums or tracks, telling clients they are gone. Albums whose tracks are only missing stay for Needs a file, an artist a Songs like playlist is seeded from stays, and rows made in the last ten minutes are left alone so a file being added is never caught half way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -548,3 +548,115 @@ func TestScanFiles_ClearsTheMarkWhenAFileReturnsToItsPath_Integration(t *testing
|
||||
t.Error("no library change logged, so clients would still show the track as unplayable")
|
||||
}
|
||||
}
|
||||
|
||||
// An album is filed under its album artist: a compilation's tracks by
|
||||
// different artists, and an album with one featured-artist track, are each
|
||||
// one album, and every track keeps its own artist. The row the old filing
|
||||
// left behind is removed by the scan's tidy-up once a re-read empties it.
|
||||
func TestScanner_AlbumArtistKeepsAnAlbumTogether_Integration(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping scanner integration in -short mode")
|
||||
}
|
||||
dsn := os.Getenv("MINSTREL_TEST_DATABASE_URL")
|
||||
if dsn == "" {
|
||||
t.Skip("MINSTREL_TEST_DATABASE_URL not set")
|
||||
}
|
||||
ctx := context.Background()
|
||||
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
if err := db.Migrate(dsn, logger); err != nil {
|
||||
t.Fatalf("migrate: %v", err)
|
||||
}
|
||||
pool, err := pgxpool.New(ctx, dsn)
|
||||
if err != nil {
|
||||
t.Fatalf("pool: %v", err)
|
||||
}
|
||||
t.Cleanup(pool.Close)
|
||||
if _, err := pool.Exec(ctx, "TRUNCATE tracks, albums, artists RESTART IDENTITY CASCADE"); err != nil {
|
||||
t.Fatalf("truncate: %v", err)
|
||||
}
|
||||
|
||||
root := t.TempDir()
|
||||
song := func(rel, title, artist, albumArtist, album string) string {
|
||||
p := filepath.Join(root, rel)
|
||||
frames := map[string]string{"TIT2": title, "TPE1": artist, "TALB": album}
|
||||
if albumArtist != "" {
|
||||
frames["TPE2"] = albumArtist
|
||||
}
|
||||
writeTestMP3(t, p, frames)
|
||||
return p
|
||||
}
|
||||
song("Summer Hits/01.mp3", "Wave", "Low Tide Choir", "Various Artists", "Summer Hits")
|
||||
song("Summer Hits/02.mp3", "Glass", "Paper Lanterns", "Various Artists", "Summer Hits")
|
||||
song("Night Drive/01.mp3", "Neon", "Paper Lanterns", "Paper Lanterns", "Night Drive")
|
||||
guest := song("Night Drive/02.mp3", "Static", "Paper Lanterns feat. Low Tide Choir", "Paper Lanterns", "Night Drive")
|
||||
|
||||
scanner := New(pool, logger, []string{root}, nil)
|
||||
if _, err := scanner.Scan(ctx, nil); err != nil {
|
||||
t.Fatalf("scan: %v", err)
|
||||
}
|
||||
|
||||
type filing struct{ albumArtist, tracks, trackArtists int }
|
||||
albums := func() map[string]filing {
|
||||
t.Helper()
|
||||
rows, err := pool.Query(ctx, `
|
||||
SELECT a.title, ar.name, count(t.id), count(DISTINCT t.artist_id)
|
||||
FROM albums a JOIN artists ar ON ar.id = a.artist_id
|
||||
LEFT JOIN tracks t ON t.album_id = a.id
|
||||
GROUP BY a.id, a.title, ar.name`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer rows.Close()
|
||||
out := map[string]filing{}
|
||||
names := map[string]string{}
|
||||
for rows.Next() {
|
||||
var title, artist string
|
||||
var tracks, trackArtists int
|
||||
if err := rows.Scan(&title, &artist, &tracks, &trackArtists); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, dup := out[title]; dup {
|
||||
t.Fatalf("album %q has more than one row", title)
|
||||
}
|
||||
names[title] = artist
|
||||
out[title] = filing{tracks: tracks, trackArtists: trackArtists}
|
||||
}
|
||||
if names["Summer Hits"] != "Various Artists" || names["Night Drive"] != "Paper Lanterns" {
|
||||
t.Fatalf("album artists = %v, want Summer Hits by Various Artists and Night Drive by Paper Lanterns", names)
|
||||
}
|
||||
return out
|
||||
}
|
||||
got := albums()
|
||||
if got["Summer Hits"].tracks != 2 || got["Summer Hits"].trackArtists != 2 {
|
||||
t.Errorf("Summer Hits = %+v, want 2 tracks by 2 artists on one album", got["Summer Hits"])
|
||||
}
|
||||
if got["Night Drive"].tracks != 2 || got["Night Drive"].trackArtists != 2 {
|
||||
t.Errorf("Night Drive = %+v, want 2 tracks by 2 artists on one album", got["Night Drive"])
|
||||
}
|
||||
|
||||
// The guest track as the old filing left it: on an album of its own,
|
||||
// made long enough ago for the tidy-up, under an older tag-read version.
|
||||
if _, err := pool.Exec(ctx, `
|
||||
WITH g AS (SELECT artist_id FROM tracks WHERE file_path = $1),
|
||||
a AS (INSERT INTO albums (title, sort_title, artist_id, created_at)
|
||||
SELECT 'Night Drive', 'night drive', artist_id, now() - interval '1 day' FROM g
|
||||
RETURNING id)
|
||||
UPDATE tracks SET album_id = (SELECT id FROM a), tag_read_version = 8 WHERE file_path = $1`, guest); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := scanner.Scan(ctx, nil); err != nil {
|
||||
t.Fatalf("rescan: %v", err)
|
||||
}
|
||||
if got := albums(); got["Night Drive"].tracks != 2 {
|
||||
t.Errorf("after the re-read, Night Drive = %+v, want both tracks back on one album", got["Night Drive"])
|
||||
}
|
||||
var empty int
|
||||
if err := pool.QueryRow(ctx,
|
||||
`SELECT count(*) FROM albums a WHERE NOT EXISTS (SELECT 1 FROM tracks t WHERE t.album_id = a.id)`,
|
||||
).Scan(&empty); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if empty != 0 {
|
||||
t.Errorf("%d empty album rows left after the scan, want the tidy-up to remove them", empty)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user