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
+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):