forked from trav/lintunes
v0.37.0: Import from URL takes Spotify links
A Spotify track, album or playlist is read off Spotify's public embed page, each song found on YouTube by the result closest to Spotify's length, downloaded with the song flags, tagged with Spotify's artist/title/album/track number, then imported and identified.
This commit is contained in:
@@ -18,6 +18,11 @@ first row and returned 2,967 rows in which the linked song appeared 8 times
|
||||
(the Mix loops back on itself). So rows are de-duplicated by id, and a
|
||||
song-in-a-list link gets **Just This Song**, which works from the first
|
||||
moment and downloads the song's own page with the list stripped off.
|
||||
|
||||
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.
|
||||
"""
|
||||
from urllib.parse import parse_qs, urlsplit
|
||||
|
||||
@@ -28,7 +33,9 @@ from PyQt6.QtWidgets import (
|
||||
QVBoxLayout,
|
||||
)
|
||||
|
||||
from lintunes.url_import import PlaylistProbe, link_kind, looks_like_url
|
||||
from lintunes.url_import import (
|
||||
PlaylistProbe, SpotifyProbe, link_kind, looks_like_url,
|
||||
)
|
||||
|
||||
ENTRY_ROLE = Qt.ItemDataRole.UserRole
|
||||
|
||||
@@ -72,7 +79,7 @@ class UrlImportDialog(QDialog):
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.addWidget(QLabel("Paste a link to a song, or to a playlist of "
|
||||
"songs:"))
|
||||
"songs (YouTube, Spotify, …):"))
|
||||
self._url = QLineEdit()
|
||||
self._url.setPlaceholderText("https://…")
|
||||
clipboard = QApplication.clipboard().text().strip()
|
||||
@@ -158,6 +165,15 @@ class UrlImportDialog(QDialog):
|
||||
chosen = self.chosen_entries()
|
||||
return [e["url"] for e in chosen] if chosen else [self.url()]
|
||||
|
||||
def spotify_tracks(self) -> list:
|
||||
"""The chosen songs of a Spotify link, as ``SpotifyTrack``s (empty
|
||||
for any other link): the ticked ones, or the link's one song."""
|
||||
if self._kind != "spotify":
|
||||
return []
|
||||
entries = self.chosen_entries() or (
|
||||
[self._single] if self._single else [])
|
||||
return [e["spotify"] for e in entries if e.get("spotify")]
|
||||
|
||||
def chosen_entries(self) -> list[dict]:
|
||||
"""The ticked songs, in the list's order. Empty means "download the
|
||||
link itself" (one song, or a link that was never listed)."""
|
||||
@@ -201,12 +217,15 @@ class UrlImportDialog(QDialog):
|
||||
self._single = None
|
||||
self._url.setEnabled(False)
|
||||
self._just.setVisible(bool(self._linked))
|
||||
self._status.setText("Checking what's at the link…")
|
||||
spotify = self._kind == "spotify"
|
||||
self._status.setText("Reading the songs off Spotify…" if spotify
|
||||
else "Checking what's at the link…")
|
||||
self._status.show()
|
||||
self._busy.show()
|
||||
# No parent: a cancelled probe's thread can outlive this dialog,
|
||||
# and must not be emitting from a deleted QObject when it does.
|
||||
probe = PlaylistProbe(url, cookies_browser=self._cookies)
|
||||
probe = (SpotifyProbe if spotify else PlaylistProbe)(
|
||||
url, cookies_browser=self._cookies)
|
||||
probe.entry.connect(self._on_entry)
|
||||
probe.finished.connect(self._on_probe_finished)
|
||||
probe.failed.connect(self._on_probe_failed)
|
||||
@@ -266,6 +285,11 @@ class UrlImportDialog(QDialog):
|
||||
|
||||
def _count_text(self, listing: bool) -> str:
|
||||
n = len(self._entries)
|
||||
if self._kind == "spotify":
|
||||
return (f"This Spotify link has {n} songs"
|
||||
+ ("…" if listing else ".")
|
||||
+ "\nEach one is found on YouTube by its artist, title "
|
||||
"and length.")
|
||||
text = f"This link is a playlist: {n} songs"
|
||||
if listing:
|
||||
text += " so far, still listing…"
|
||||
|
||||
Reference in New Issue
Block a user