async def _build_music_library( self, library: dict[str, Any], include_children: bool) -> BrowseMediaSource: """Return a single music library as a browsable media source.""" library_id = library[ITEM_KEY_ID] library_name = library[ITEM_KEY_NAME] result = BrowseMediaSource( domain=DOMAIN, identifier=library_id, media_class=MEDIA_CLASS_DIRECTORY, media_content_type=MEDIA_TYPE_NONE, title=library_name, can_play=False, can_expand=True, ) if include_children: result.children_media_class = MEDIA_CLASS_ARTIST result.children = await self._build_artists( library_id) # type: ignore[assignment] if not result.children: result.children_media_class = MEDIA_CLASS_ALBUM result.children = await self._build_albums( library_id) # type: ignore[assignment] return result
async def _build_movie_library( self, library: dict[str, Any], include_children: bool ) -> BrowseMediaSource: """Return a single movie library as a browsable media source.""" library_id = library[ITEM_KEY_ID] library_name = library[ITEM_KEY_NAME] result = BrowseMediaSource( domain=DOMAIN, identifier=library_id, media_class=MEDIA_CLASS_DIRECTORY, media_content_type=MEDIA_TYPE_NONE, title=library_name, can_play=False, can_expand=True, ) if include_children: result.children_media_class = MEDIA_CLASS_MOVIE result.children = await self._build_movies(library_id) return result
async def _build_album(self, album: dict[str, Any], include_children: bool) -> BrowseMediaSource: """Return a single album as a browsable media source.""" album_id = album[ITEM_KEY_ID] album_title = album[ITEM_KEY_NAME] thumbnail_url = self._get_thumbnail_url(album) result = BrowseMediaSource( domain=DOMAIN, identifier=album_id, media_class=MEDIA_CLASS_ALBUM, media_content_type=MEDIA_TYPE_NONE, title=album_title, can_play=False, can_expand=True, thumbnail=thumbnail_url, ) if include_children: result.children_media_class = MEDIA_CLASS_TRACK result.children = await self._build_tracks( album_id) # type: ignore[assignment] return result
async def _build_artist( self, artist: dict[str, Any], include_children: bool ) -> BrowseMediaSource: """Return a single artist as a browsable media source.""" artist_id = artist[ITEM_KEY_ID] artist_name = artist[ITEM_KEY_NAME] thumbnail_url = self._get_thumbnail_url(artist) result = BrowseMediaSource( domain=DOMAIN, identifier=artist_id, media_class=MEDIA_CLASS_ARTIST, media_content_type=MEDIA_TYPE_NONE, title=artist_name, can_play=False, can_expand=True, thumbnail=thumbnail_url, ) if include_children: result.children_media_class = MEDIA_CLASS_ALBUM result.children = await self._build_albums(artist_id) return result
async def async_library_items(jelly_cm: JellyfinClientManager, media_content_type_in=None, media_content_id_in=None, canPlayList=True) -> BrowseMediaSource: """ Create response payload to describe contents of a specific library. Used by async_browse_media. """ _LOGGER.debug( f'>> async_library_items: {media_content_id_in} / {canPlayList}') library_info = None query = None if (media_content_type_in is None): media_content_type = None media_content_id = None else: media_content_type, media_content_id = JellyfinSource.parse_mediasource_identifier( media_content_id_in) _LOGGER.debug( f'-- async_library_items: {media_content_type} / {media_content_id}') if media_content_type in [None, "library"]: library_info = BrowseMediaSource( domain=DOMAIN, identifier=f'library{IDENTIFIER_SPLIT}library', media_class=MEDIA_CLASS_DIRECTORY, media_content_type="library", title="Media Library", can_play=False, can_expand=True, children=[], ) elif media_content_type in [ MEDIA_CLASS_DIRECTORY, MEDIA_TYPE_ARTIST, MEDIA_TYPE_ALBUM, MEDIA_TYPE_PLAYLIST, MEDIA_TYPE_TVSHOW, MEDIA_TYPE_SEASON ]: query = { "ParentId": media_content_id, "sortBy": "SortName", "sortOrder": "Ascending" } parent_item = await jelly_cm.get_item(media_content_id) library_info = BrowseMediaSource( domain=DOMAIN, identifier= f'{media_content_type}{IDENTIFIER_SPLIT}{media_content_id}', media_class=media_content_type, media_content_type=media_content_type, title=parent_item["Name"], can_play=IsPlayable(parent_item["Type"], canPlayList), can_expand=True, thumbnail=jelly_cm.get_artwork_url(media_content_id), children=[], ) else: query = {"Id": media_content_id} library_info = BrowseMediaSource( domain=DOMAIN, identifier= f'{media_content_type}{IDENTIFIER_SPLIT}{media_content_id}', media_class=MEDIA_CLASS_DIRECTORY, media_content_type=media_content_type, title="", can_play=True, can_expand=False, thumbnail=jelly_cm.get_artwork_url(media_content_id), children=[], ) _LOGGER.debug(f'-- async_library_items: 1') items = await jelly_cm.get_items(query) for item in items: if media_content_type in [ None, "library", MEDIA_CLASS_DIRECTORY, MEDIA_TYPE_ARTIST, MEDIA_TYPE_ALBUM, MEDIA_TYPE_PLAYLIST, MEDIA_TYPE_TVSHOW, MEDIA_TYPE_SEASON ]: if item["IsFolder"]: library_info.children_media_class = MEDIA_CLASS_DIRECTORY library_info.children.append( BrowseMediaSource( domain=DOMAIN, identifier= f'{Type2Mediatype(item["Type"])}{IDENTIFIER_SPLIT}{item["Id"]}', media_class=Type2Mediaclass(item["Type"]), media_content_type=Type2Mimetype(item["Type"]), title=item["Name"], can_play=IsPlayable(item["Type"], canPlayList), can_expand=True, children=[], thumbnail=jelly_cm.get_artwork_url(item["Id"]))) else: library_info.children_media_class = Type2Mediaclass( item["Type"]) library_info.children.append( BrowseMediaSource( domain=DOMAIN, identifier= f'{Type2Mediatype(item["Type"])}{IDENTIFIER_SPLIT}{item["Id"]}', media_class=Type2Mediaclass(item["Type"]), media_content_type=Type2Mimetype(item["Type"]), title=item["Name"], can_play=IsPlayable(item["Type"], canPlayList), can_expand=False, children=[], thumbnail=jelly_cm.get_artwork_url(item["Id"]))) else: library_info.domain = DOMAIN library_info.identifier = f'{Type2Mediatype(item["Type"])}{IDENTIFIER_SPLIT}{item["Id"]}', library_info.title = item["Name"] library_info.media_content_type = Type2Mimetype(item["Type"]) library_info.media_class = Type2Mediaclass(item["Type"]) library_info.can_expand = False library_info.can_play = IsPlayable(item["Type"], canPlayList), break _LOGGER.debug(f'<< async_library_items {library_info.as_dict()}') return library_info