Public Access
Serve album covers from the service, show and sort by dates
Covers are stored with the assignment and served by the service, since Music Assistant's plain-http image URLs are blocked on an https page. Search results load covers through a signed /covers proxy. Adds a fetch-covers command for imported assignments, a migration for existing databases, and sorting assignments by artist, recently assigned or recently scanned, with both dates shown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+34
-1
@@ -1,8 +1,9 @@
|
||||
import json
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from tag_albums.library import MusicLibrary
|
||||
from tag_albums.library import Album, MusicLibrary
|
||||
|
||||
|
||||
def test_search_albums_parses_music_assistant_response():
|
||||
@@ -30,3 +31,35 @@ def test_search_albums_parses_music_assistant_response():
|
||||
library.search_albums("lateralus")
|
||||
# The Music Assistant config entry is looked up once, then cached.
|
||||
assert sum(c.url.path == "/api/config/config_entries/entry" for c in calls) == 1
|
||||
|
||||
|
||||
def _library_with_images(responses):
|
||||
seen = []
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
seen.append(request)
|
||||
return responses[str(request.url)]
|
||||
|
||||
images = httpx.Client(transport=httpx.MockTransport(handler))
|
||||
return MusicLibrary("http://ha", "ha-token", client=httpx.Client(), image_client=images), seen
|
||||
|
||||
|
||||
def test_fetch_image_checks_type_and_never_sends_ha_token():
|
||||
library, seen = _library_with_images({
|
||||
"http://ma/cover": httpx.Response(200, content=b"jpg", headers={"content-type": "image/jpeg"}),
|
||||
"http://ma/page": httpx.Response(200, content=b"<html>", headers={"content-type": "text/html"}),
|
||||
})
|
||||
assert library.fetch_image("http://ma/cover") == (b"jpg", "image/jpeg")
|
||||
assert "authorization" not in seen[0].headers
|
||||
with pytest.raises(ValueError):
|
||||
library.fetch_image("http://ma/page")
|
||||
|
||||
|
||||
def test_find_album_needs_exact_names():
|
||||
library = MusicLibrary("http://ha", "t", client=httpx.Client())
|
||||
library.search_albums = lambda query, limit=12: [
|
||||
Album("Tool", "Lateralus (Live)", "http://img/live"),
|
||||
Album("TOOL", "lateralus", "http://img/1"),
|
||||
]
|
||||
assert library.find_album("Tool", "Lateralus").image == "http://img/1"
|
||||
assert library.find_album("Mogwai", "Lateralus") is None
|
||||
|
||||
Reference in New Issue
Block a user