|
|
|
@@ -290,7 +290,10 @@ def test_title_beside_artist_over_album_when_there_is_room(qapp):
|
|
|
|
|
assert (text.artist.text(), text.album.text()) == ("Donald Fagen",
|
|
|
|
|
"Kamakiriad")
|
|
|
|
|
|
|
|
|
|
text.resize(text.title.fontMetrics().horizontalAdvance(
|
|
|
|
|
from PyQt6.QtGui import QFontMetrics
|
|
|
|
|
big = text.title.font().pixelSize()
|
|
|
|
|
assert big > QFontMetrics(text._title_font).height() # it grew
|
|
|
|
|
text.resize(QFontMetrics(text._title_font).horizontalAdvance(
|
|
|
|
|
"Tomorrow's Girls") + 20, 50) # too narrow: the stack
|
|
|
|
|
assert not text.side and text.album.isHidden()
|
|
|
|
|
assert text.artist.text().startswith("Donald Fagen") # maybe elided
|
|
|
|
@@ -315,3 +318,122 @@ def test_fixed_lines_and_a_bare_title_always_stack(qapp):
|
|
|
|
|
assert not text.side and text.artist.text() == ""
|
|
|
|
|
text.set_song("Song", "", "Album only")
|
|
|
|
|
assert text.side and not text.album.isHidden() and text.artist.isHidden()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
|
# F. songs the library already has: unticked, but still in the playlist
|
|
|
|
|
|
|
|
|
|
from lintunes.library_match import LibraryMatcher # noqa: E402
|
|
|
|
|
from lintunes.models.track import Track # noqa: E402
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _t(tid, artist, name, seconds=200):
|
|
|
|
|
return Track(track_id=tid, artist=artist, name=name,
|
|
|
|
|
total_time=seconds * 1000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_the_matcher_finds_the_same_song_and_not_another_take():
|
|
|
|
|
m = LibraryMatcher([
|
|
|
|
|
_t(1, "Donald Fagen", "Tomorrow's Girls (Remastered)", 378),
|
|
|
|
|
_t(2, "Tate McRae", "Housewife", 209),
|
|
|
|
|
_t(3, "Some Band", "Song", 200),
|
|
|
|
|
_t(4, "Some Band", "Song", 320),
|
|
|
|
|
])
|
|
|
|
|
assert m.find("Donald Fagen", "Tomorrow's Girls", 378).track_id == 1
|
|
|
|
|
# Apple's "A & B" artist still shares a word with the library's.
|
|
|
|
|
assert m.find("Tate McRae & Julia Michaels", "Housewife",
|
|
|
|
|
209).track_id == 2
|
|
|
|
|
assert m.find("Some Band", "Song", 318).track_id == 4 # closest length
|
|
|
|
|
assert m.find("Some Band", "Song", 260) is None # neither take
|
|
|
|
|
assert m.find("Other Band", "Housewife", 209) is None
|
|
|
|
|
assert m.find("Donald Fagen", "Tomorrow's Girls", None).track_id == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_owned_songs_are_unticked_and_still_listed_in_order(qapp, canned):
|
|
|
|
|
owned = [_t(7, "Donald Fagen", "Tomorrow's Girls", 378)]
|
|
|
|
|
qapp.clipboard().setText(PLAYLIST_URL)
|
|
|
|
|
dialog = UrlImportDialog(None, library_tracks=lambda: owned)
|
|
|
|
|
dialog._on_import()
|
|
|
|
|
_pump(qapp, lambda: dialog._probe is None)
|
|
|
|
|
first, second = dialog._list.item(0), dialog._list.item(1)
|
|
|
|
|
assert "already in your library" in first.text()
|
|
|
|
|
assert first.checkState() == first.checkState().Unchecked
|
|
|
|
|
assert second.checkState() == second.checkState().Checked
|
|
|
|
|
assert "1 is already in your library" in dialog._status.text()
|
|
|
|
|
assert dialog._ok.text() == "Import 1 Song"
|
|
|
|
|
dialog._make.setChecked(True)
|
|
|
|
|
dialog._on_import()
|
|
|
|
|
assert [t.title for t in dialog.spotify_tracks()] == ["Zou bisou bisou"]
|
|
|
|
|
assert dialog.link_rows() == [
|
|
|
|
|
{"key": "617854252", "owned": 7, "download": False},
|
|
|
|
|
{"key": "1452872926", "owned": None, "download": True}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_all_owned_offers_to_add_them(qapp, canned):
|
|
|
|
|
owned = [_t(7, "Donald Fagen", "Tomorrow's Girls", 378),
|
|
|
|
|
_t(8, "Gillian Hills", "Zou bisou bisou", 136)]
|
|
|
|
|
qapp.clipboard().setText(PLAYLIST_URL)
|
|
|
|
|
dialog = UrlImportDialog(None, library_tracks=lambda: owned)
|
|
|
|
|
dialog._on_import()
|
|
|
|
|
_pump(qapp, lambda: dialog._probe is None)
|
|
|
|
|
assert dialog._ok.text() == "Add 2 Songs From Library"
|
|
|
|
|
assert dialog._ok.isEnabled()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_the_playlist_comes_out_in_the_links_order(window, qapp):
|
|
|
|
|
"""Owned songs go in as soon as everything before them is placed; a
|
|
|
|
|
download holds back what follows it; a failed one is skipped."""
|
|
|
|
|
manager = window._manager
|
|
|
|
|
for tid, name in ((1, "Have A"), (2, "Have B"), (3, "Got C"),
|
|
|
|
|
(4, "Got E")):
|
|
|
|
|
manager.add_track(_t(tid, "X", name))
|
|
|
|
|
window._url_target = None
|
|
|
|
|
window._url_inserted = 0
|
|
|
|
|
window._url_new_name, window._url_new_pid = "From Apple", ""
|
|
|
|
|
window._url_new_cover = ""
|
|
|
|
|
window._url_rows = [
|
|
|
|
|
{"key": "a", "owned": 1, "download": False},
|
|
|
|
|
{"key": "c", "owned": None, "download": True},
|
|
|
|
|
{"key": "b", "owned": 2, "download": False},
|
|
|
|
|
{"key": "d", "owned": None, "download": True}, # will fail
|
|
|
|
|
{"key": "e", "owned": None, "download": True},
|
|
|
|
|
]
|
|
|
|
|
window._url_placed = 0
|
|
|
|
|
window._place_url_rows()
|
|
|
|
|
[playlist] = _named(manager, "From Apple")
|
|
|
|
|
assert playlist.track_ids == [1] # c holds the rest back
|
|
|
|
|
window._url_row_done("e", 4) # lands early: waits
|
|
|
|
|
assert playlist.track_ids == [1]
|
|
|
|
|
window._url_row_done("c", 3)
|
|
|
|
|
assert playlist.track_ids == [1, 3, 2] # d still downloading
|
|
|
|
|
window._on_url_item_failed("d")
|
|
|
|
|
assert playlist.track_ids == [1, 3, 2, 4]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
|
# G. the playlist's cover in the art panel while nothing plays
|
|
|
|
|
|
|
|
|
|
def test_the_shown_playlists_cover_shows_while_nothing_plays(window, qapp,
|
|
|
|
|
tmp_path):
|
|
|
|
|
from PyQt6.QtGui import QColor, QImage
|
|
|
|
|
manager = window._manager
|
|
|
|
|
playlist = manager.create_playlist("Covered")
|
|
|
|
|
image = QImage(8, 8, QImage.Format.Format_RGB32)
|
|
|
|
|
image.fill(QColor("red"))
|
|
|
|
|
png = tmp_path / "c.png"
|
|
|
|
|
image.save(str(png))
|
|
|
|
|
playlist_art.save(manager.data_dir, playlist.persistent_id,
|
|
|
|
|
png.read_bytes())
|
|
|
|
|
art = window._sidebar.art
|
|
|
|
|
window._show_playlist(playlist.persistent_id)
|
|
|
|
|
assert art.showing_playlist_art() and art.has_art()
|
|
|
|
|
assert art._title() == "Covered"
|
|
|
|
|
|
|
|
|
|
manager.add_track(_t(9, "X", "Playing"))
|
|
|
|
|
art.set_track(manager.library.tracks[9]) # a song: its art wins
|
|
|
|
|
assert not art.showing_playlist_art()
|
|
|
|
|
art.set_track(None)
|
|
|
|
|
assert art.showing_playlist_art()
|
|
|
|
|
|
|
|
|
|
window._show_library() # no playlist shown
|
|
|
|
|
assert not art.showing_playlist_art() and not art.has_art()
|
|
|
|
|