def library_payload(*, can_play_artist: bool) -> BrowseMedia: """ Create response payload to describe contents of a specific library. Used by async_browse_media. """ browse_media = BrowseMedia( can_expand=True, can_play=False, children_media_class=MEDIA_CLASS_DIRECTORY, media_class=MEDIA_CLASS_DIRECTORY, media_content_id="library", media_content_type=f"{MEDIA_PLAYER_PREFIX}library", title="Media Library", ) browse_media.children = [] for item in [{"name": n, "type": t} for t, n in LIBRARY_MAP.items()]: browse_media.children.append( item_payload( { "name": item["name"], "type": item["type"], "uri": item["type"] }, can_play_artist=can_play_artist, )) return browse_media
async def library_payload(): """ Create response payload to describe contents of a specific library. Used by async_browse_media. """ library_info = BrowseMedia( media_class=MEDIA_CLASS_DIRECTORY, media_content_id="library", media_content_type="library", title="Media Library", can_play=False, can_expand=True, children=[], ) library = { "library_music": "Music", MEDIA_TYPE_MOVIE: "Movies", MEDIA_TYPE_TVSHOW: "TV shows", MEDIA_TYPE_CHANNEL: "Channels", } library_info.children = await asyncio.gather(*(item_payload( { "label": item["label"], "type": item["type"], "uri": item["type"], }, ) for item in [{ "label": name, "type": type_ } for type_, name in library.items()])) return library_info
async def library_payload(hass): """ Create response payload to describe contents of a specific library. Used by async_browse_media. """ library_info = BrowseMedia( media_class=MEDIA_CLASS_DIRECTORY, media_content_id="library", media_content_type="library", title="Media Library", can_play=False, can_expand=True, children=[], ) library = { "library_music": "Music", MEDIA_TYPE_MOVIE: "Movies", MEDIA_TYPE_TVSHOW: "TV shows", MEDIA_TYPE_CHANNEL: "Channels", } library_info.children = await asyncio.gather(*(item_payload( { "label": item["label"], "type": item["type"], "uri": item["type"], }, ) for item in [{ "label": name, "type": type_ } for type_, name in library.items()])) for child in library_info.children: child.thumbnail = "https://brands.home-assistant.io/_/kodi/logo.png" with contextlib.suppress(media_source.BrowseError): item = await media_source.async_browse_media( hass, None, content_filter=media_source_content_filter) # If domain is None, it's overview of available sources if item.domain is None: library_info.children.extend(item.children) else: library_info.children.append(item) return library_info
def server_payload(plex_server): """Create response payload to describe libraries of the Plex server.""" server_info = BrowseMedia( title=plex_server.friendly_name, media_class=MEDIA_CLASS_DIRECTORY, media_content_id=plex_server.machine_identifier, media_content_type="server", can_play=False, can_expand=True, children_media_class=MEDIA_CLASS_DIRECTORY, ) server_info.children = [] server_info.children.append(special_library_payload(server_info, "On Deck")) server_info.children.append(special_library_payload(server_info, "Recently Added")) for library in plex_server.library.sections(): if library.type == "photo": continue server_info.children.append(library_section_payload(library)) server_info.children.append(BrowseMedia(**PLAYLISTS_BROWSE_PAYLOAD)) return server_info
except KeyError: _LOGGER.debug("Unknown media type received: %s", media_content_type) return None if media_content_type == BrowsableMedia.CATEGORIES: media_item = BrowseMedia( can_expand=True, can_play=False, children_media_class=media_class["children"], media_class=media_class["parent"], media_content_id=media_content_id, media_content_type=f"{MEDIA_PLAYER_PREFIX}{media_content_type}", title=LIBRARY_MAP.get(media_content_id, "Unknown"), ) media_item.children = [] for item in items: try: item_id = item["id"] except KeyError: _LOGGER.debug("Missing ID for media item: %s", item) continue media_item.children.append( BrowseMedia( can_expand=True, can_play=False, children_media_class=MEDIA_CLASS_TRACK, media_class=MEDIA_CLASS_PLAYLIST, media_content_id=item_id, media_content_type= f"{MEDIA_PLAYER_PREFIX}category_playlists",