v0.73.0: Connections › Import Shazams… — the Rabbit's new Shazams, found on YouTube as the original song, tagged as they land

Reads Shazam's history over root adb (and unroots after), offers only
Shazams not dealt with yet (a synced list), picks the plain studio take
(no live/cover/karaoke/clean/vinyl/sped-up, Apple's length decides), and
shows every song's stage with the Identify panel for each one as soon as
it's imported, in the same window.
This commit is contained in:
2026-10-20 00:00:20 -07:00
parent fb5f134045
commit a52542750c
9 changed files with 1948 additions and 27 deletions
+181 -1
View File
@@ -10,7 +10,8 @@ from PyQt6.QtWidgets import (
from PyQt6.QtCore import QRect, Qt, QEvent, QObject, QTimer, pyqtSignal
from PyQt6.QtGui import QAction, QKeySequence
from lintunes import bpm_detect, device_sync, loudness, music_folder, theme, url_import
from lintunes import (bpm_detect, device_sync, loudness, music_folder, shazam,
theme, url_import)
from lintunes.andtunes import layout as andtunes_layout
from lintunes.andtunes import install as andtunes_install
from lintunes.andtunes import sync as andtunes_sync
@@ -45,6 +46,7 @@ from lintunes.gui.playlist_view import PlaylistView
from lintunes.gui.transport import TransportBar
from lintunes.gui.url_import_dialog import UrlImportDialog
from lintunes.gui.url_import_progress import UrlImportProgress
from lintunes.gui.shazam_import import ShazamImportWindow, ShazamPreviewDialog
from lintunes.gui import web_upload_progress as web_progress
from lintunes.gui.info_dialog import InfoDialog
from lintunes.gui.music_folder_dialog import MusicFolderDialog
@@ -282,6 +284,12 @@ class MainWindow(QMainWindow):
# Several songs are looked up quietly while they download, and
# reviewed together once the last one has landed.
self._url_batch = None # identify_batch.IdentifyCollector
# Import Shazams runs as a URL import (it owns _url_worker and
# _url_progress), with its own window and its own lookup queue, so
# Identify proposals appear in that window as songs land.
self._shazam_window = None
self._shazam_identify: list = [] # (request id, track) to look up
self._shazam_identifier = None # the TrackIdentifier running
# Popups waiting for LinTunes to be the app in front (they must
# never land on top of another app).
self._popups_waiting: list = []
@@ -531,6 +539,8 @@ class MainWindow(QMainWindow):
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)
# "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.
@@ -612,6 +622,7 @@ class MainWindow(QMainWindow):
andtunes_install.bundled_apk() is not None
and not (self._install_worker is not None
and self._install_worker.busy()))
self._shazam_action.setEnabled(self._busy_worker() is None)
# The self-updater ships code but not dependencies, so a machine that
# has pulled this round hasn't necessarily installed pychromecast (or
@@ -1696,6 +1707,7 @@ class MainWindow(QMainWindow):
self._url_progress.close()
self._url_progress.deleteLater()
self._url_progress = None
self._shazam_window = None
if len(chosen) > 1:
self._url_progress = UrlImportProgress(chosen, self)
self._url_progress.stop_requested.connect(
@@ -1898,6 +1910,174 @@ class MainWindow(QMainWindow):
self, "Import from URL",
f"Couldn't import from that link:\n\n{message}"))
# ---- Import Shazams (Connections menu) ----
def _import_shazams(self):
if self._busy_worker() is not None:
self.statusBar().showMessage(
"Wait for the current transfer to finish first", 6000)
return
missing = [name for name, ok in (
("adb", andtunes_install.adb_path() is not None),
("yt-dlp", url_import.ytdlp_available()),
("ffmpeg", exporter.web_support.ffmpeg_available())) if not ok]
if missing:
QMessageBox.warning(
self, "Import Shazams",
f"Importing Shazams needs {', '.join(missing)}, which "
f"{'is' if len(missing) == 1 else 'are'} not installed.\n\n"
"adb: Fedora's “android-tools” package\n"
"yt-dlp: pip install --user yt-dlp (or your distro's "
"package)\nffmpeg: your distro's “ffmpeg” package")
return
target = self._url_import_target()
handled = shazam.handled_ids(self._prefs) | shazam.legacy_handled()
dialog = ShazamPreviewDialog(
shazam.ShazamReader(), handled,
self._manager.library.tracks.values(),
target.description if target else None, self)
if not dialog.exec() or self._ensure_music_dir() is None:
return
# Unticked and already-owned songs are dealt with now; the others
# only once they're imported, so a failure is offered again.
shazam.mark_handled(self._prefs, dialog.passed_over())
chosen = dialog.chosen()
if not chosen:
return
self._url_target = target if dialog.add_to_playlist() else None
self._url_inserted = 0
self._url_imported = 0
self._url_identify = True
self._url_note = ""
if self._url_batch is not None:
self._url_batch.cancel()
self._url_batch = None
self._shazam_identify = []
worker = shazam.ShazamImportWorker(
chosen, self,
cookies_browser=load_config().get(url_import.COOKIES_KEY))
if self._url_progress is not None:
self._url_progress.close()
self._url_progress.deleteLater()
window = ShazamImportWindow(chosen, self)
window.stop_requested.connect(self._confirm_cancel_url_import)
window.apply_tags.connect(self._apply_shazam_tags)
self._url_progress = self._shazam_window = window
worker.stage.connect(window.set_stage)
worker.item_failed.connect(window.failed)
worker.cookies_used.connect(self._remember_cookies_browser)
worker.item_started.connect(self._on_shazam_started)
worker.progress.connect(self._sync_progress.setValue)
worker.landed.connect(self._on_shazam_landed)
worker.finished.connect(self._on_shazam_finished)
worker.failed.connect(self._on_shazam_failed)
self._url_worker = worker
self._sync_label.setText("Importing Shazams…")
self._sync_progress.setRange(0, 100)
self._sync_progress.setValue(0)
self._sync_cancel.show()
self._sync_label.show()
self._sync_progress.show()
window.show()
worker.start()
def _on_shazam_started(self, index: int, count: int, _rid: str,
title: str):
short = title if len(title) <= 40 else title[:39] + "…"
self._sync_label.setText(f"Shazam {index} of {count} · {short}")
self._sync_progress.setValue(0)
def _on_shazam_landed(self, rid: str, path: str):
"""One song is downloaded and wearing Shazam's tags: import it, then
look it up for the window's tagging panel."""
window = self._shazam_window
if window is not None:
window.importing(rid)
target = self._url_target
pid, position = "", None
if target is not None and target.pid in self._manager.library.playlists:
pid = target.pid
if target.position is not None:
position = target.position + self._url_inserted
imported = self.import_files([Path(path)], pid, position)
if pid:
self._url_inserted += len(imported)
self._url_imported += len(imported)
if imported:
shazam.mark_handled(self._prefs, [rid])
if window is not None:
window.imported(rid, imported[0] if imported else None)
if imported:
self._shazam_identify.append((rid, imported[0]))
if self._shazam_identifier is None:
self._shazam_identify_next()
def _shazam_identify_next(self):
"""One lookup at a time (AcoustID allows three a second)."""
self._shazam_identifier = None
while self._shazam_identify:
rid, track = self._shazam_identify.pop(0)
if track.track_id in self._manager.library.tracks:
break
else:
return
window = self._shazam_window
identifier = TrackIdentifier()
identifier.finished.connect(
lambda result, r=rid, w=window:
self._on_shazam_identified(w, r, result))
self._shazam_identifier = identifier
identifier.identify(track,
self._prefs.acoustid.get("api_key", "").strip())
def _on_shazam_identified(self, window, rid: str, result: dict):
# The file already carries Shazam's own title and artist, which beat
# anything read off a YouTube upload's name: only real matches.
candidates = [c for c in result.get("candidates", [])
if c.source != "filename"]
if window is not None and window is self._shazam_window:
window.identified(rid, candidates)
self._shazam_identify_next()
def _apply_shazam_tags(self, track_id: int, fields: dict):
if track_id in self._manager.library.tracks:
# The edit funnel writes the tags, may relocate the file and
# records one undo step.
self._manager.edit_track_fields(track_id, fields)
def _on_shazam_finished(self, summary: dict):
self._finish_url_import()
window = self._shazam_window
if window is not None:
window.finish(summary["cancelled"])
if window.waiting_to_tag() and not window.isVisible():
# Hidden mid-run, and the status-bar line that brought it
# back is gone: songs still waiting to be tagged reopen it.
self._when_app_active(window.show)
count = self._url_imported
if summary["cancelled"]:
msg = f"Shazam import stopped — {count} song(s) imported"
else:
msg = f"Imported {count} Shazam(s)"
sounds.play_done(self._prefs)
target = self._url_target
playlist = (self._manager.library.playlists.get(target.pid)
if target is not None else None)
if playlist is not None and count:
msg += f" into “{playlist.name}”"
if summary["errors"]:
msg += f" · {len(summary['errors'])} couldn't be found"
self.statusBar().showMessage(msg, 12000)
def _on_shazam_failed(self, message: str):
self._finish_url_import()
if self._shazam_window is not None:
self._shazam_window.finish(False)
self._when_app_active(lambda: QMessageBox.warning(
self, "Import Shazams",
f"Couldn't import the Shazams:\n\n{message}"))
def _confirm_cancel_url_import(self):
box = QMessageBox(self)
box.setWindowTitle("Stop downloading")