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:
@@ -78,7 +78,13 @@ var audioExtensions = map[string]bool{
|
||||
// 8: a file tagged with no release group joins the same-named album that
|
||||
// already holds a track from its folder. Under 7 it took the oldest row,
|
||||
// which could file a bonus track on a later album of the same name.
|
||||
const tagReadVersion int16 = 8
|
||||
// 9: an album is filed under its album artist (ALBUMARTIST / TPE2 / aART,
|
||||
// with its MusicBrainz id) when the file names one, not under the
|
||||
// track's artist. A compilation, or an album with one featured-artist
|
||||
// track, was split into an album per track artist; a re-read files each
|
||||
// track back on the one album, and the scan's tidy-up removes the rows
|
||||
// it leaves empty.
|
||||
const tagReadVersion int16 = 9
|
||||
|
||||
type Stats struct {
|
||||
Scanned int `json:"scanned"`
|
||||
@@ -214,9 +220,45 @@ func (s *Scanner) Scan(ctx context.Context, progressCb func(Stats)) (Stats, erro
|
||||
// marked and then healed, is not reported as lost.
|
||||
s.notifyStillMissing(ctx, stats.marked)
|
||||
s.announceNewAlbums(ctx)
|
||||
s.tidyEmptyRows(ctx)
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
// tidyEmptyRows removes the album rows no track points to any more, and the
|
||||
// artists left with neither albums nor tracks. Re-filing a track (a re-read
|
||||
// under a new tag-read version, a moved file, a merged duplicate) can leave
|
||||
// its old album empty, and an empty album would otherwise still show in
|
||||
// album lists. An album whose tracks are only missing keeps its row: those
|
||||
// tracks wait in Needs a file. Not fatal; the next scan tries again.
|
||||
func (s *Scanner) tidyEmptyRows(ctx context.Context) {
|
||||
q := dbq.New(s.pool)
|
||||
albums, err := q.DeleteEmptyAlbums(ctx)
|
||||
if err != nil {
|
||||
s.logger.Warn("library scan: removing empty albums failed", "err", err)
|
||||
return
|
||||
}
|
||||
artists, err := q.DeleteEmptyArtists(ctx)
|
||||
if err != nil {
|
||||
s.logger.Warn("library scan: removing empty artists failed", "err", err)
|
||||
}
|
||||
if len(albums) == 0 && len(artists) == 0 {
|
||||
return
|
||||
}
|
||||
s.logger.Info("library scan: removed empty rows", "albums", len(albums), "artists", len(artists))
|
||||
for _, c := range []struct {
|
||||
entity syncpkg.EntityType
|
||||
ids []pgtype.UUID
|
||||
}{{syncpkg.EntityAlbum, albums}, {syncpkg.EntityArtist, artists}} {
|
||||
ids := make([]string, len(c.ids))
|
||||
for i, id := range c.ids {
|
||||
ids[i] = syncpkg.FormatUUID(id)
|
||||
}
|
||||
if err := syncpkg.LogChanges(ctx, s.pool, c.entity, ids, syncpkg.OpDelete); err != nil {
|
||||
s.logger.Warn("library scan: logging removed rows failed", "entity", c.entity, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// enumerate walks every configured root and returns the audio paths found, in
|
||||
// walk order, plus a count of walk errors.
|
||||
//
|
||||
@@ -345,7 +387,18 @@ func (s *Scanner) scanFile(
|
||||
if err != nil {
|
||||
return pgtype.UUID{}, false, fmt.Errorf("artist: %w", err)
|
||||
}
|
||||
album, err := s.resolveAlbum(ctx, q, artist.ID, albumTitle, meta.Year(), albumMBID, releaseGroupMBID, filepath.Dir(path))
|
||||
// The album belongs to its album artist when the file names one: every
|
||||
// track of a compilation, or of an album with a featured guest, then
|
||||
// lands on one album instead of one per track artist. The track keeps
|
||||
// its own artist.
|
||||
albumArtist := artist
|
||||
if name := strings.TrimSpace(meta.AlbumArtist()); name != "" && name != artistName {
|
||||
albumArtist, err = s.resolveArtist(ctx, q, name, ids.AlbumArtist)
|
||||
if err != nil {
|
||||
return pgtype.UUID{}, false, fmt.Errorf("album artist: %w", err)
|
||||
}
|
||||
}
|
||||
album, err := s.resolveAlbum(ctx, q, albumArtist.ID, albumTitle, meta.Year(), albumMBID, releaseGroupMBID, filepath.Dir(path))
|
||||
if err != nil {
|
||||
return pgtype.UUID{}, false, fmt.Errorf("album: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user