/
/
/
1"""Parsers for Radio Paradise provider."""
2
3from typing import Any
4
5from music_assistant_models.enums import ImageType
6from music_assistant_models.media_items import (
7 MediaItemImage,
8 ProviderMapping,
9 Radio,
10)
11from music_assistant_models.streamdetails import StreamMetadata
12
13from .constants import RADIO_PARADISE_CHANNELS, STATION_ICONS_BASE_URL
14
15
16def parse_radio(channel_id: str, instance_id: str, provider_domain: str) -> Radio:
17 """Create a Radio object from cached channel information."""
18 channel_info = RADIO_PARADISE_CHANNELS.get(channel_id, {})
19
20 radio = Radio(
21 provider=instance_id,
22 item_id=channel_id,
23 name=channel_info.get("name", "Unknown Radio"),
24 provider_mappings={
25 ProviderMapping(
26 provider_domain=provider_domain,
27 provider_instance=instance_id,
28 item_id=channel_id,
29 available=True,
30 )
31 },
32 )
33
34 # Add static station icon
35 station_icon = channel_info.get("station_icon")
36 if station_icon:
37 icon_url = f"{STATION_ICONS_BASE_URL}/{station_icon}"
38 radio.metadata.add_image(
39 MediaItemImage(
40 provider=instance_id,
41 type=ImageType.THUMB,
42 path=icon_url,
43 remotely_accessible=True,
44 )
45 )
46
47 return radio
48
49
50def build_stream_metadata(current_song: dict[str, Any]) -> StreamMetadata:
51 """Build StreamMetadata with current track info.
52
53 :param current_song: Current track data from Radio Paradise now_playing API.
54 """
55 # Extract track info from now_playing API response
56 artist = current_song.get("artist", "Unknown Artist")
57 title = current_song.get("title", "Unknown Title")
58 album = current_song.get("album")
59 year = current_song.get("year")
60
61 # Build album string with year if available
62 album_display = album
63 if album and year:
64 album_display = f"{album} ({year})"
65 elif year:
66 album_display = str(year)
67
68 # Get cover image URL - now_playing API returns full URL
69 image_url = current_song.get("cover")
70
71 return StreamMetadata(
72 title=title,
73 artist=artist,
74 album=album_display,
75 image_url=image_url,
76 )
77