fix: scan records the probed format + skips hidden album dirs (probe once)
Probe each album exactly once and thread the ProbeResult through for tags, quality, and format instead of hardcoding LibraryItem.format to "FLAC" and re-probing on the tag-fallback path. Also skip album-level directories starting with "." (previously only artist-level dirs were skipped).
This commit is contained in:
@@ -28,7 +28,7 @@ def _first_audio(album_path: str) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def _upsert(conn, target, quality_class: int, path: str) -> bool:
|
||||
def _upsert(conn, target, quality_class: int, fmt: str, path: str) -> bool:
|
||||
"""Record have + monitored + followed for a resolved album. Returns True if newly imported."""
|
||||
with conn.cursor() as cur:
|
||||
watched_id = None
|
||||
@@ -61,7 +61,7 @@ def _upsert(conn, target, quality_class: int, path: str) -> bool:
|
||||
'"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, "FLAC", quality_class),
|
||||
(target.artist, target.album, path, fmt, quality_class),
|
||||
)
|
||||
newly = cur.rowcount == 1 # a new LibraryItem means this album wasn't recorded before
|
||||
conn.commit()
|
||||
@@ -81,21 +81,20 @@ def scan_library(conn: psycopg.Connection, resolver, probe: AudioProbe, dest_roo
|
||||
continue
|
||||
for album_folder in sorted(os.listdir(artist_path)):
|
||||
album_path = os.path.join(artist_path, album_folder)
|
||||
if not os.path.isdir(album_path):
|
||||
if album_folder.startswith(".") or not os.path.isdir(album_path):
|
||||
continue
|
||||
audio = _first_audio(album_path)
|
||||
if audio is None:
|
||||
continue # no audio → not an album
|
||||
pr = probe.probe(audio)
|
||||
album_name = _parse_album_dir(album_folder)
|
||||
target = resolver.resolve(artist_name, album_name) if artist_name and album_name else None
|
||||
if target is None: # fall back to the file's embedded tags
|
||||
pr = probe.probe(audio)
|
||||
if pr.artist and pr.album and (pr.artist, pr.album) != (artist_name, album_name):
|
||||
target = resolver.resolve(pr.artist, pr.album)
|
||||
if target is None:
|
||||
skipped += 1
|
||||
continue
|
||||
q = probe.probe(audio).quality_class
|
||||
if _upsert(conn, target, q, album_path):
|
||||
if _upsert(conn, target, pr.quality_class, pr.fmt, album_path):
|
||||
imported += 1
|
||||
return ScanResult(imported, skipped)
|
||||
|
||||
Reference in New Issue
Block a user