The app now holds one RadioProvider and asks it for stations, song history and stream URLs instead of importing SomaFM's HTTP client directly. - models.py: provider-neutral Song/Station plus the shared parsers every catalogue needs (Station.provider/.uid keep ids unique once there is more than one). - providers/base.py: the RadioProvider interface and the toolkit it needs in practice - httpx client factory, .pls/.m3u resolution with an 8h disk cache, and a default stream_candidates() strategy. - providers/somafm/: everything SomaFM-specific (channels.json, songs/<id>.json, PLS layout, guessed icecast mirrors) behind SomaFMProvider. - providers/__init__.py: registry, get_provider() and --provider, remembered in the config file. Widgets render branding, splash copy and the help credits from the active provider, so a second catalogue needs no UI changes; with SomaFM selected the screen is byte-identical to before.
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
os.environ["BEEFY_IMAGES"] = "0"
|
|
|
|
import pytest
|
|
|
|
from beefy_player import config
|
|
from beefy_player.providers import base
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def isolated_state(tmp_path, monkeypatch):
|
|
"""Keep tests out of the real ~/.config and ~/.cache."""
|
|
config_dir = tmp_path / "config"
|
|
cache_dir = tmp_path / "cache"
|
|
songs_dir = cache_dir / "songs"
|
|
runtime_dir = tmp_path / "run"
|
|
|
|
for attr, value in (
|
|
("CONFIG_DIR", config_dir),
|
|
("CACHE_DIR", cache_dir),
|
|
("SONGS_CACHE_DIR", songs_dir),
|
|
("RUNTIME_DIR", runtime_dir),
|
|
("CONFIG_PATH", config_dir / "config.json"),
|
|
("CHANNELS_CACHE", cache_dir / "channels.json"),
|
|
("PLAYLIST_CACHE", cache_dir / "playlists.json"),
|
|
("ARTWORK_CACHE_DIR", cache_dir / "artwork"),
|
|
("LEGACY_CONFIG_PATH", tmp_path / "legacy" / "config.json"),
|
|
):
|
|
monkeypatch.setattr(config, attr, value)
|
|
|
|
def ensure_dirs() -> None:
|
|
for path in (config_dir, cache_dir, songs_dir, runtime_dir):
|
|
path.mkdir(parents=True, exist_ok=True)
|
|
|
|
monkeypatch.setattr(config, "ensure_dirs", ensure_dirs)
|
|
base.reset_playlist_cache()
|
|
ensure_dirs()
|
|
yield
|