Fix plex browse media (#39766)

This commit is contained in:
Martin Hjelmare 2020-09-07 22:58:21 +02:00 committed by GitHub
parent c3ee79e4db
commit 38834d1945
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -76,7 +76,7 @@ def browse_media(
items = getattr(library_or_section, method)() items = getattr(library_or_section, method)()
for item in items: for item in items:
payload["children"].append(item_payload(item)) payload["children"].append(item_payload(item))
return payload return BrowseMedia(**payload)
if media_content_type in ["server", None]: if media_content_type in ["server", None]:
return server_payload(plex_server) return server_payload(plex_server)
@ -114,46 +114,44 @@ def item_payload(item):
def library_section_payload(section): def library_section_payload(section):
"""Create response payload for a single library section.""" """Create response payload for a single library section."""
return { return BrowseMedia(
"title": section.title, title=section.title,
"media_content_id": section.key, media_content_id=section.key,
"media_content_type": "library", media_content_type="library",
"can_play": False, can_play=False,
"can_expand": True, can_expand=True,
} )
def special_library_payload(parent_payload, special_type): def special_library_payload(parent_payload, special_type):
"""Create response payload for special library folders.""" """Create response payload for special library folders."""
title = f"{special_type} ({parent_payload['title']})" title = f"{special_type} ({parent_payload.title})"
return { return BrowseMedia(
"title": title, title=title,
"media_content_id": f"{parent_payload['media_content_id']}:{special_type}", media_content_id=f"{parent_payload.media_content_id}:{special_type}",
"media_content_type": parent_payload["media_content_type"], media_content_type=parent_payload.media_content_type,
"can_play": False, can_play=False,
"can_expand": True, can_expand=True,
} )
def server_payload(plex_server): def server_payload(plex_server):
"""Create response payload to describe libraries of the Plex server.""" """Create response payload to describe libraries of the Plex server."""
server_info = { server_info = BrowseMedia(
"title": plex_server.friendly_name, title=plex_server.friendly_name,
"media_content_id": plex_server.machine_identifier, media_content_id=plex_server.machine_identifier,
"media_content_type": "server", media_content_type="server",
"can_play": False, can_play=False,
"can_expand": True, can_expand=True,
}
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")
) )
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(): for library in plex_server.library.sections():
if library.type == "photo": if library.type == "photo":
continue continue
server_info["children"].append(library_section_payload(library)) server_info.children.append(library_section_payload(library))
server_info["children"].append(PLAYLISTS_BROWSE_PAYLOAD) server_info.children.append(BrowseMedia(**PLAYLISTS_BROWSE_PAYLOAD))
return server_info return server_info
@ -161,13 +159,13 @@ def library_payload(plex_server, library_id):
"""Create response payload to describe contents of a specific library.""" """Create response payload to describe contents of a specific library."""
library = plex_server.library.sectionByID(library_id) library = plex_server.library.sectionByID(library_id)
library_info = library_section_payload(library) library_info = library_section_payload(library)
library_info["children"] = [] library_info.children = []
library_info["children"].append(special_library_payload(library_info, "On Deck")) library_info.children.append(special_library_payload(library_info, "On Deck"))
library_info["children"].append( library_info.children.append(
special_library_payload(library_info, "Recently Added") special_library_payload(library_info, "Recently Added")
) )
for item in library.all(): for item in library.all():
library_info["children"].append(item_payload(item)) library_info.children.append(item_payload(item))
return library_info return library_info
@ -176,4 +174,4 @@ def playlists_payload(plex_server):
playlists_info = {**PLAYLISTS_BROWSE_PAYLOAD, "children": []} playlists_info = {**PLAYLISTS_BROWSE_PAYLOAD, "children": []}
for playlist in plex_server.playlists(): for playlist in plex_server.playlists():
playlists_info["children"].append(item_payload(playlist)) playlists_info["children"].append(item_payload(playlist))
return playlists_info return BrowseMedia(**playlists_info)