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`
|
applies rename + cover): name, kind, songs/length, `Playlist.date_created`
|
||||||
(set by every create_* since Round 130; older/iTunes playlists show —),
|
(set by every create_* since Round 130; older/iTunes playlists show —),
|
||||||
`date_modified`, last played and `source_url` (the link a URL import made
|
`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`
|
from both machines = Round 42's conflict): `storage/playlist_plays.py`
|
||||||
keeps `playlist_plays/<machine id>.json` per machine (owner-only writer,
|
keeps `playlist_plays/<machine id>.json` per machine (owner-only writer,
|
||||||
≤ one write a minute per playlist), stamped when a song starts in a
|
≤ 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."""
|
"""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
|
return
|
||||||
if dialog.new_name():
|
if dialog.new_name():
|
||||||
self._manager.rename_playlist(pid, 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()
|
change = dialog.art_change()
|
||||||
if change is not None:
|
if change is not None:
|
||||||
try:
|
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
|
Passive, like the song Get Info: nothing is written until OK, and then by
|
||||||
the caller (``MainWindow._playlist_info``), which reads ``new_name()`` and
|
the caller (``MainWindow._playlist_info``), which reads ``new_name()`` and
|
||||||
``art_change()``.
|
``source_change()`` and ``art_change()``.
|
||||||
"""
|
"""
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@@ -107,25 +107,27 @@ class PlaylistInfoDialog(QDialog):
|
|||||||
form.addRow("Songs changed:",
|
form.addRow("Songs changed:",
|
||||||
self._label(when_text(playlist.date_modified)))
|
self._label(when_text(playlist.date_modified)))
|
||||||
form.addRow("Last played:", self._label(when_text(last_played)))
|
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
|
source = playlist.source_url
|
||||||
if source:
|
|
||||||
row = QHBoxLayout()
|
row = QHBoxLayout()
|
||||||
self._source = QLineEdit(source)
|
self._source = QLineEdit(source)
|
||||||
self._source.setReadOnly(True)
|
self._source.setPlaceholderText("a link (https://…)")
|
||||||
self._source.setCursorPosition(0)
|
self._source.setCursorPosition(0)
|
||||||
copy = QPushButton("Copy")
|
copy = QPushButton("Copy")
|
||||||
copy.clicked.connect(
|
copy.clicked.connect(lambda: QApplication.clipboard().setText(
|
||||||
lambda: QApplication.clipboard().setText(source))
|
self._source.text().strip()))
|
||||||
open_link = QPushButton("Open")
|
open_link = QPushButton("Open")
|
||||||
open_link.clicked.connect(
|
open_link.clicked.connect(lambda: QDesktopServices.openUrl(
|
||||||
lambda: QDesktopServices.openUrl(QUrl(source)))
|
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(self._source, 1)
|
||||||
row.addWidget(copy)
|
row.addWidget(copy)
|
||||||
row.addWidget(open_link)
|
row.addWidget(open_link)
|
||||||
form.addRow("Imported from:", row)
|
form.addRow("Imported from:", row)
|
||||||
else:
|
|
||||||
form.addRow("Imported from:", self._label("—"))
|
|
||||||
self._source_label = source
|
|
||||||
|
|
||||||
box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok
|
box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok
|
||||||
| QDialogButtonBox.StandardButton.Cancel)
|
| QDialogButtonBox.StandardButton.Cancel)
|
||||||
@@ -161,6 +163,12 @@ class PlaylistInfoDialog(QDialog):
|
|||||||
name = self._name.text().strip()
|
name = self._name.text().strip()
|
||||||
return name if name and name != self._playlist.name else ""
|
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:
|
def art_change(self) -> bytes | None:
|
||||||
"""None: leave the cover; b"": remove it; else the new image."""
|
"""None: leave the cover; b"": remove it; else the new image."""
|
||||||
return self._art_change
|
return self._art_change
|
||||||
|
|||||||
@@ -224,6 +224,22 @@ class LibraryManager(QObject):
|
|||||||
def playlist_last_played(self, pid: str) -> str | None:
|
def playlist_last_played(self, pid: str) -> str | None:
|
||||||
return self.playlist_plays.last_played(pid)
|
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):
|
def rename_playlist(self, pid: str, name: str):
|
||||||
playlist = self.library.playlists.get(pid)
|
playlist = self.library.playlists.get(pid)
|
||||||
if playlist and name and playlist.name != name:
|
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""
|
assert dialog.new_name() == "Mix 2" and dialog.art_change() == b""
|
||||||
dialog._on_art_staged(PNG, "image/png")
|
dialog._on_art_staged(PNG, "image/png")
|
||||||
assert dialog.art_change() == 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,
|
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
|
return True
|
||||||
def new_name(self):
|
def new_name(self):
|
||||||
return "New Name"
|
return "New Name"
|
||||||
|
def source_change(self):
|
||||||
|
return "https://open.spotify.com/playlist/abc"
|
||||||
def art_change(self):
|
def art_change(self):
|
||||||
return bmp.read_bytes()
|
return bmp.read_bytes()
|
||||||
monkeypatch.setattr(mw, "PlaylistInfoDialog", _Dialog)
|
monkeypatch.setattr(mw, "PlaylistInfoDialog", _Dialog)
|
||||||
window._playlist_info(playlist.persistent_id)
|
window._playlist_info(playlist.persistent_id)
|
||||||
assert playlist.name == "New Name"
|
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)
|
saved = playlist_art.find(manager.data_dir, playlist.persistent_id)
|
||||||
assert saved.suffix == ".png"
|
assert saved.suffix == ".png"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user