v0.94.0: a playlist made from a Spotify or Apple Music link keeps the link's cover image (stored, not shown yet)
This commit is contained in:
@@ -194,3 +194,77 @@ def test_an_apple_song_goes_straight_through(qapp, canned):
|
||||
_pump(qapp, lambda: dialog.result() == dialog.DialogCode.Accepted)
|
||||
assert [t.artist for t in dialog.spotify_tracks()] == ["Donald Fagen"]
|
||||
assert dialog.new_playlist_name() == ""
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# D. the playlist's cover (kept, not shown yet)
|
||||
|
||||
from lintunes import playlist_art # noqa: E402
|
||||
from tests.test_round109 import _import, _named, fake, window # noqa: E402,F401
|
||||
|
||||
JPEG = b"\xff\xd8\xff\xe0" + b"\0" * 32
|
||||
PNG = b"\x89PNG\r\n\x1a\n" + b"\0" * 32
|
||||
|
||||
|
||||
def test_cover_urls_are_read_off_every_kind_of_answer():
|
||||
page = PLAYLIST.replace(
|
||||
'"trackCount": 2}', '"trackCount": 2, "artwork": {"dictionary": '
|
||||
'{"url": "https://is1-ssl.mzstatic.com/x/{w}x{h}bb.{f}"}}}')
|
||||
assert apple_music_link.playlist_cover_url(page) == (
|
||||
"https://is1-ssl.mzstatic.com/x/1200x1200bb.jpg")
|
||||
assert apple_music_link.playlist_cover_url(PLAYLIST) == ""
|
||||
assert apple_music_link.lookup_cover_url({"results": [
|
||||
{"artworkUrl100": "https://a/b/100x100bb.jpg"}]}) == (
|
||||
"https://a/b/1200x1200bb.jpg")
|
||||
embed = ('<script id="__NEXT_DATA__" type="application/json">'
|
||||
+ json.dumps({"entity": {
|
||||
"type": "playlist", "name": "P",
|
||||
"trackList": [{"title": "t"}],
|
||||
"coverArt": {"sources": [
|
||||
{"url": "https://i.scdn.co/small", "width": 64},
|
||||
{"url": "https://i.scdn.co/big", "width": 640}]}}})
|
||||
+ "</script>")
|
||||
assert spotify_link.cover_url(embed) == "https://i.scdn.co/big"
|
||||
assert spotify_link.cover_url("<html></html>") == ""
|
||||
|
||||
|
||||
def test_a_cover_is_kept_per_playlist_and_replaced(tmp_path):
|
||||
assert playlist_art.find(tmp_path, "ABCD1234") is None
|
||||
playlist_art.save(tmp_path, "ABCD1234", JPEG)
|
||||
assert playlist_art.find(tmp_path, "ABCD1234").name == "ABCD1234.jpg"
|
||||
playlist_art.save(tmp_path, "ABCD1234", PNG) # png replaces jpg
|
||||
assert playlist_art.find(tmp_path, "ABCD1234").name == "ABCD1234.png"
|
||||
assert sorted(p.name for p in (tmp_path / "playlist_art").iterdir()) == [
|
||||
"ABCD1234.png"]
|
||||
with pytest.raises(ValueError):
|
||||
playlist_art.save(tmp_path, "ABCD1234", b"<html>not an image")
|
||||
with pytest.raises(ValueError):
|
||||
playlist_art.save(tmp_path, "../x", JPEG)
|
||||
|
||||
|
||||
def test_the_probe_passes_the_cover_on_for_a_new_playlist(qapp, monkeypatch):
|
||||
monkeypatch.setattr(apple_music_link, "fetch", lambda *a: (
|
||||
*parse_playlist_page(PLAYLIST), "https://img/cover.jpg"))
|
||||
dialog = _dialog(qapp, PLAYLIST_URL)
|
||||
dialog._on_import()
|
||||
_pump(qapp, lambda: dialog._probe is None)
|
||||
dialog._on_import()
|
||||
assert dialog.new_playlist_cover() == "" # not ticked: no cover
|
||||
dialog._make.setChecked(True)
|
||||
assert dialog.new_playlist_cover() == "https://img/cover.jpg"
|
||||
|
||||
|
||||
def test_the_new_playlist_gets_its_cover(window, qapp, fake, mp3_file,
|
||||
monkeypatch):
|
||||
monkeypatch.setenv("FAKE_YTDLP_AUDIO", str(mp3_file))
|
||||
monkeypatch.setattr(playlist_art, "download", lambda url: JPEG)
|
||||
saved = []
|
||||
real_save = playlist_art.save
|
||||
monkeypatch.setattr(playlist_art, "save",
|
||||
lambda *a: saved.append(real_save(*a)))
|
||||
manager = window._manager
|
||||
_import(window, qapp, monkeypatch, ["aaa", "bbb"], cover="https://img/c")
|
||||
[playlist] = _named(manager, "Road Trip")
|
||||
_pump(qapp, lambda: saved)
|
||||
assert playlist_art.find(manager.data_dir, playlist.persistent_id) \
|
||||
== saved[0]
|
||||
|
||||
Reference in New Issue
Block a user