v0.36.0: a playlist link says so before it downloads

Pasting a song from a YouTube Mix (watch?v=…&list=RD…) imported song
after song: yt-dlp takes the whole list by default, and a Mix runs to
thousands of rows and loops back on itself, so the linked song came in
again and again with nothing on screen saying why.

Now anything but a plain song link is listed first (--flat-playlist,
streamed into the dialog). One song goes straight through. Several become
a checklist: a song-in-a-list link ticks only its song and offers Just
This Song without waiting, and a playlist link ticks everything. Rows are
de-duplicated by id. The chosen songs download by their own pages, never
the list link, and more than one gets a per-song progress window (Hide
keeps downloading; the status-bar line brings it back).
This commit is contained in:
2026-10-02 17:41:55 -07:00
parent d6140f5ac4
commit 25b25f61fb
9 changed files with 1185 additions and 102 deletions
+57 -6
View File
@@ -39,6 +39,7 @@ from lintunes.gui.library_view import LibraryView
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.info_dialog import InfoDialog
from lintunes.gui.music_folder_dialog import MusicFolderDialog
from lintunes.gui.preferences_dialog import PreferencesDialog
@@ -57,6 +58,17 @@ def album_tracks(library, artist: str, album: str) -> list:
and (t.album_artist or t.artist).casefold() == artist_cf]
class _StatusLabel(QLabel):
"""The status bar's transfer line, which also answers a click."""
clicked = pyqtSignal()
def mouseReleaseEvent(self, event):
if event.button() == Qt.MouseButton.LeftButton:
self.clicked.emit()
super().mouseReleaseEvent(event)
class _CancelSyncButton(QPushButton):
"""Compact "✕" in the status bar's right corner that expands to say what
it does ("cancel transfer") while hovered, then shrinks back. Expanding
@@ -197,8 +209,10 @@ class MainWindow(QMainWindow):
# is added *last* owns the corner and never moves. The cancel button
# goes there deliberately: it is the one widget the user aims at, and
# the label beside it is as wide as the song title of the moment.
self._sync_label = QLabel()
self._sync_label = _StatusLabel()
self._sync_label.hide()
# A click brings back a hidden link-import progress window.
self._sync_label.clicked.connect(self._show_url_progress)
self.statusBar().addPermanentWidget(self._sync_label)
self._sync_progress = QProgressBar()
self._sync_progress.setFixedWidth(160)
@@ -235,6 +249,7 @@ class MainWindow(QMainWindow):
self._url_imported = 0
self._url_identify = True # False after "Stop Identifying"
self._url_note = ""
self._url_progress = None # UrlImportProgress, for several songs
# 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.
@@ -1305,11 +1320,18 @@ class MainWindow(QMainWindow):
"package)\nffmpeg: your distro's “ffmpeg” package")
return
target = self._url_import_target()
dialog = UrlImportDialog(target.description if target else None, self)
if not dialog.exec():
cookies = load_config().get(url_import.COOKIES_KEY)
dialog = UrlImportDialog(target.description if target else None, self,
cookies_browser=cookies)
accepted = dialog.exec()
if dialog.cookies_used: # the listing needed them
self._remember_cookies_browser(dialog.cookies_used)
cookies = dialog.cookies_used
if not accepted:
return
if self._ensure_music_dir() is None:
return
chosen = dialog.chosen_entries()
self._url_target = target if dialog.add_to_playlist() else None
self._url_inserted = 0
self._url_imported = 0
@@ -1318,9 +1340,22 @@ class MainWindow(QMainWindow):
self._url_note = (f"tags proposed from filenames only ({problem})"
if problem else "")
# The chosen songs by their own pages, never the list link: that
# would download the whole list again, and a Mix reshuffles.
worker = url_import.UrlImportWorker(
dialog.url(), self,
cookies_browser=load_config().get(url_import.COOKIES_KEY))
dialog.download_urls(), self,
cookies_browser=cookies)
if self._url_progress is not None:
self._url_progress.close()
self._url_progress.deleteLater()
self._url_progress = None
if len(chosen) > 1:
self._url_progress = UrlImportProgress(chosen, self)
self._url_progress.stop_requested.connect(
self._confirm_cancel_url_import)
worker.item_failed.connect(self._url_progress.failed)
worker.progress.connect(self._url_progress.progress)
self._url_progress.show()
worker.cookies_used.connect(self._remember_cookies_browser)
worker.item_started.connect(self._on_url_item_started)
worker.progress.connect(self._sync_progress.setValue)
@@ -1336,6 +1371,13 @@ class MainWindow(QMainWindow):
self._sync_progress.show()
worker.start()
def _show_url_progress(self):
if (self._url_progress is not None
and self._url_worker is not None and self._url_worker.busy()):
self._url_progress.show()
self._url_progress.raise_()
self._url_progress.activateWindow()
def _remember_cookies_browser(self, browser: str):
"""A bot-checked link got through on this browser's cookies: send
them from the start next time. config.json, not preferences — the
@@ -1345,7 +1387,10 @@ class MainWindow(QMainWindow):
config[url_import.COOKIES_KEY] = browser
save_config(config)
def _on_url_item_started(self, index: int, count: int, title: str):
def _on_url_item_started(self, index: int, count: int, item_id: str,
title: str):
if self._url_progress is not None:
self._url_progress.started(item_id)
short = title if len(title) <= 40 else title[:39] + "…"
where = f"{index} of {count} · " if count > 1 else ""
self._sync_label.setText(f"Downloading {where}{short}")
@@ -1366,6 +1411,8 @@ class MainWindow(QMainWindow):
if pid:
self._url_inserted += len(imported)
self._url_imported += len(imported)
if self._url_progress is not None:
self._url_progress.landed(bool(imported))
if imported and self._url_identify:
self._enqueue_identify(imported)
@@ -1376,6 +1423,8 @@ class MainWindow(QMainWindow):
def _on_url_finished(self, summary: dict):
self._finish_url_import()
if self._url_progress is not None:
self._url_progress.finish(summary["cancelled"])
count = self._url_imported
if summary["cancelled"]:
msg = f"Import cancelled — {count} song(s) imported"
@@ -1395,6 +1444,8 @@ class MainWindow(QMainWindow):
def _on_url_failed(self, message: str):
self._finish_url_import()
if self._url_progress is not None:
self._url_progress.finish(False)
QMessageBox.warning(self, "Import from URL",
f"Couldn't import from that link:\n\n{message}")