feat: show real on-disk tracklist in the Library album modal (#9)
The Library modal showed MusicBrainz's canonical tracklist, hiding incomplete downloads / edition or track-order mismatches, and showed nothing for albums without an rgMbid. Now it shows the REAL files on disk. - LibraryItem gains trackNames String[] (migration add_library_track_names): the album's on-disk "## Title.ext" audio filenames. - Captured at import (pipeline._import lists the final album folder) and at scan (scan._record_owned now also refreshes trackNames on re-scan via ON CONFLICT DO UPDATE + xmax=0 to preserve the newly-imported flag). New shared library.list_audio_files() helper. - /api/library exposes trackNames; the AlbumModal prefers on-disk tracks when present (parsed "## Title" → position/title, zero network, labeled "On disk · N tracks"), falling back to the MusicBrainz listing otherwise. Items imported before this column show the MB fallback until re-scanned. worker 221 tests / 7-skip, web 153, tsc + build clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ from dataclasses import dataclass
|
||||
|
||||
import psycopg
|
||||
|
||||
from lyra_worker.library import list_audio_files
|
||||
from lyra_worker.probe import AudioProbe
|
||||
|
||||
_AUDIO_EXT = {".flac", ".mp3", ".m4a", ".opus", ".ogg", ".aac", ".wav"}
|
||||
@@ -80,14 +81,18 @@ def _record_owned(conn, target, quality_class: int, fmt: str, path: str, watched
|
||||
' "watchedArtistId" = COALESCE("MonitoredRelease"."watchedArtistId", EXCLUDED."watchedArtistId")',
|
||||
(watched_id, target.artist_mbid, target.artist, target.rg_mbid, target.album, quality_class),
|
||||
)
|
||||
track_names = list_audio_files(path) # capture the real on-disk tracks
|
||||
cur.execute(
|
||||
'INSERT INTO "LibraryItem" (id, "requestId", artist, album, path, source, format, '
|
||||
'"qualityClass", "importedAt") '
|
||||
"VALUES (gen_random_uuid()::text, NULL, %s, %s, %s, 'scan', %s, %s, now()) "
|
||||
'ON CONFLICT (artist, album) DO NOTHING',
|
||||
(target.artist, target.album, path, fmt, quality_class),
|
||||
'"qualityClass", "trackNames", "importedAt") '
|
||||
"VALUES (gen_random_uuid()::text, NULL, %s, %s, %s, 'scan', %s, %s, %s, now()) "
|
||||
# refresh trackNames on re-scan (populates items imported before this column);
|
||||
# xmax=0 ⇒ this was an INSERT (a genuinely new library item) vs an UPDATE.
|
||||
'ON CONFLICT (artist, album) DO UPDATE SET "trackNames" = EXCLUDED."trackNames" '
|
||||
"RETURNING (xmax = 0) AS inserted",
|
||||
(target.artist, target.album, path, fmt, quality_class, track_names),
|
||||
)
|
||||
newly = cur.rowcount == 1 # a new LibraryItem means this album wasn't recorded before
|
||||
newly = cur.fetchone()[0] # a new LibraryItem means this album wasn't recorded before
|
||||
conn.commit()
|
||||
return newly
|
||||
|
||||
|
||||
Reference in New Issue
Block a user