v0.98.1: a playlist's Imported from link can be typed in Get Info, for playlists imported before it was kept
This commit is contained in:
@@ -873,7 +873,7 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
|
||||
applies rename + cover): name, kind, songs/length, `Playlist.date_created`
|
||||
(set by every create_* since Round 130; older/iTunes playlists show —),
|
||||
`date_modified`, last played and `source_url` (the link a URL import made
|
||||
it from). Last played is **never in the playlist JSON** (a write per song
|
||||
it from; editable there, undoable, `set_playlist_source`). Last played is **never in the playlist JSON** (a write per song
|
||||
from both machines = Round 42's conflict): `storage/playlist_plays.py`
|
||||
keeps `playlist_plays/<machine id>.json` per machine (owner-only writer,
|
||||
≤ one write a minute per playlist), stamped when a song starts in a
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||
|
||||
__version__ = "0.98.0"
|
||||
__version__ = "0.98.1"
|
||||
|
||||
@@ -1611,6 +1611,8 @@ class MainWindow(QMainWindow):
|
||||
return
|
||||
if dialog.new_name():
|
||||
self._manager.rename_playlist(pid, dialog.new_name())
|
||||
if dialog.source_change() is not None:
|
||||
self._manager.set_playlist_source(pid, dialog.source_change())
|
||||
change = dialog.art_change()
|
||||
if change is not None:
|
||||
try:
|
||||
|
||||
@@ -10,7 +10,7 @@ paste, drop or choose an image, or remove it.
|
||||
|
||||
Passive, like the song Get Info: nothing is written until OK, and then by
|
||||
the caller (``MainWindow._playlist_info``), which reads ``new_name()`` and
|
||||
``art_change()``.
|
||||
``source_change()`` and ``art_change()``.
|
||||
"""
|
||||
from datetime import datetime
|
||||
|
||||
@@ -107,25 +107,27 @@ class PlaylistInfoDialog(QDialog):
|
||||
form.addRow("Songs changed:",
|
||||
self._label(when_text(playlist.date_modified)))
|
||||
form.addRow("Last played:", self._label(when_text(last_played)))
|
||||
# Editable, so a playlist imported before Round 130 (or made by hand
|
||||
# from a list somewhere) can be given its link.
|
||||
source = playlist.source_url
|
||||
if source:
|
||||
row = QHBoxLayout()
|
||||
self._source = QLineEdit(source)
|
||||
self._source.setReadOnly(True)
|
||||
self._source.setPlaceholderText("a link (https://…)")
|
||||
self._source.setCursorPosition(0)
|
||||
copy = QPushButton("Copy")
|
||||
copy.clicked.connect(
|
||||
lambda: QApplication.clipboard().setText(source))
|
||||
copy.clicked.connect(lambda: QApplication.clipboard().setText(
|
||||
self._source.text().strip()))
|
||||
open_link = QPushButton("Open")
|
||||
open_link.clicked.connect(
|
||||
lambda: QDesktopServices.openUrl(QUrl(source)))
|
||||
open_link.clicked.connect(lambda: QDesktopServices.openUrl(
|
||||
QUrl(self._source.text().strip())))
|
||||
for button in (copy, open_link):
|
||||
button.setEnabled(bool(source))
|
||||
self._source.textChanged.connect(
|
||||
lambda text, b=button: b.setEnabled(bool(text.strip())))
|
||||
row.addWidget(self._source, 1)
|
||||
row.addWidget(copy)
|
||||
row.addWidget(open_link)
|
||||
form.addRow("Imported from:", row)
|
||||
else:
|
||||
form.addRow("Imported from:", self._label("—"))
|
||||
self._source_label = source
|
||||
|
||||
box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok
|
||||
| QDialogButtonBox.StandardButton.Cancel)
|
||||
@@ -161,6 +163,12 @@ class PlaylistInfoDialog(QDialog):
|
||||
name = self._name.text().strip()
|
||||
return name if name and name != self._playlist.name else ""
|
||||
|
||||
def source_change(self) -> str | None:
|
||||
"""The new "Imported from" link ("" clears it), or None to leave
|
||||
it."""
|
||||
text = self._source.text().strip()
|
||||
return None if text == self._playlist.source_url else text
|
||||
|
||||
def art_change(self) -> bytes | None:
|
||||
"""None: leave the cover; b"": remove it; else the new image."""
|
||||
return self._art_change
|
||||
|
||||
@@ -224,6 +224,22 @@ class LibraryManager(QObject):
|
||||
def playlist_last_played(self, pid: str) -> str | None:
|
||||
return self.playlist_plays.last_played(pid)
|
||||
|
||||
def set_playlist_source(self, pid: str, url: str):
|
||||
"""Where the playlist was imported from (Get Info), undoable. Not a
|
||||
change to its songs, so it moves no ``date_modified``."""
|
||||
playlist = self.library.playlists.get(pid)
|
||||
if playlist is None or playlist.source_url == url:
|
||||
return
|
||||
old = playlist.source_url
|
||||
|
||||
def apply(value):
|
||||
playlist.source_url = value
|
||||
self._mark_playlist(pid)
|
||||
apply(url)
|
||||
self.undo_stack.push(Command("Edit Playlist Info",
|
||||
undo=lambda: apply(old),
|
||||
redo=lambda: apply(url)))
|
||||
|
||||
def rename_playlist(self, pid: str, name: str):
|
||||
playlist = self.library.playlists.get(pid)
|
||||
if playlist and name and playlist.name != name:
|
||||
|
||||
@@ -555,6 +555,11 @@ def test_the_dialog_reports_name_and_cover_changes(qapp):
|
||||
assert dialog.new_name() == "Mix 2" and dialog.art_change() == b""
|
||||
dialog._on_art_staged(PNG, "image/png")
|
||||
assert dialog.art_change() == PNG
|
||||
assert dialog.source_change() is None
|
||||
dialog._source.setText(" ")
|
||||
assert dialog.source_change() == "" # cleared
|
||||
dialog._source.setText("https://open.spotify.com/playlist/z")
|
||||
assert dialog.source_change() == "https://open.spotify.com/playlist/z"
|
||||
|
||||
|
||||
def test_get_info_ok_renames_and_sets_the_cover(window, qapp, monkeypatch,
|
||||
@@ -575,11 +580,16 @@ def test_get_info_ok_renames_and_sets_the_cover(window, qapp, monkeypatch,
|
||||
return True
|
||||
def new_name(self):
|
||||
return "New Name"
|
||||
def source_change(self):
|
||||
return "https://open.spotify.com/playlist/abc"
|
||||
def art_change(self):
|
||||
return bmp.read_bytes()
|
||||
monkeypatch.setattr(mw, "PlaylistInfoDialog", _Dialog)
|
||||
window._playlist_info(playlist.persistent_id)
|
||||
assert playlist.name == "New Name"
|
||||
assert playlist.source_url == "https://open.spotify.com/playlist/abc"
|
||||
manager.undo_stack.undo() # the link edit is its own step
|
||||
assert playlist.source_url == ""
|
||||
saved = playlist_art.find(manager.data_dir, playlist.persistent_id)
|
||||
assert saved.suffix == ".png"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user