Beispiel #1
0
def library_payload():
    """
    Create response payload to describe contents of a specific library.

    Used by async_browse_media.
    """
    library_info = {
        "title": "Media Library",
        "media_class": MEDIA_CLASS_DIRECTORY,
        "media_content_id": "library",
        "media_content_type": "library",
        "can_play": False,
        "can_expand": True,
        "children": [],
    }

    for item in [{"name": n, "type": t} for t, n in LIBRARY_MAP.items()]:
        library_info["children"].append(
            item_payload({
                "name": item["name"],
                "type": item["type"],
                "uri": item["type"]
            }))
    response = BrowseMedia(**library_info)
    response.children_media_class = MEDIA_CLASS_DIRECTORY
    return response
Beispiel #2
0
def library_payload(coordinator, get_thumbnail_url=None):
    """
    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 = {
        MEDIA_TYPE_APPS: "Apps",
        MEDIA_TYPE_CHANNELS: "Channels",
    }

    for item in [{
            "title": name,
            "type": type_
    } for type_, name in library.items()]:
        if (item["type"] == MEDIA_TYPE_CHANNELS
                and coordinator.data.info.device_type != "tv"):
            continue

        library_info.children.append(
            item_payload(
                {
                    "title": item["title"],
                    "type": item["type"]
                },
                coordinator,
                get_thumbnail_url,
            ))

    if all(child.media_content_type == MEDIA_TYPE_APPS
           for child in library_info.children):
        library_info.children_media_class = MEDIA_CLASS_APP
    elif all(child.media_content_type == MEDIA_TYPE_CHANNELS
             for child in library_info.children):
        library_info.children_media_class = MEDIA_CLASS_CHANNEL

    return library_info
Beispiel #3
0
 def playlists_payload():
     """Create response payload for all available playlists."""
     playlists_info = {**PLAYLISTS_BROWSE_PAYLOAD, "children": []}
     for playlist in entity.plex_server.playlists():
         try:
             playlists_info["children"].append(item_payload(playlist))
         except UnknownMediaType:
             continue
     response = BrowseMedia(**playlists_info)
     response.children_media_class = MEDIA_CLASS_PLAYLIST
     return response
Beispiel #4
0
async def build_item_response(media_library, payload, get_thumbnail_url=None):
    """Create response payload for the provided media query."""
    search_id = payload["search_id"]
    search_type = payload["search_type"]

    _, title, media = await get_media_info(media_library, search_id, search_type)
    thumbnail = await get_thumbnail_url(search_type, search_id)

    if media is None:
        return None

    children = await asyncio.gather(
        *[item_payload(item, get_thumbnail_url) for item in media]
    )

    if search_type in (MEDIA_TYPE_TVSHOW, MEDIA_TYPE_MOVIE) and search_id == "":
        children.sort(key=lambda x: x.title.replace("The ", "", 1), reverse=False)

    response = BrowseMedia(
        media_class=CONTAINER_TYPES_SPECIFIC_MEDIA_CLASS.get(
            search_type, MEDIA_CLASS_DIRECTORY
        ),
        media_content_id=search_id,
        media_content_type=search_type,
        title=title,
        can_play=search_type in PLAYABLE_MEDIA_TYPES and search_id,
        can_expand=True,
        children=children,
        thumbnail=thumbnail,
    )

    if search_type == "library_music":
        response.children_media_class = MEDIA_CLASS_MUSIC
    else:
        response.calculate_children_class()

    return response