v0.86.0: Identify windows find the album art too — one song gets a cover picker beside its tags, a playlist batch a cover per album
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
"""Round 119: the Identify windows find the album art too.
|
||||
|
||||
- One song: the Identify window searches a cover for the album its grid
|
||||
proposes, and searches again when the proposal changes.
|
||||
- Embed ticks itself only when the song has no cover yet.
|
||||
- A playlist batch gets a cover per album: one search at a time, a Cover
|
||||
column, the selected song's album beside the table.
|
||||
"""
|
||||
import pytest
|
||||
from PyQt6.QtCore import QBuffer, QByteArray, QIODevice, QObject, pyqtSignal
|
||||
from PyQt6.QtGui import QImage
|
||||
|
||||
from lintunes.art_search import ArtCandidate
|
||||
from lintunes.fingerprint import IdentifyCandidate
|
||||
from lintunes.gui import art_picker
|
||||
from lintunes.gui.identify_batch_dialog import IdentifyBatchDialog
|
||||
from lintunes.gui.identify_dialog import IdentifyDialog
|
||||
from lintunes.identify_batch import analyze
|
||||
from lintunes.models.track import Track
|
||||
|
||||
|
||||
class _Signals(QObject):
|
||||
search_finished = pyqtSignal(object)
|
||||
image_finished = pyqtSignal(object)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fetchers(monkeypatch):
|
||||
made = []
|
||||
|
||||
class _Fetcher:
|
||||
def __init__(self):
|
||||
self._s = _Signals()
|
||||
self.search_finished = self._s.search_finished
|
||||
self.image_finished = self._s.image_finished
|
||||
self.searched, self.fetched = [], []
|
||||
made.append(self)
|
||||
|
||||
def search(self, artist, album):
|
||||
self.searched.append((artist, album))
|
||||
|
||||
def fetch(self, candidate):
|
||||
self.fetched.append(candidate)
|
||||
monkeypatch.setattr(art_picker, "AlbumArtFetcher", _Fetcher)
|
||||
return made
|
||||
|
||||
|
||||
def _png():
|
||||
image = QImage(4, 4, QImage.Format.Format_RGB32)
|
||||
image.fill(0x00ff00)
|
||||
data = QByteArray()
|
||||
buf = QBuffer(data)
|
||||
buf.open(QIODevice.OpenModeFlag.WriteOnly)
|
||||
image.save(buf, "PNG")
|
||||
return bytes(data)
|
||||
|
||||
|
||||
def _c(name, album, artist="Digable Planets", score=0.9):
|
||||
return IdentifyCandidate(score=score, source="acoustid", name=name,
|
||||
artist=artist, album=album)
|
||||
|
||||
|
||||
def _answer(fetcher, album="Reachin'"):
|
||||
art = ArtCandidate("Digable Planets", album, "http://x/a.jpg")
|
||||
fetcher.search_finished.emit({"candidates": [art]})
|
||||
fetcher.image_finished.emit({"candidate": art, "image": _png(),
|
||||
"mime": "image/png"})
|
||||
|
||||
|
||||
def test_one_song_searches_the_proposed_album(qapp, fetchers):
|
||||
track = Track(track_id=1, name="rebirth of slick [abc123]")
|
||||
dialog = IdentifyDialog(track, [_c("Rebirth of Slick", "Reachin'"),
|
||||
_c("Rebirth of Slick", "Best Of")],
|
||||
find_art=True)
|
||||
assert fetchers[-1].searched == [("Digable Planets", "Reachin'")]
|
||||
_answer(fetchers[-1])
|
||||
assert dialog.art._embed.isChecked()
|
||||
dialog._on_accept()
|
||||
assert dialog.selected_image == _png()
|
||||
assert dialog.selected_mime == "image/png"
|
||||
|
||||
|
||||
def test_another_candidate_searches_again_and_old_answers_are_ignored(
|
||||
qapp, fetchers):
|
||||
track = Track(track_id=1, name="x")
|
||||
dialog = IdentifyDialog(track, [_c("Song", "Reachin'"),
|
||||
_c("Song", "Best Of")], find_art=True)
|
||||
first = fetchers[-1]
|
||||
dialog.panel._combo.setCurrentIndex(1)
|
||||
assert fetchers[-1].searched == [("Digable Planets", "Best Of")]
|
||||
_answer(first) # the old search, late
|
||||
assert dialog.art.image() is None
|
||||
dialog._on_accept()
|
||||
assert dialog.selected_image is None
|
||||
|
||||
|
||||
def test_typing_an_album_searches_after_a_pause(qapp, fetchers):
|
||||
track = Track(track_id=1, name="x")
|
||||
dialog = IdentifyDialog(track, [_c("Song", "")], find_art=True)
|
||||
assert fetchers == [] # nothing to search by
|
||||
album = dialog.panel._editors["album"]
|
||||
dialog.panel._checks["album"].setEnabled(True)
|
||||
dialog.panel._checks["album"].setChecked(True)
|
||||
album.setText("Blowout Comb")
|
||||
assert fetchers == [] # still typing
|
||||
dialog._art_timer.timeout.emit()
|
||||
assert fetchers[-1].searched == [("Digable Planets", "Blowout Comb")]
|
||||
|
||||
|
||||
def test_a_song_with_a_cover_isnt_ticked_to_replace_it(qapp, fetchers):
|
||||
track = Track(track_id=1, name="x")
|
||||
dialog = IdentifyDialog(track, [_c("Song", "Reachin'")], find_art=True,
|
||||
embed_art=False)
|
||||
_answer(fetchers[-1])
|
||||
assert not dialog.art._embed.isChecked()
|
||||
dialog._on_accept()
|
||||
assert dialog.selected_image is None
|
||||
|
||||
|
||||
def test_plain_identify_dialog_searches_nothing(qapp, fetchers):
|
||||
dialog = IdentifyDialog(Track(track_id=1, name="x"),
|
||||
[_c("Song", "Reachin'")])
|
||||
assert dialog.art is None and fetchers == []
|
||||
|
||||
|
||||
def test_a_playlist_gets_a_cover_per_album_one_search_at_a_time(
|
||||
qapp, fetchers):
|
||||
analysis = analyze([
|
||||
(Track(track_id=1), [_c("A", "Reachin'")]),
|
||||
(Track(track_id=2), [_c("B", "Blowout Comb")]),
|
||||
(Track(track_id=3), [_c("C", "Reachin'")]),
|
||||
(Track(track_id=4), []), # nothing to search by
|
||||
])
|
||||
dialog = IdentifyBatchDialog(analysis, None)
|
||||
assert not analysis.is_album
|
||||
assert [f.searched for f in fetchers] == [
|
||||
[("Digable Planets", "Reachin'")]]
|
||||
_answer(fetchers[0])
|
||||
assert [f.searched for f in fetchers][1:] == [
|
||||
[("Digable Planets", "Blowout Comb")]]
|
||||
|
||||
rows = {r.track.track_id: i for i, r in enumerate(dialog._rows)}
|
||||
cover = dialog._cover_col
|
||||
assert not dialog._table.item(rows[1], cover).icon().isNull()
|
||||
assert not dialog._table.item(rows[3], cover).icon().isNull()
|
||||
assert dialog._table.item(rows[2], cover).icon().isNull()
|
||||
|
||||
dialog._table.selectRow(rows[2])
|
||||
assert dialog._cover_stack.currentWidget() is \
|
||||
dialog._pickers[("digable planets", "blowout comb")]
|
||||
dialog._table.selectRow(rows[4])
|
||||
assert dialog._cover_stack.currentWidget() is dialog._no_album
|
||||
|
||||
[(art_rows, image, _mime)] = dialog.selected_art()
|
||||
assert sorted(r.track.track_id for r in art_rows) == [1, 3]
|
||||
assert image == _png()
|
||||
|
||||
# Unticking Embed takes the thumbnails away and the cover with them.
|
||||
dialog._pickers[("digable planets", "reachin'")]._embed.setChecked(False)
|
||||
assert dialog._table.item(rows[1], cover).icon().isNull()
|
||||
assert dialog.selected_art() == []
|
||||
+14
-11
@@ -14,7 +14,7 @@ from PyQt6.QtCore import Qt
|
||||
|
||||
from lintunes import identify_batch
|
||||
from lintunes.fingerprint import IdentifyCandidate
|
||||
from lintunes.gui import identify_batch_dialog as dialog_module
|
||||
from lintunes.gui import art_picker as dialog_module
|
||||
from lintunes.gui.identify_batch_dialog import (
|
||||
IdentifyBatchDialog, format_cell, parse_cell,
|
||||
)
|
||||
@@ -183,7 +183,7 @@ def test_the_album_window_applies_ticked_rows(qapp, no_network):
|
||||
assert [r.track.track_id for r in dialog.unchecked_rows()] == [2]
|
||||
dialog._on_apply()
|
||||
assert dialog.outcome == dialog.APPLY
|
||||
assert dialog.selected_image is None # no art loaded
|
||||
assert dialog.selected_art() == [] # no art loaded
|
||||
|
||||
|
||||
def test_art_arrives_ticked_and_is_handed_over(qapp, no_network):
|
||||
@@ -200,21 +200,23 @@ def test_art_arrives_ticked_and_is_handed_over(qapp, no_network):
|
||||
analysis = _album_analysis()
|
||||
dialog = IdentifyBatchDialog(analysis, ("The Breeders", "Last Splash"))
|
||||
art = ArtCandidate("The Breeders", "Last Splash", "http://x/a.jpg")
|
||||
dialog._on_art_search({"candidates": [art]})
|
||||
dialog._on_art_image({"candidate": art, "image": bytes(data),
|
||||
"mime": "image/png"})
|
||||
assert dialog._embed.isChecked()
|
||||
dialog._art._on_search({"candidates": [art]})
|
||||
dialog._art._on_image({"candidate": art, "image": bytes(data),
|
||||
"mime": "image/png"})
|
||||
assert dialog._art._embed.isChecked()
|
||||
dialog._on_apply()
|
||||
assert dialog.selected_image == bytes(data)
|
||||
assert dialog.selected_mime == "image/png"
|
||||
[(rows, image, mime)] = dialog.selected_art()
|
||||
assert len(rows) == 2
|
||||
assert image == bytes(data) and mime == "image/png"
|
||||
|
||||
|
||||
def test_a_playlist_window_has_no_album_panel(qapp, no_network):
|
||||
analysis = analyze([(_t(1), [_c("A", "One")]),
|
||||
(_t(2), [_c("B", "Two")])])
|
||||
dialog = IdentifyBatchDialog(analysis, None)
|
||||
assert dialog._album_edit is None and dialog._embed is None
|
||||
assert no_network == []
|
||||
assert dialog._album_edit is None and dialog._art is None
|
||||
# A cover per album instead (Round 119), searched one at a time.
|
||||
assert no_network == [("The Breeders", "One")]
|
||||
dialog._on_review_all()
|
||||
assert dialog.outcome == dialog.REVIEW_ALL
|
||||
|
||||
@@ -319,7 +321,8 @@ def test_a_batch_review_applies_then_reviews_the_unticked(window, qapp,
|
||||
class _Batch:
|
||||
APPLY, REVIEW_ALL = 1, 2
|
||||
outcome = 1
|
||||
selected_image = None
|
||||
def selected_art(self):
|
||||
return []
|
||||
def __init__(self, analysis, query, parent):
|
||||
pass
|
||||
def exec(self):
|
||||
|
||||
Reference in New Issue
Block a user