v0.15.0: ask the song what it is

Right-click → Identify Track… fingerprints the file with Chromaprint's
fpcalc and asks AcoustID who it is, then proposes the tags it found.

The year is the point. A 60s song kept getting stamped with the year its
CD reissue came out, which sorts the library wrong, so every candidate
carries the recording's *original* year — the earliest release across all
of its release groups — including the candidate that proposes a later
greatest-hits as the album. Ranking separately prefers a plain studio
Album over EP/Single over anything wearing a Compilation or Live
secondary type, so the default proposal is the real album as well.

Nothing is written until accepted: the dialog shows each current value
beside an editable proposed one, and a row starts checked only where the
proposal actually differs from what the file already has, so an untouched
field can never quietly blank a tag. Applying goes through
edit_track_fields, which is what buys the tag write, the abort-if-it-fails
rule, artist/album file relocation and one undo step without re-deriving
any of them.

A selection is a queue reviewed one track at a time; a failure is a
status-bar message that moves on rather than ending the batch. fpcalc is
detected at runtime like ffmpeg and the AcoustID key lives in preferences
(so it syncs, and stays out of git) — the round adds no new dependency.

Also fixes a pre-existing round 40 test that used the real tummult mount
point as its stand-in for an unreachable path, so it failed whenever that
drive was plugged in.

Claude-Session: https://claude.ai/code/session_01NsiFHdyVg1UhBSxDJfTNRm
This commit is contained in:
2026-09-02 15:40:52 -04:00
parent 5831175584
commit 312748d05e
12 changed files with 946 additions and 2 deletions
+90
View File
@@ -14,12 +14,14 @@ from lintunes.art_search import AlbumArtFetcher
from lintunes.cast.controller import CastController
from lintunes.eventlog import log_control
from lintunes.export import exporter
from lintunes.fingerprint import TrackIdentifier, fpcalc_available
from lintunes.inhibit import INHIBIT_LOGOUT, INHIBIT_SUSPEND, SleepInhibitor
from lintunes.player import Player
from lintunes.importers import file_importer
from lintunes.gui.album_art_dialog import AlbumArtDialog
from lintunes.gui.cast_dialog import ChromecastDialog
from lintunes.gui.export_dialog import ExportKindDialog, WebMixDialog
from lintunes.gui.identify_dialog import IdentifyDialog
from lintunes.gui.sidebar import SidebarPanel
from lintunes.gui.library_view import LibraryView
from lintunes.gui.playlist_view import PlaylistView
@@ -159,6 +161,11 @@ class MainWindow(QMainWindow):
# Export shares the status-bar progress widgets with device sync —
# only one of the two may run at a time (each guards on the other).
self._export_worker = None
# Identify Track… works through its selection one at a time, each
# behind its own review dialog.
self._identify_queue = []
self._identify_total = 0
self._identifier = None
# Separate instance from the playback inhibitor: pausing music
# mid-sync must not drop the sync's hold. Logout flag included so
# GNOME's shutdown/restart dialog names the transfer as the blocker.
@@ -182,6 +189,7 @@ class MainWindow(QMainWindow):
view.show_in_playlist_requested.connect(self._show_track_in_playlist)
view.table.tracks_changed.connect(self._update_totals)
view.table.download_art_requested.connect(self._download_album_art)
view.table.identify_requested.connect(self._identify_tracks)
view.table.remove_from_library_requested.connect(
lambda ids: self._delete_tracks(ids, delete_files=False))
view.table.delete_from_library_requested.connect(
@@ -1077,6 +1085,88 @@ class MainWindow(QMainWindow):
self.statusBar().showMessage(
f"Artwork embedded in {done} {noun}", 5000)
# ---- track identification (fingerprint lookup) ----
def _identify_tracks(self, track_ids: list[int]):
"""Fingerprint the selection and look each track up on AcoustID, one
at a time, each behind its own proposal dialog."""
if not fpcalc_available():
QMessageBox.warning(
self, "Identify Track",
"Track identification needs the fpcalc tool from Chromaprint.\n\n"
"Install it (Fedora: chromaprint-tools, Debian: "
"libchromaprint-tools) and try again.")
return
api_key = self._prefs.acoustid.get("api_key", "").strip()
if not api_key:
QMessageBox.information(
self, "Identify Track",
"AcoustID needs a free application key.\n\n"
"Register one at acoustid.org/new-application, then paste it "
"into Preferences under Track Identification.")
return
tracks = []
skipped = 0
for tid in track_ids:
track = self._manager.library.tracks.get(tid)
if track is None:
continue
if not track.location:
skipped += 1
continue
tracks.append(track)
if skipped:
self.statusBar().showMessage(
f"Skipped {skipped} track(s) with no file to fingerprint", 6000)
if not tracks:
return
self._identify_queue = tracks
self._identify_total = len(tracks)
self._identify_next(api_key)
def _identify_next(self, api_key: str):
if not self._identify_queue:
return
track = self._identify_queue.pop(0)
done = self._identify_total - len(self._identify_queue)
counter = (f" ({done} of {self._identify_total})"
if self._identify_total > 1 else "")
self.statusBar().showMessage(
f"Identifying “{track.name}”{counter}…")
# Kept as an attribute so the identifier (and its thread's signal
# source) outlives this method.
self._identifier = TrackIdentifier()
self._identifier.finished.connect(
lambda result, t=track, k=api_key: self._on_identified(t, k, result))
self._identifier.identify(track.track_id, track.location, api_key)
def _on_identified(self, track, api_key: str, result: dict):
if "error" in result:
self.statusBar().showMessage(
f"Couldn't identify “{track.name}”: {result['error']}", 6000)
elif not result["candidates"]:
self.statusBar().showMessage(
f"No match found for “{track.name}”", 6000)
else:
self.statusBar().clearMessage()
dialog = IdentifyDialog(track, result["candidates"],
remaining=len(self._identify_queue),
parent=self)
accepted = dialog.exec()
if accepted:
fields = dialog.result_fields()
if fields:
# The edit funnel writes the tags, may relocate the file
# and records one undo step — see LibraryManager.
self._manager.edit_track_fields(track.track_id, fields)
self.statusBar().showMessage(
f"Updated tags for “{track.name}”", 5000)
elif dialog.cancel_all:
self._identify_queue.clear()
self.statusBar().clearMessage()
return
self._identify_next(api_key)
# ---- relocating a moved/renamed file ----
def _existing_ancestor(self, path: str) -> str: