v0.20.0: the Rabbit's plays come home

andTunes phase 3. The R1 is now one more machine in the Round 38 play-count
model, and nothing lands on it that Android can't play.

Play counts: andTunes 0.2.0 counts a play on a natural finish (LinTunes'
rule) and keeps Music/andTunes/plays/andtunes-<install id>.json in exactly
the per-machine-totals journal shape, written beside the old one and renamed
over it. Each sync first folds it into <data_dir>/plays/ with a new
play_journal.merge_totals, the per-track max: the file now has two homes and
both desktops may bring it back, so the max converges and an older copy can
never pull a count down. Nothing is written when nothing moved, and
PlayJournal.load needed no change.

Format gate: the planner reuses export/web_support.conversion_for outright,
since Android's MediaPlayer decodes the browser's set. FairPlay is refused
and reported; ALAC, AIFF and oddities land as FLAC, converted once into a
per-track cache and size-diffed after that. With no ffmpeg, the export's
"sync without them?" question. A file ffmpeg can't read costs that song,
not the sync.

"Sync Playlist to Rabbit (Auxio)" is retired from the menu; device_sync's
helpers stay because export and andTunes import them.

The dev fixture grew a real ALAC track, a Protected AAC .m4p and an "Odd
Formats" playlist. Verified on the R1 with it: AIFF and ALAC arrived as
FLAC and played, the FairPlay track was refused, four plays came back on the
next sync and each track's effective count rose by exactly one, and a third
sync copied nothing.

Found along the way: USB re-enumeration can wedge gvfsd-mtp, after which
anything touching the mount (find_device, the GUI tests) hangs in an
uninterruptible wait. CLAUDE.md now has the recovery.

Claude-Session: https://claude.ai/code/session_018ZCVBTJRFJ2XfMshu2gtUv
This commit is contained in:
2026-09-11 15:20:44 -05:00
parent 077479967a
commit 1280c89015
17 changed files with 864 additions and 127 deletions
+35 -84
View File
@@ -161,7 +161,6 @@ class MainWindow(QMainWindow):
self._sync_progress.setTextVisible(False)
self._sync_progress.hide()
self.statusBar().addPermanentWidget(self._sync_progress)
self._sync_worker = None
self._andtunes_worker = None
self._install_worker = None
self._sync_device_name = ""
@@ -362,15 +361,9 @@ class MainWindow(QMainWindow):
self._install_action = self._add_action(
connections_menu, "Install andTunes on Rabbit…", "",
self._install_andtunes)
connections_menu.addSeparator()
# The per-playlist sync stays until andTunes can actually play a
# song: it is what feeds Auxio, and pulling it in the same round that
# adds the new tree would leave the device full of files and nothing
# able to open them.
self._sync_action = self._add_action(
connections_menu, "Sync Playlist to Rabbit (Auxio)", "",
self._sync_playlist_to_device)
self._sync_action.setEnabled(False)
# "Sync Playlist to Rabbit (Auxio)" was retired in Round 51, once
# andTunes could play what it syncs. device_sync's helpers stay: the
# export and andTunes code import them.
connections_menu.addSeparator()
self._cast_action = self._add_action(
connections_menu, "Connect to Chromecast…", "", self._toggle_cast)
@@ -403,11 +396,7 @@ class MainWindow(QMainWindow):
# An export in flight owns the same status-bar widgets, so it blocks
# a sync just as another sync would.
busy = self._busy_worker() is not None
on_playlist = (self._content.currentWidget() is self._playlist_view
and bool(self._playlist_view.playlist_id))
device = device_sync.find_device()
self._sync_action.setEnabled(
not busy and on_playlist and device is not None)
# Whole-library sync doesn't care which view is open — only that a
# device is plugged in and at least one playlist is ticked.
self._andtunes_action.setEnabled(not busy and device is not None)
@@ -464,49 +453,6 @@ class MainWindow(QMainWindow):
self.statusBar().showMessage(
f"Skipped “{track.name}” — {reason}", 6000)
def _sync_playlist_to_device(self):
# Everything may have changed since the menu opened — re-verify.
if self._sync_worker is not None and self._sync_worker.busy():
return
device = device_sync.find_device()
playlist = self._manager.library.playlists.get(
self._playlist_view.playlist_id)
if device is None or playlist is None:
return
tracks = [self._manager.library.tracks[tid]
for tid in playlist.track_ids
if tid in self._manager.library.tracks]
try:
plan = device_sync.plan_sync(
playlist.name, tracks, device.music_dir, device)
free = shutil.disk_usage(device.root).free
except OSError as e:
QMessageBox.warning(self, "Sync failed",
f"Couldn't read the {device.name}: {e}")
return
needed = plan.bytes_to_copy + device_sync.SPACE_MARGIN
if free + plan.bytes_freed < needed:
QMessageBox.warning(
self, "Not enough space",
f"Syncing “{playlist.name}” needs "
f"{device_sync.format_bytes(needed - plan.bytes_freed)}, but the "
f"{device.name} only has {device_sync.format_bytes(free)} free.")
return
self._sync_worker = device_sync.DeviceSyncWorker(plan, self)
self._sync_worker.progress.connect(self._on_sync_progress)
self._sync_worker.finished.connect(self._on_sync_finished)
self._sync_worker.cancelled.connect(self._on_sync_cancelled)
self._sync_worker.failed.connect(self._on_sync_failed)
self._sync_device_name = device.name
self._sync_label.setText(f"Copying to {device.name}")
self._sync_progress.setRange(0, max(plan.bytes_to_copy // 1024, 1))
self._sync_progress.setValue(0)
self._sync_cancel.show()
self._sync_label.show()
self._sync_progress.show()
self._sync_inhibitor.inhibit()
self._sync_worker.start()
def _hide_sync_widgets(self):
self._sync_cancel.hide()
self._sync_label.hide()
@@ -514,8 +460,8 @@ class MainWindow(QMainWindow):
def _busy_worker(self):
"""The transfer currently owning the status-bar progress widgets."""
for worker in (self._sync_worker, self._andtunes_worker,
self._export_worker, self._url_worker):
for worker in (self._andtunes_worker, self._export_worker,
self._url_worker):
if worker is not None and worker.busy():
return worker
return None
@@ -527,9 +473,7 @@ class MainWindow(QMainWindow):
if self._export_worker is not None and self._export_worker.busy():
self._confirm_cancel_export()
return
worker = self._sync_worker
if self._andtunes_worker is not None and self._andtunes_worker.busy():
worker = self._andtunes_worker
worker = self._andtunes_worker
if worker is None or not worker.busy():
return
box = QMessageBox(self)
@@ -553,27 +497,10 @@ class MainWindow(QMainWindow):
self.statusBar().showMessage(
f"Sync cancelled — {summary['copied']} of {summary['total']} "
"tracks copied; sync again to finish.", 8000)
def _on_sync_progress(self, done_kib, total_kib, label):
self._sync_progress.setRange(0, total_kib)
self._sync_progress.setValue(done_kib)
self._sync_label.setText(
f"Copying to {self._sync_device_name} · "
f"{device_sync.format_bytes(done_kib * 1024)} / "
f"{device_sync.format_bytes(total_kib * 1024)}")
def _on_sync_finished(self, summary):
self._sync_inhibitor.release()
self._hide_sync_widgets()
msg = (f"Synced “{summary['playlist']}” to the {summary['device']}: "
f"{summary['copied']} copied, {summary['kept']} up to date, "
f"{summary['removed']} removed")
if summary["skipped"]:
msg += f", {summary['skipped']} skipped (no local file)"
if summary.get("vanished"):
msg += (f", {summary['vanished']} changed under us "
"(re-sync to pick them up)")
self.statusBar().showMessage(msg, 8000)
if summary.get("plays"):
# Counts are brought back before anything is copied, so even a
# cancelled sync has news for the journals.
self._manager.reload_from_disk()
def _on_sync_failed(self, message):
self._sync_inhibitor.release()
@@ -620,12 +547,27 @@ class MainWindow(QMainWindow):
try:
plan = andtunes_sync.plan_andtunes_sync(
playlists, self._manager.library.tracks, root, device,
copy_art=bool(self._prefs.device_sync.get("copy_art", True)))
copy_art=bool(self._prefs.device_sync.get("copy_art", True)),
data_dir=self._manager.data_dir)
free = shutil.disk_usage(device.root).free
except OSError as e:
QMessageBox.warning(self, "Sync failed",
f"Couldn't read the {device.name}: {e}")
return
if plan.needs_ffmpeg and not exporter.web_support.ffmpeg_available():
conversions = plan.conversions
names = "\n".join(f" • {device_sync.track_display(i.track)}"
for i in conversions[:8])
more = (f"\n … and {len(conversions) - 8} more"
if len(conversions) > 8 else "")
answer = QMessageBox.question(
self, "FFmpeg not found",
f"{len(conversions)} song(s) need converting to FLAC before "
f"the {device.name} can play them, but the ffmpeg command "
f"isn't installed:\n\n{names}{more}\n\nSync without them?")
if answer != QMessageBox.StandardButton.Yes:
return
plan.drop_conversions("it needs ffmpeg to convert")
needed = plan.bytes_to_copy + device_sync.SPACE_MARGIN
if free + plan.bytes_freed < needed:
QMessageBox.warning(
@@ -667,6 +609,15 @@ class MainWindow(QMainWindow):
f"{summary['albums']} covers, {summary['removed']} removed")
if summary["skipped"]:
msg += f", {summary['skipped']} skipped (no local file)"
if summary.get("refused"):
msg += f", {summary['refused']} left out (can't play there)"
if summary.get("unconverted"):
msg += f", {summary['unconverted']} couldn't be converted"
if summary.get("plays"):
msg += f"; play counts back for {summary['plays']} song(s)"
# The journal landed in the data dir; fold it in now rather than
# waiting for the file watcher.
self._manager.reload_from_disk()
self.statusBar().showMessage(msg, 10000)
# ---- connections: install the andTunes app ----