async def async_create_media_item_source(mass: MusicAssistant, media_item: dict): """Convert Music Assistant media_item into a BrowseMedia item.""" # get media_type and class media_type = media_item["media_type"] media_class = CONTENT_TYPE_MEDIA_CLASS[media_type] # get image url image = await mass.get_media_item_image_url(media_item) # create title if media_type == "album": title = f'{media_item["artist"]["name"]} - {media_item["name"]}' if media_type == "track": artist_names = [i["name"] for i in media_item["artists"]] artist_names_str = " / ".join(artist_names) title = f'{artist_names_str} - {media_item["name"]}' else: title = media_item["name"] # create media_content_id from provider/item_id combination media_item_id = ( f'{media_item["provider"]}{ITEM_ID_SEPERATOR}{media_item["item_id"]}') # we're constructing the identifier and media_content_id manually # this way we're compatible with both BrowseMedia and BrowseMediaSource identifier = f"{mass.server_id}/{media_type}/{media_item_id}" media_content_id = f"{MASS_URI_SCHEME}{identifier}" src = BrowseMedia( title=title, media_class=media_class["parent"], children_media_class=media_class["children"], media_content_id=media_content_id, media_content_type=CONTENT_TYPE_AUDIO, can_play=media_type in PLAYABLE_MEDIA_TYPES, children=[], can_expand=media_type not in [MEDIA_TYPE_TRACK, MEDIA_TYPE_RADIO], thumbnail=image, ) # set these manually so we're compatible with BrowseMediaSource src.identifier = identifier src.domain = DOMAIN return src