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