v0.78.0: importing a playlist link can make a new playlist of the same name

Once a YouTube, SoundCloud or Spotify link turns out to be a named list,
Import from URL offers "Make a new playlist of these songs, named …"
(off unless ticked, the name editable). yt-dlp's listing now prints each
entry's playlist_title; Spotify's probe hands over the album's or
playlist's name. The playlist is made when the first song lands, so a
link that downloads nothing leaves no empty playlist, and the songs go
in in the link's order. Undoing "New Playlist" takes it all back in one
step.
This commit is contained in:
2026-10-23 01:47:41 -07:00
parent e368b8eb6e
commit 4a32baac3a
9 changed files with 327 additions and 7 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.77.1"
__version__ = "0.78.0"
+22
View File
@@ -287,6 +287,11 @@ class MainWindow(QMainWindow):
self._bpm_results: dict[int, int] = {}
self._url_target = None # url_import.ImportTarget, or None
self._url_inserted = 0 # songs added to the target so far
# "Make a new playlist of these songs": its name until the first
# song lands, then the playlist's pid (made then, so a link that
# downloads nothing leaves no empty playlist behind).
self._url_new_name = ""
self._url_new_pid = ""
self._url_imported = 0
self._url_identify = True # False after "Stop Identifying"
self._url_note = ""
@@ -1828,6 +1833,8 @@ class MainWindow(QMainWindow):
chosen = dialog.chosen_entries()
self._url_target = target if dialog.add_to_playlist() else None
self._url_inserted = 0
self._url_new_name = dialog.new_playlist_name()
self._url_new_pid = ""
self._url_imported = 0
self._url_identify = True
problem = self._identify_setup_problem()
@@ -1921,6 +1928,8 @@ class MainWindow(QMainWindow):
imported = self.import_files([Path(path)], pid, position)
if pid:
self._url_inserted += len(imported)
if imported and (self._url_new_name or self._url_new_pid):
self._add_to_new_url_playlist(imported)
self._url_imported += len(imported)
if self._url_progress is not None:
self._url_progress.landed(bool(imported))
@@ -1930,6 +1939,19 @@ class MainWindow(QMainWindow):
else:
self._enqueue_identify(imported)
def _add_to_new_url_playlist(self, tracks):
"""Into the link's own new playlist, in the order the songs land
(the link's order). One undo step: undoing "New Playlist" takes
it away with everything in it."""
if self._url_new_pid not in self._manager.library.playlists:
if not self._url_new_name:
return # it was made, then deleted mid-import
playlist = self._manager.create_playlist(self._url_new_name)
self._url_new_pid = playlist.persistent_id
self._url_new_name = ""
self._manager.add_tracks_to_playlist(
self._url_new_pid, [t.track_id for t in tracks], undoable=False)
def _finish_url_import(self):
if self._url_worker is not None:
self._url_worker.cleanup()
+46 -1
View File
@@ -23,6 +23,11 @@ A Spotify link (Round 76) is listed the same way, from Spotify's own page
(``url_import.SpotifyProbe``): a track goes straight through, an album or
playlist is a checklist with everything ticked. The caller reads the chosen
songs from ``spotify_tracks()`` and finds each one on YouTube.
A list that has a name (a YouTube or SoundCloud playlist, a Spotify album
or playlist) offers to make a new playlist of the same name holding every
song imported (``new_playlist_name()``). Off unless ticked; the name can be
edited first.
"""
from urllib.parse import parse_qs, urlsplit
@@ -75,6 +80,7 @@ class UrlImportDialog(QDialog):
self._single = None # the one entry of a one-song link
self._seen: set[str] = set() # ids already listed (a Mix loops)
self._just_song = False # "Just This Song" was pressed
self._list_name = "" # what the link's list is called
self.cookies_used = None # a browser the probe needed
layout = QVBoxLayout(self)
@@ -132,6 +138,20 @@ class UrlImportDialog(QDialog):
else:
self._add.setChecked(True)
# Shown once the link turns out to be a named list.
self._make_row = QHBoxLayout()
self._make = QCheckBox("Make a new playlist of these songs, named")
self._make_name = QLineEdit()
self._make_name.setEnabled(False)
self._make.toggled.connect(self._make_name.setEnabled)
self._make.toggled.connect(self._update_ok)
self._make_name.textChanged.connect(self._update_ok)
self._make_row.addWidget(self._make)
self._make_row.addWidget(self._make_name, 1)
for widget in (self._make, self._make_name):
widget.hide()
layout.addLayout(self._make_row)
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok
| QDialogButtonBox.StandardButton.Cancel)
self._ok = buttons.button(QDialogButtonBox.StandardButton.Ok)
@@ -157,6 +177,13 @@ class UrlImportDialog(QDialog):
def add_to_playlist(self) -> bool:
return self._add.isEnabled() and self._add.isChecked()
def new_playlist_name(self) -> str:
"""The name for a new playlist of the imported songs ("" for none)."""
if (not self._picking or not self._list_name or self._just_song
or not self._make.isChecked()):
return ""
return self._make_name.text().strip()
def download_urls(self) -> list[str]:
"""What to hand yt-dlp: the ticked songs' own pages, the linked song
alone, or the link itself — never a list link the user didn't see."""
@@ -193,7 +220,9 @@ class UrlImportDialog(QDialog):
if self._picking:
n = self._checked_count()
self._ok.setText(f"Import {n} Song{'' if n == 1 else 's'}")
self._ok.setEnabled(n > 0)
self._ok.setEnabled(n > 0 and not (
self._make.isChecked()
and not self._make_name.text().strip()))
elif self._probe is not None:
self._ok.setEnabled(False)
else:
@@ -215,6 +244,7 @@ class UrlImportDialog(QDialog):
self._entries = []
self._seen = set()
self._single = None
self._list_name = ""
self._url.setEnabled(False)
self._just.setVisible(bool(self._linked))
spotify = self._kind == "spotify"
@@ -227,6 +257,7 @@ class UrlImportDialog(QDialog):
probe = (SpotifyProbe if spotify else PlaylistProbe)(
url, cookies_browser=self._cookies)
probe.entry.connect(self._on_entry)
probe.named.connect(self._on_named)
probe.finished.connect(self._on_probe_finished)
probe.failed.connect(self._on_probe_failed)
probe.cookies_used.connect(self._on_cookies_used)
@@ -259,11 +290,25 @@ class UrlImportDialog(QDialog):
self._add_row(entry)
self._status.setText(self._count_text(listing=True))
def _on_named(self, name: str):
if self.sender() is not self._probe:
return
self._list_name = name
self._make_name.setText(name)
if self._picking:
self._show_make()
def _show_make(self):
self._make.show()
self._make_name.show()
def _show_picker(self):
self._picking = True
self._list.show()
self._all.show()
self._none.show()
if self._list_name:
self._show_make()
self.resize(max(self.width(), 560), max(self.height(), 520))
def _add_row(self, entry: dict):
+24 -5
View File
@@ -71,6 +71,9 @@ ENTRY = "LTENTRY"
# a postprocessor starting or finishing (ExtractAudio = the mp3 conversion).
HIT = "LTHIT"
POSTPROCESS = "LTPP"
# The name of the list an ENTRY came from (empty for a lone song), printed
# beside every entry — "make a new playlist with these songs" is named by it.
LISTNAME = "LTLIST"
# What YouTube says when it wants a signed-in browser. Matched on a fragment
@@ -189,6 +192,7 @@ def build_probe_command(url: str,
a different order every time it's listed."""
return [
"yt-dlp", "--flat-playlist", *_cookie_args(cookies_browser),
"--print", f"{LISTNAME} %(playlist_title|)s",
"--print",
f"{ENTRY} %(id)s\t%(duration|)s\t%(webpage_url|)s\t%(title)s",
"--", url,
@@ -232,7 +236,8 @@ def parse_line(line: str):
"""One line of yt-dlp output → ("start", i, n, id, title) |
("file", path) | ("progress", percent) | ("entry", {id, duration, url,
title}) | ("hit", {id, duration, views, url, channel, title}) |
("postprocess", name, status) | None for everything else."""
("postprocess", name, status) | ("list", name) | None for everything
else."""
line = line.rstrip("\r\n")
if line.startswith(START + " "):
parts = line[len(START) + 1:].split("\t", 3)
@@ -253,6 +258,9 @@ def parse_line(line: str):
return ("hit", {"id": parts[0], "duration": _duration(parts[1]),
"views": _int(parts[2], 0), "url": parts[3],
"channel": parts[4], "title": parts[5]})
if line.startswith(LISTNAME + " "):
name = line[len(LISTNAME) + 1:].strip()
return ("list", name) if name and name != "NA" else None
if line.startswith(POSTPROCESS + " "):
parts = line[len(POSTPROCESS) + 1:].split()
if len(parts) != 2:
@@ -479,17 +487,20 @@ class PlaylistProbe(_YtdlpRun):
``entry`` streams each song as yt-dlp finds it ({id, duration, url,
title}); a long Mix takes a while to list, and the dialog fills as it
goes. ``finished`` carries how many were found (cancelled or not);
``failed`` means none were.
goes. ``named`` carries the list's own name, once, if it has one.
``finished`` carries how many were found (cancelled or not); ``failed``
means none were.
"""
entry = pyqtSignal(dict)
named = pyqtSignal(str)
finished = pyqtSignal(int)
def __init__(self, url: str, parent=None, *,
cookies_browser: str | None = None):
super().__init__(parent, cookies_browser=cookies_browser)
self._url = url
self._named = False
def start(self):
if not self._busy:
@@ -499,7 +510,12 @@ class PlaylistProbe(_YtdlpRun):
return build_probe_command(self._url, cookies_browser)
def _on_parsed(self, parsed):
if parsed[0] != "entry" or self._cancel.is_set():
if self._cancel.is_set():
return False
if parsed[0] == "list" and not self._named:
self._named = True
self.named.emit(parsed[1])
if parsed[0] != "entry":
return False
self.entry.emit(parsed[1])
return True
@@ -603,6 +619,7 @@ class SpotifyProbe(QObject):
``SpotifyTrack`` under ``"spotify"``. One request, no yt-dlp."""
entry = pyqtSignal(dict)
named = pyqtSignal(str) # the album's or playlist's name
finished = pyqtSignal(int)
failed = pyqtSignal(str)
cookies_used = pyqtSignal(str) # never: Spotify needs no cookies
@@ -627,11 +644,13 @@ class SpotifyProbe(QObject):
def _run(self):
try:
kind, source_id = spotify_link.spotify_source(self._url)
_name, tracks = spotify_link.fetch(kind, source_id)
name, tracks = spotify_link.fetch(kind, source_id)
except Exception as e:
self._busy = False
self.failed.emit(str(e))
return
if kind != "track":
self.named.emit(name)
count = 0
for track in tracks:
if self._cancel.is_set():