v0.87.0: Connections › Full Rabbit Sync — the music sync, then Import Shazams into the current playlist; Sync to Rabbit is now Sync Music to Rabbit

This commit is contained in:
2026-11-06 01:30:39 -08:00
parent 61955ef996
commit 39bbfaa5c0
5 changed files with 178 additions and 10 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.86.0"
__version__ = "0.87.0"
+63 -8
View File
@@ -109,6 +109,10 @@ class _ResetRelay(QObject):
done = pyqtSignal(object)
# Import Shazams' default target: whatever playlist is current.
_CURRENT_TARGET = object()
class MainWindow(QMainWindow):
def __init__(self, manager, prefs, lastfm=None, parent=None):
super().__init__(parent)
@@ -254,6 +258,10 @@ class MainWindow(QMainWindow):
self.statusBar().addPermanentWidget(self._sync_cancel)
self._andtunes_worker = None
self._andtunes_planner = None
# Full Rabbit Sync: the playlist target Import Shazams will use once
# the music sync is over (latched at the click), or None.
self._full_sync_target = None
self._full_sync_pending = False
self._install_worker = None
self._sync_device_name = ""
# Export shares the status-bar progress widgets with device sync —
@@ -561,15 +569,21 @@ class MainWindow(QMainWindow):
# Mnemonic on the "n": Alt+C already belongs to &Controls.
connections_menu = bar.addMenu("Co&nnections")
self._andtunes_action = self._add_action(
connections_menu, "Sync to Rabbit", "", self._sync_to_andtunes)
connections_menu, "Sync Music to Rabbit", "",
self._sync_to_andtunes)
self._andtunes_action.setEnabled(False)
# The music sync, then Import Shazams as soon as it's over.
self._full_sync_action = self._add_action(
connections_menu, "Full Rabbit Sync", "", self._full_rabbit_sync)
self._full_sync_action.setEnabled(False)
self._add_action(connections_menu, "Rabbit Sync Settings…", "",
self._show_device_sync_settings)
self._install_action = self._add_action(
connections_menu, "Install andTunes on Rabbit…", "",
self._install_andtunes)
self._shazam_action = self._add_action(
connections_menu, "Import Shazams…", "", self._import_shazams)
connections_menu, "Import Shazams…", "",
lambda: self._import_shazams())
# "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.
@@ -805,6 +819,8 @@ class MainWindow(QMainWindow):
worker.cancel()
def _on_sync_cancelled(self, summary):
self._full_sync_pending = False # a cancel stops a Full Sync too
self._full_sync_target = None
self._sync_inhibitor.release()
self._hide_sync_widgets()
self.statusBar().showMessage(
@@ -816,19 +832,21 @@ class MainWindow(QMainWindow):
self._manager.reload_from_disk()
def _refresh_device_actions(self):
"""Sync to Rabbit from the watcher's cached answer — never a fresh
"""Sync Music / Full Rabbit Sync from the watcher's cached answer — never a fresh
look at the mount, which is what froze the menu."""
busy = self._busy_worker() is not None
if self._devices.state == device_sync.STUCK:
# Enabled: the click explains and offers the reset.
self._andtunes_action.setText("Rabbit isn't responding…")
self._andtunes_action.setEnabled(True)
self._full_sync_action.setEnabled(False)
return
self._andtunes_action.setText("Sync to Rabbit")
self._andtunes_action.setText("Sync Music to Rabbit")
# 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 self._devices.device is not None)
ready = not busy and self._devices.device is not None
self._andtunes_action.setEnabled(ready)
self._full_sync_action.setEnabled(ready)
def _rabbit_stuck(self):
"""The mount stopped answering: say so, and offer the CLAUDE.md
@@ -870,6 +888,8 @@ class MainWindow(QMainWindow):
self._sync_inhibitor.release()
self._hide_sync_widgets()
QMessageBox.warning(self, "Sync failed", message)
# Shazams come over adb, not the MTP mount that just failed.
self._then_shazams()
# ---- connections: andTunes (whole-library sync) ----
@@ -889,16 +909,45 @@ class MainWindow(QMainWindow):
# Everything may have changed since the menu opened — re-verify.
if self._busy_worker() is not None:
return
self._full_sync_pending = False
self._devices.when_ready(self._sync_to_device)
def _full_rabbit_sync(self):
"""Sync Music to Rabbit, then Import Shazams into the playlist that
was current at the click (the user may browse away meanwhile)."""
if self._busy_worker() is not None:
return
self._full_sync_pending = True
self._full_sync_target = self._url_import_target()
self._devices.when_ready(self._sync_to_device)
def _then_shazams(self):
"""The music half of a Full Rabbit Sync is over (done, failed or
never started): on to the Shazams. A cancel ends the whole thing."""
if not self._full_sync_pending:
return
if self._busy_worker() is not None:
# The worker's thread clears its busy flag just after its last
# signal, which may reach us first.
QTimer.singleShot(50, self._then_shazams)
return
self._full_sync_pending = False
target, self._full_sync_target = self._full_sync_target, None
self._when_app_active(lambda: self._import_shazams(target=target))
def _sync_to_device(self, device, state):
if state == device_sync.STUCK:
self._full_sync_pending = False
self._rabbit_stuck()
return
if device is None or self._busy_worker() is not None:
self._full_sync_pending = False
return
playlists = self._selected_sync_playlists()
if not playlists:
if self._full_sync_pending:
self._then_shazams() # no music to send; Shazams still
return
QMessageBox.information(
self, "Nothing to sync",
"No playlists are set to sync yet.\n\n"
@@ -938,6 +987,7 @@ class MainWindow(QMainWindow):
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:
self._then_shazams()
return
plan.drop_conversions("it needs ffmpeg to convert")
needed = plan.bytes_to_copy + device_sync.SPACE_MARGIN
@@ -948,6 +998,7 @@ class MainWindow(QMainWindow):
f"{device_sync.format_bytes(needed - plan.bytes_freed)}, but "
f"the {device.name} only has "
f"{device_sync.format_bytes(free)} free.")
self._then_shazams()
return
self._andtunes_worker = andtunes_sync.AndTunesSyncWorker(plan, self)
@@ -1011,6 +1062,7 @@ class MainWindow(QMainWindow):
"They've been left out of the library on the device, so the "
"app won't list a song it can't play. Unplugging the "
"device and plugging it back in usually clears this.")
self._then_shazams()
# ---- connections: install the andTunes app ----
@@ -2148,7 +2200,9 @@ class MainWindow(QMainWindow):
# ---- Import Shazams (Connections menu) ----
def _import_shazams(self):
def _import_shazams(self, target=_CURRENT_TARGET):
"""``target`` is the playlist to add to (a Full Rabbit Sync latches
it at its click); left out, it's the current one."""
if self._busy_worker() is not None:
self.statusBar().showMessage(
"Wait for the current transfer to finish first", 6000)
@@ -2166,7 +2220,8 @@ class MainWindow(QMainWindow):
"yt-dlp: pip install --user yt-dlp (or your distro's "
"package)\nffmpeg: your distro's “ffmpeg” package")
return
target = self._url_import_target()
if target is _CURRENT_TARGET:
target = self._url_import_target()
handled = shazam.handled_ids(self._prefs) | shazam.legacy_handled()
dialog = ShazamPreviewDialog(
shazam.ShazamReader(), handled,