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:
@@ -869,6 +869,12 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
|
|||||||
*and* an embedded `identify_dialog.IdentifyPanel` per song as soon as it's
|
*and* an embedded `identify_dialog.IdentifyPanel` per song as soon as it's
|
||||||
imported (its own one-at-a-time `TrackIdentifier` queue; filename
|
imported (its own one-at-a-time `TrackIdentifier` queue; filename
|
||||||
candidates are dropped, since the file already wears Shazam's tags).
|
candidates are dropped, since the file already wears Shazam's tags).
|
||||||
|
**Full Rabbit Sync** (Round 120, beside Sync Music to Rabbit) is the
|
||||||
|
music sync, then Import Shazams into the playlist current *at the
|
||||||
|
click* (`_full_sync_target`). `_then_shazams` runs at every end of the
|
||||||
|
music half — done, failed, nothing ticked, declined — except a cancel,
|
||||||
|
and retries until the sync worker's busy flag clears (it drops just
|
||||||
|
after the worker's last signal).
|
||||||
|
|
||||||
- **`lintunes/mpris.py`** — registers `org.mpris.MediaPlayer2.lintunes` over D-Bus
|
- **`lintunes/mpris.py`** — registers `org.mpris.MediaPlayer2.lintunes` over D-Bus
|
||||||
so the desktop's media keys / now-playing popup control playback. Spacebar and
|
so the desktop's media keys / now-playing popup control playback. Spacebar and
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||||
|
|
||||||
__version__ = "0.86.0"
|
__version__ = "0.87.0"
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ class _ResetRelay(QObject):
|
|||||||
done = pyqtSignal(object)
|
done = pyqtSignal(object)
|
||||||
|
|
||||||
|
|
||||||
|
# Import Shazams' default target: whatever playlist is current.
|
||||||
|
_CURRENT_TARGET = object()
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
def __init__(self, manager, prefs, lastfm=None, parent=None):
|
def __init__(self, manager, prefs, lastfm=None, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@@ -254,6 +258,10 @@ class MainWindow(QMainWindow):
|
|||||||
self.statusBar().addPermanentWidget(self._sync_cancel)
|
self.statusBar().addPermanentWidget(self._sync_cancel)
|
||||||
self._andtunes_worker = None
|
self._andtunes_worker = None
|
||||||
self._andtunes_planner = 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._install_worker = None
|
||||||
self._sync_device_name = ""
|
self._sync_device_name = ""
|
||||||
# Export shares the status-bar progress widgets with device sync —
|
# 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.
|
# Mnemonic on the "n": Alt+C already belongs to &Controls.
|
||||||
connections_menu = bar.addMenu("Co&nnections")
|
connections_menu = bar.addMenu("Co&nnections")
|
||||||
self._andtunes_action = self._add_action(
|
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)
|
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._add_action(connections_menu, "Rabbit Sync Settings…", "",
|
||||||
self._show_device_sync_settings)
|
self._show_device_sync_settings)
|
||||||
self._install_action = self._add_action(
|
self._install_action = self._add_action(
|
||||||
connections_menu, "Install andTunes on Rabbit…", "",
|
connections_menu, "Install andTunes on Rabbit…", "",
|
||||||
self._install_andtunes)
|
self._install_andtunes)
|
||||||
self._shazam_action = self._add_action(
|
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
|
# "Sync Playlist to Rabbit (Auxio)" was retired in Round 51, once
|
||||||
# andTunes could play what it syncs. device_sync's helpers stay: the
|
# andTunes could play what it syncs. device_sync's helpers stay: the
|
||||||
# export and andTunes code import them.
|
# export and andTunes code import them.
|
||||||
@@ -805,6 +819,8 @@ class MainWindow(QMainWindow):
|
|||||||
worker.cancel()
|
worker.cancel()
|
||||||
|
|
||||||
def _on_sync_cancelled(self, summary):
|
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._sync_inhibitor.release()
|
||||||
self._hide_sync_widgets()
|
self._hide_sync_widgets()
|
||||||
self.statusBar().showMessage(
|
self.statusBar().showMessage(
|
||||||
@@ -816,19 +832,21 @@ class MainWindow(QMainWindow):
|
|||||||
self._manager.reload_from_disk()
|
self._manager.reload_from_disk()
|
||||||
|
|
||||||
def _refresh_device_actions(self):
|
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."""
|
look at the mount, which is what froze the menu."""
|
||||||
busy = self._busy_worker() is not None
|
busy = self._busy_worker() is not None
|
||||||
if self._devices.state == device_sync.STUCK:
|
if self._devices.state == device_sync.STUCK:
|
||||||
# Enabled: the click explains and offers the reset.
|
# Enabled: the click explains and offers the reset.
|
||||||
self._andtunes_action.setText("Rabbit isn't responding…")
|
self._andtunes_action.setText("Rabbit isn't responding…")
|
||||||
self._andtunes_action.setEnabled(True)
|
self._andtunes_action.setEnabled(True)
|
||||||
|
self._full_sync_action.setEnabled(False)
|
||||||
return
|
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
|
# Whole-library sync doesn't care which view is open — only that a
|
||||||
# device is plugged in and at least one playlist is ticked.
|
# device is plugged in and at least one playlist is ticked.
|
||||||
self._andtunes_action.setEnabled(
|
ready = not busy and self._devices.device is not None
|
||||||
not busy and self._devices.device is not None)
|
self._andtunes_action.setEnabled(ready)
|
||||||
|
self._full_sync_action.setEnabled(ready)
|
||||||
|
|
||||||
def _rabbit_stuck(self):
|
def _rabbit_stuck(self):
|
||||||
"""The mount stopped answering: say so, and offer the CLAUDE.md
|
"""The mount stopped answering: say so, and offer the CLAUDE.md
|
||||||
@@ -870,6 +888,8 @@ class MainWindow(QMainWindow):
|
|||||||
self._sync_inhibitor.release()
|
self._sync_inhibitor.release()
|
||||||
self._hide_sync_widgets()
|
self._hide_sync_widgets()
|
||||||
QMessageBox.warning(self, "Sync failed", message)
|
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) ----
|
# ---- connections: andTunes (whole-library sync) ----
|
||||||
|
|
||||||
@@ -889,16 +909,45 @@ class MainWindow(QMainWindow):
|
|||||||
# Everything may have changed since the menu opened — re-verify.
|
# Everything may have changed since the menu opened — re-verify.
|
||||||
if self._busy_worker() is not None:
|
if self._busy_worker() is not None:
|
||||||
return
|
return
|
||||||
|
self._full_sync_pending = False
|
||||||
self._devices.when_ready(self._sync_to_device)
|
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):
|
def _sync_to_device(self, device, state):
|
||||||
if state == device_sync.STUCK:
|
if state == device_sync.STUCK:
|
||||||
|
self._full_sync_pending = False
|
||||||
self._rabbit_stuck()
|
self._rabbit_stuck()
|
||||||
return
|
return
|
||||||
if device is None or self._busy_worker() is not None:
|
if device is None or self._busy_worker() is not None:
|
||||||
|
self._full_sync_pending = False
|
||||||
return
|
return
|
||||||
playlists = self._selected_sync_playlists()
|
playlists = self._selected_sync_playlists()
|
||||||
if not playlists:
|
if not playlists:
|
||||||
|
if self._full_sync_pending:
|
||||||
|
self._then_shazams() # no music to send; Shazams still
|
||||||
|
return
|
||||||
QMessageBox.information(
|
QMessageBox.information(
|
||||||
self, "Nothing to sync",
|
self, "Nothing to sync",
|
||||||
"No playlists are set to sync yet.\n\n"
|
"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"the {device.name} can play them, but the ffmpeg command "
|
||||||
f"isn't installed:\n\n{names}{more}\n\nSync without them?")
|
f"isn't installed:\n\n{names}{more}\n\nSync without them?")
|
||||||
if answer != QMessageBox.StandardButton.Yes:
|
if answer != QMessageBox.StandardButton.Yes:
|
||||||
|
self._then_shazams()
|
||||||
return
|
return
|
||||||
plan.drop_conversions("it needs ffmpeg to convert")
|
plan.drop_conversions("it needs ffmpeg to convert")
|
||||||
needed = plan.bytes_to_copy + device_sync.SPACE_MARGIN
|
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"{device_sync.format_bytes(needed - plan.bytes_freed)}, but "
|
||||||
f"the {device.name} only has "
|
f"the {device.name} only has "
|
||||||
f"{device_sync.format_bytes(free)} free.")
|
f"{device_sync.format_bytes(free)} free.")
|
||||||
|
self._then_shazams()
|
||||||
return
|
return
|
||||||
|
|
||||||
self._andtunes_worker = andtunes_sync.AndTunesSyncWorker(plan, self)
|
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 "
|
"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 "
|
"app won't list a song it can't play. Unplugging the "
|
||||||
"device and plugging it back in usually clears this.")
|
"device and plugging it back in usually clears this.")
|
||||||
|
self._then_shazams()
|
||||||
|
|
||||||
# ---- connections: install the andTunes app ----
|
# ---- connections: install the andTunes app ----
|
||||||
|
|
||||||
@@ -2148,7 +2200,9 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
# ---- Import Shazams (Connections menu) ----
|
# ---- 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:
|
if self._busy_worker() is not None:
|
||||||
self.statusBar().showMessage(
|
self.statusBar().showMessage(
|
||||||
"Wait for the current transfer to finish first", 6000)
|
"Wait for the current transfer to finish first", 6000)
|
||||||
@@ -2166,6 +2220,7 @@ class MainWindow(QMainWindow):
|
|||||||
"yt-dlp: pip install --user yt-dlp (or your distro's "
|
"yt-dlp: pip install --user yt-dlp (or your distro's "
|
||||||
"package)\nffmpeg: your distro's “ffmpeg” package")
|
"package)\nffmpeg: your distro's “ffmpeg” package")
|
||||||
return
|
return
|
||||||
|
if target is _CURRENT_TARGET:
|
||||||
target = self._url_import_target()
|
target = self._url_import_target()
|
||||||
handled = shazam.handled_ids(self._prefs) | shazam.legacy_handled()
|
handled = shazam.handled_ids(self._prefs) | shazam.legacy_handled()
|
||||||
dialog = ShazamPreviewDialog(
|
dialog = ShazamPreviewDialog(
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
"""Round 120: Connections ▸ Full Rabbit Sync.
|
||||||
|
|
||||||
|
- "Sync to Rabbit" is now "Sync Music to Rabbit", and does what it did.
|
||||||
|
- "Full Rabbit Sync" runs that music sync and then Import Shazams, adding
|
||||||
|
them to the playlist that was current when it was clicked.
|
||||||
|
- A cancelled music sync stops it; a failed one or nothing to sync still
|
||||||
|
goes on to the Shazams (they come over adb, not the MTP mount).
|
||||||
|
"""
|
||||||
|
import time
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from lintunes import device_sync
|
||||||
|
from lintunes.library_manager import LibraryManager
|
||||||
|
from lintunes.models import Library
|
||||||
|
from lintunes.preferences import Preferences
|
||||||
|
|
||||||
|
|
||||||
|
def _pump(qapp, until, timeout=3.0):
|
||||||
|
deadline = time.monotonic() + timeout
|
||||||
|
while time.monotonic() < deadline:
|
||||||
|
qapp.processEvents()
|
||||||
|
if until():
|
||||||
|
return True
|
||||||
|
time.sleep(0.01)
|
||||||
|
return until()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def window(qapp, tmp_path, monkeypatch):
|
||||||
|
from lintunes.gui.main_window import MainWindow
|
||||||
|
manager = LibraryManager(Library(), tmp_path / "data")
|
||||||
|
win = MainWindow(manager, Preferences(tmp_path / "data"))
|
||||||
|
calls = []
|
||||||
|
monkeypatch.setattr(win, "_import_shazams",
|
||||||
|
lambda target=None: calls.append(target))
|
||||||
|
monkeypatch.setattr(win, "_when_app_active", lambda show: show())
|
||||||
|
win.shazam_calls = calls
|
||||||
|
yield win
|
||||||
|
win.close()
|
||||||
|
|
||||||
|
|
||||||
|
def _summary():
|
||||||
|
return {"playlists": 1, "device": "Rabbit", "tracks": 1, "copied": 1,
|
||||||
|
"kept": 0, "removed": 0, "skipped": 0, "total": 1}
|
||||||
|
|
||||||
|
|
||||||
|
def test_menu_names(window):
|
||||||
|
window._refresh_device_actions()
|
||||||
|
assert window._andtunes_action.text() == "Sync Music to Rabbit"
|
||||||
|
assert window._full_sync_action.text() == "Full Rabbit Sync"
|
||||||
|
# No Rabbit plugged in: neither can start.
|
||||||
|
assert not window._full_sync_action.isEnabled()
|
||||||
|
|
||||||
|
|
||||||
|
def test_full_sync_with_nothing_ticked_goes_straight_to_shazams(
|
||||||
|
window, monkeypatch):
|
||||||
|
target = object()
|
||||||
|
monkeypatch.setattr(window, "_url_import_target", lambda: target)
|
||||||
|
monkeypatch.setattr(window._devices, "when_ready",
|
||||||
|
lambda cb: cb(object(), device_sync.ABSENT))
|
||||||
|
window._full_rabbit_sync()
|
||||||
|
assert window.shazam_calls == [target]
|
||||||
|
|
||||||
|
|
||||||
|
def test_shazams_follow_a_finished_music_sync(window, qapp):
|
||||||
|
target = object()
|
||||||
|
window._full_sync_pending, window._full_sync_target = True, target
|
||||||
|
window._on_andtunes_finished(_summary())
|
||||||
|
assert _pump(qapp, lambda: window.shazam_calls)
|
||||||
|
assert window.shazam_calls == [target]
|
||||||
|
assert not window._full_sync_pending
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_cancelled_music_sync_stops_there(window, qapp):
|
||||||
|
window._full_sync_pending = True
|
||||||
|
window._on_sync_cancelled(_summary())
|
||||||
|
window._then_shazams()
|
||||||
|
qapp.processEvents()
|
||||||
|
assert window.shazam_calls == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_failed_music_sync_still_imports_shazams(window, qapp, monkeypatch):
|
||||||
|
from lintunes.gui import main_window as mw
|
||||||
|
monkeypatch.setattr(mw.QMessageBox, "warning", lambda *a, **k: None)
|
||||||
|
window._full_sync_pending = True
|
||||||
|
window._on_sync_failed("mount wedged")
|
||||||
|
assert window.shazam_calls == [None]
|
||||||
|
|
||||||
|
|
||||||
|
def test_plain_music_sync_never_imports_shazams(window, qapp):
|
||||||
|
window._on_andtunes_finished(_summary())
|
||||||
|
qapp.processEvents()
|
||||||
|
assert window.shazam_calls == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_waits_for_the_worker_to_let_go(window, qapp):
|
||||||
|
class _Busy:
|
||||||
|
busy_for = 3
|
||||||
|
def busy(self):
|
||||||
|
self.busy_for -= 1
|
||||||
|
return self.busy_for > 0
|
||||||
|
window._andtunes_worker = _Busy()
|
||||||
|
window._full_sync_pending = True
|
||||||
|
window._then_shazams()
|
||||||
|
assert window.shazam_calls == []
|
||||||
|
assert _pump(qapp, lambda: window.shazam_calls)
|
||||||
@@ -144,5 +144,5 @@ class TestMenu:
|
|||||||
finally:
|
finally:
|
||||||
release.set()
|
release.set()
|
||||||
assert _pump(lambda: window._devices.state == ABSENT)
|
assert _pump(lambda: window._devices.state == ABSENT)
|
||||||
assert window._andtunes_action.text() == "Sync to Rabbit"
|
assert window._andtunes_action.text() == "Sync Music to Rabbit"
|
||||||
window.close()
|
window.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user