Add MA_URL to download covers through a reverse proxy

The jail can't reach Music Assistant's port 8095. MA_URL replaces the host of Music Assistant's image URLs when downloading. fetch-covers now stops at the first connection failure instead of stalling on every album, and image connections time out after 3 seconds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-25 21:34:41 +00:00
co-authored by Claude Opus 5.5
parent 1abba34cfe
commit 91e4519503
7 changed files with 100 additions and 11 deletions
+25
View File
@@ -176,3 +176,28 @@ def test_import_yaml(tmp_path):
store = Store(db)
assert store.get("29-92-68-C5").album == "Van Woede Tot Wanhoop"
store.close()
def test_fetch_covers_stops_when_music_assistant_is_unreachable(store, library):
import httpx
import pytest
def unreachable(url):
raise httpx.ConnectTimeout("timed out")
library.fetch_image = unreachable
library.image_download_url = lambda url: url
store.assign("A", "Tool", "Lateralus")
store.assign("B", "Kiasmos", "Kiasmos")
with pytest.raises(SystemExit, match="Set MA_URL"):
fetch_covers(store, library)
def test_settings_read_ma_url(monkeypatch):
from tag_albums.config import Settings
for k, v in {"API_TOKEN": "t", "HA_URL": "https://ha/", "HA_TOKEN": "h", "MA_URL": "https://ma.example/"}.items():
monkeypatch.setenv(k, v)
assert Settings.from_env().ma_url == "https://ma.example"
monkeypatch.delenv("MA_URL")
assert Settings.from_env().ma_url is None
+12
View File
@@ -63,3 +63,15 @@ def test_find_album_needs_exact_names():
]
assert library.find_album("Tool", "Lateralus").image == "http://img/1"
assert library.find_album("Mogwai", "Lateralus") is None
def test_ma_url_replaces_music_assistant_host_for_downloads():
library, seen = _library_with_images({
"https://ma.example/imageproxy/abc?size=0":
httpx.Response(200, content=b"jpg", headers={"content-type": "image/jpeg"}),
})
library._ma_url = httpx.URL("https://ma.example")
assert library.fetch_image("http://172.16.40.250:8095/imageproxy/abc?size=0") == (b"jpg", "image/jpeg")
assert str(seen[0].url) == "https://ma.example/imageproxy/abc?size=0"
# Without MA_URL the address is used as Music Assistant reports it.
assert MusicLibrary("http://ha", "t", client=httpx.Client()).image_download_url("http://x:8095/a") == "http://x:8095/a"