feat(providers): add nine catalogues and the Radio Browser directory
This commit is contained in:
1 parent
a3ad693132
commit
49f7efe0d2
27 files changed
+1695
-22
No files matched your search
@@ -0,0 +1,90 @@
|
||||
"""Radio Paradise: five mixes, one now-playing API, rolling history."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from beefy_player.providers.radioparadise import RadioParadiseProvider, api
|
||||
|
||||
NOW = {
|
||||
"time": 244,
|
||||
"artist": "Eric Bibb",
|
||||
"title": "Don't Ever Let Nobody Drag Your Spirit Down",
|
||||
"album": "Painting Signs",
|
||||
"year": "1999",
|
||||
"cover": "https://img.radioparadise.com/covers/l/1.jpg",
|
||||
}
|
||||
|
||||
|
||||
def test_parse_now_keeps_the_cover_art() -> None:
|
||||
song = api.parse_now(NOW)
|
||||
assert song is not None
|
||||
assert (song.artist, song.title) == ("Eric Bibb", NOW["title"])
|
||||
assert song.album == "Painting Signs"
|
||||
assert song.art_url.endswith("1.jpg")
|
||||
assert api.parse_now({}) is None
|
||||
assert api.parse_now(None) is None
|
||||
|
||||
|
||||
def test_playlists_prefer_flac_and_carry_real_bitrates() -> None:
|
||||
playlists = api.playlists(("flac", "aac-320", "mp3-320", "mp3-128"))
|
||||
assert [entry["url"].rsplit("/", 1)[1] for entry in playlists] == [
|
||||
"flac",
|
||||
"aac-320",
|
||||
"mp3-320",
|
||||
"mp3-128",
|
||||
]
|
||||
assert [entry["quality"] for entry in playlists] == [
|
||||
"highest",
|
||||
"high",
|
||||
"high",
|
||||
"high",
|
||||
]
|
||||
assert playlists[0]["bitrate"] == "1411"
|
||||
assert playlists[-1]["bitrate"] == "128"
|
||||
|
||||
|
||||
def test_five_mixes_with_channel_numbers() -> None:
|
||||
provider = RadioParadiseProvider()
|
||||
stations = provider.fallback_stations()
|
||||
assert [station.id for station in stations] == [
|
||||
"main",
|
||||
"mellow",
|
||||
"rock",
|
||||
"global",
|
||||
"beyond",
|
||||
]
|
||||
assert api.CHANNEL_BY_STATION["beyond"] == 5
|
||||
assert stations[0].format_label.startswith("flac")
|
||||
# the alternates are FLAC-only relays
|
||||
assert [entry["url"].rsplit("/", 1)[1] for entry in stations[1].playlists] == [
|
||||
"mellow-flac"
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_history_polls_the_right_channel_and_rolls() -> None:
|
||||
seen: list[str] = []
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
seen.append(str(request.url))
|
||||
return httpx.Response(200, json=NOW)
|
||||
|
||||
provider = RadioParadiseProvider()
|
||||
async with httpx.AsyncClient(transport=httpx.MockTransport(handler)) as client:
|
||||
first = await provider.fetch_history(client, "mellow")
|
||||
again = await provider.fetch_history(client, "mellow")
|
||||
|
||||
assert any("chan=1" in url for url in seen)
|
||||
assert len(first) == 1
|
||||
assert again[0].key() == first[0].key()
|
||||
assert again[0].played_at == first[0].played_at # first sighting kept
|
||||
assert provider.load_cached_stations()[0].title == "The Main Mix"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_an_unknown_station_has_no_history() -> None:
|
||||
provider = RadioParadiseProvider()
|
||||
async with httpx.AsyncClient(transport=httpx.MockTransport(lambda r: httpx.Response(200, json=NOW))) as client:
|
||||
assert await provider.fetch_history(client, "no-such-mix") == []
|
||||
Reference in new issue
Block a user