1 """Support to interface with the Roon API."""
9 """Unknown media type."""
33 _LOGGER = logging.getLogger(__name__)
36 def browse_media(zone_id, roon_server, media_content_type=None, media_content_id=None):
37 """Implement the websocket media browsing helper."""
39 _LOGGER.debug(
"browse_media: %s: %s", media_content_type, media_content_id)
40 if media_content_type
in [
None,
"library"]:
43 except UnknownMediaType
as err:
45 f
"Media not found: {media_content_type} / {media_content_id}"
50 """Create response payload for a single media item."""
53 if (subtitle := item.get(
"subtitle"))
is None:
56 display_title = f
"{title} ({subtitle})"
58 image_id = item.get(
"image_key")
or list_image_id
62 image = roon_server.roonapi.get_image(image_id)
64 media_content_id = item[
"item_key"]
65 media_content_type =
"library"
67 hint = item.get(
"hint")
69 media_class = MediaClass.DIRECTORY
71 elif hint ==
"action_list":
72 media_class = MediaClass.PLAYLIST
74 elif hint ==
"action":
75 media_content_type =
"track"
76 media_class = MediaClass.TRACK
80 media_class = MediaClass.DIRECTORY
82 _LOGGER.warning(
"Unknown hint %s - %s", title, hint)
85 "title": display_title,
86 "media_class": media_class,
87 "media_content_id": media_content_id,
88 "media_content_type": media_content_type,
90 "can_expand": can_expand,
98 """Create response payload for the library."""
101 "hierarchy":
"browse",
102 "zone_or_output_id": zone_id,
107 if media_content_id
is None or media_content_id ==
"Explore":
108 opts[
"pop_all"] =
True
109 content_id =
"Explore"
111 opts[
"item_key"] = media_content_id
112 content_id = media_content_id
114 result_header = roon_server.roonapi.browse_browse(opts)
115 _LOGGER.debug(
"Result header %s", result_header)
117 header = result_header[
"list"]
118 title = header.get(
"title")
120 if (subtitle := header.get(
"subtitle"))
is None:
123 list_title = f
"{title} ({subtitle})"
125 total_count = header[
"count"]
127 library_image_id = header.get(
"image_key")
131 media_content_id=content_id,
132 media_content_type=
"library",
133 media_class=MediaClass.DIRECTORY,
139 result_detail = roon_server.roonapi.browse_load(opts)
140 _LOGGER.debug(
"Result detail %s", result_detail)
142 items = result_detail[
"items"]
145 if count < total_count:
147 "Exceeded limit of %d, loaded %d/%d", ITEM_LIMIT, count, total_count
151 if item.get(
"title")
in EXCLUDE_ITEMS:
153 entry =
item_payload(roon_server, item, library_image_id)
154 library_info.children.append(entry)