From 61c1a3db8e165c026190275911404fb678885461 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 1 Oct 2022 22:15:44 -0400 Subject: [PATCH 1/2] Add support for mixed content libraries --- resources/lib/dir_functions.py | 2 + resources/lib/menu_functions.py | 171 +++++++++++++++++++++++++++++++- 2 files changed, 168 insertions(+), 5 deletions(-) diff --git a/resources/lib/dir_functions.py b/resources/lib/dir_functions.py index 0f12aa0..9eeb3bf 100644 --- a/resources/lib/dir_functions.py +++ b/resources/lib/dir_functions.py @@ -68,6 +68,8 @@ def get_content(url, params): content_type = 'episodes' elif media_type == "playlists": view_type = "Playlists" + elif media_type == "mixed": + content_type = 'videos' log.debug("media_type:{0} content_type:{1} view_type:{2} ".format(media_type, content_type, view_type)) diff --git a/resources/lib/menu_functions.py b/resources/lib/menu_functions.py index 131b396..2a38212 100644 --- a/resources/lib/menu_functions.py +++ b/resources/lib/menu_functions.py @@ -280,6 +280,9 @@ def show_genre_list(menu_params): elif item_type == 'MusicAlbum': jellyfin_type = 'MusicAlbum' kodi_type = 'albums' + elif item_type == 'mixed': + jellyfin_type = 'Movie,Series' + kodi_type = 'videos' params = { "IncludeItemTypes": jellyfin_type, @@ -451,6 +454,56 @@ def show_tvshow_alpha_list(menu_params): xbmcplugin.endOfDirectory(int(sys.argv[1])) +def show_mixed_alpha_list(menu_params): + log.debug("== ENTER: showTvShowAlphaList() ==") + + server = settings.getSetting('server_address') + if server is None: + return + + parent_id = menu_params.get("parent_id") + user_id = get_current_user_id() + + prefixes = '#' + string.ascii_uppercase + + params = { + "Fields": get_default_filters(), + "ImageTypeLimit": 1, + "IncludeItemTypes": "Series,Movie", + "SortBy": "Name", + "SortOrder": "Ascending", + "Recursive": True, + "IsMissing": False + } + + for alpha_name in prefixes: + + if parent_id is not None: + params["ParentId"] = parent_id + + if alpha_name == "#": + params["NameLessThan"] = "A" + # Ensure we don't try to search both at once + if 'NameStartsWith' in params: + params.pop('NameStartsWith') + else: + params["NameStartsWith"] = alpha_name + # Ensure we don't try to search both at once + if 'NameLessThan' in params: + params.pop('NameLessThan') + + path = get_jellyfin_url("/Users/{userid}/Items", params) + + art = {"thumb": "http://localhost:24276/{}".format(ensure_text(base64.b64encode(ensure_binary(path))))} + + url = (sys.argv[0] + "?url=" + quote(path) + + "&mode=GET_CONTENT&media_type=mixed") + log.debug("addMenuDirectoryItem: {0} ({1})".format(alpha_name, url)) + add_menu_directory_item(alpha_name, url, art=art) + + xbmcplugin.endOfDirectory(int(sys.argv[1])) + + def show_artist_alpha_list(menu_params): log.debug("== ENTER: showArtistAlphaList() ==") @@ -1037,6 +1090,112 @@ def display_movies_type(menu_params, view): xbmcplugin.endOfDirectory(handle) +def display_mixed_type(params, view): + handle = int(sys.argv[1]) + + view_name = translate_string(30261) + if view is not None: + view_name = view.get("Name") + + item_limit = settings.getSetting("show_x_filtered_items") + user_id = get_current_user_id() + + # All Mixed content + base_params = { + "Fields": get_default_filters(), + "ImageTypeLimit": 1, + "IsMissing": False, + "IncludeItemTypes": "Series,Movie", + "Recursive": True + } + if view is not None: + base_params["ParentId"] = view.get("Id") + path = get_jellyfin_url("/Users/{userid}/Items", base_params) + url = sys.argv[0] + "?url=" + quote(path) + "&mode=GET_CONTENT&media_type=mixed" + add_menu_directory_item(view_name + translate_string(30405), url) + + # Favorite Mixed + params = {} + params.update(base_params) + params["Filters"] = "IsFavorite" + path = get_jellyfin_url("/Users/{userid}/Items", params) + url = sys.argv[0] + "?url=" + quote(path) + "&mode=GET_CONTENT&media_type=mixed" + add_menu_directory_item(view_name + translate_string(30414), url) + + # Unplayed Mixed + params = {} + params.update(base_params) + params["IsPlayed"] = False + path = get_jellyfin_url("/Users/{userid}/Items", params) + url = sys.argv[0] + "?url=" + quote(path) + "&mode=GET_CONTENT&media_type=mixed" + add_menu_directory_item(view_name + translate_string(30285), url) + + # In progress mixed + params = {} + params.update(base_params) + params["Limit"] = item_limit + params["SortBy"] = "DatePlayed" + params["SortOrder"] = "Descending" + params["Filters"] = "IsResumable" + params["IncludeItemTypes"] = "Episode" + path = get_jellyfin_url("/Users/{userid}/Items", params) + url = sys.argv[0] + "?url=" + quote(path) + "&mode=GET_CONTENT&media_type=mixed&sort=none" + url += "&name_format=" + quote('Episode|episode_name_format') + add_menu_directory_item(view_name + translate_string(30267) + " (" + item_limit + ")", url) + + # Latest mixed + params = {} + params.update(base_params) + params["Limit"] = item_limit + params["SortBy"] = "DateCreated" + params["SortOrder"] = "Descending" + params["IncludeItemTypes"] = "Episode" + path = get_jellyfin_url("/Users/{userid}/Items/Latest", params) + url = sys.argv[0] + "?url=" + quote(path) + "&mode=GET_CONTENT&media_type=mixed&sort=none" + add_menu_directory_item(view_name + translate_string(30288) + " (" + item_limit + ")", url) + + # Recently Added + params = {} + params.update(base_params) + params["Limit"] = item_limit + params["SortBy"] = "DateCreated" + params["SortOrder"] = "Descending" + params["Filters"] = "IsNotFolder" + params["IncludeItemTypes"] = "Episode" + path = get_jellyfin_url("/Users/{userid}/Items", params) + url = sys.argv[0] + "?url=" + quote(path) + "&mode=GET_CONTENT&media_type=mixed&sort=none" + url += "&name_format=" + quote('Episode|episode_name_format') + add_menu_directory_item(view_name + translate_string(30268) + " (" + item_limit + ")", url) + + # Next Up Episodes + params = {} + params.update(base_params) + params["Limit"] = item_limit + params["Userid"] = '{userid}' + params["SortBy"] = "DateCreated" + params["SortOrder"] = "Descending" + params["Filters"] = "IsNotFolder" + params["IncludeItemTypes"] = "Episode" + path = get_jellyfin_url("/Shows/NextUp", params) + url = sys.argv[0] + "?url=" + quote(path) + "&mode=GET_CONTENT&media_type=Episodes&sort=none" + url += "&name_format=" + quote('Episode|episode_name_format') + add_menu_directory_item(view_name + translate_string(30278) + " (" + item_limit + ")", url) + + # Mixed Genres + path = "plugin://plugin.video.jellycon/?mode=GENRES&item_type=mixed" + if view is not None: + path += "&parent_id=" + view.get("Id") + add_menu_directory_item(view_name + translate_string(30325), path) + + # Mixed Alpha picker + path = "plugin://plugin.video.jellycon/?mode=TVSHOW_ALPHA" + if view is not None: + path += "&parent_id=" + view.get("Id") + add_menu_directory_item(view_name + translate_string(30404), path) + + xbmcplugin.endOfDirectory(handle) + + def display_library_views(params): handle = int(sys.argv[1]) xbmcplugin.setContent(handle, 'files') @@ -1052,10 +1211,10 @@ def display_library_views(params): return [] views = views.get("Items", []) - view_types = ["movies", "tvshows", "homevideos", "boxsets", "playlists", "music", "musicvideos", "livetv", "Channel"] + view_types = ["movies", "tvshows", "homevideos", "boxsets", "playlists", "music", "musicvideos", "livetv", "Channel", "mixed"] for view in views: - collection_type = view.get('CollectionType', None) + collection_type = view.get('CollectionType', 'mixed') item_type = view.get('Type', None) if collection_type in view_types or item_type == "Channel": view_name = view.get("Name") @@ -1130,7 +1289,7 @@ def display_library_view(params): log.debug("VIEW_INFO : {0}".format(view_info)) - collection_type = view_info.get("CollectionType", None) + collection_type = view_info.get("CollectionType", "mixed") if collection_type == "movies": display_movies_type(params, view_info) @@ -1144,6 +1303,8 @@ def display_library_view(params): display_musicvideos_type(params, view_info) elif collection_type == "livetv": display_livetv_type(params, view_info) + elif collection_type == "mixed": + display_mixed_type(params, view_info) def show_widgets(): @@ -1211,8 +1372,8 @@ def set_library_window_values(force=False): index = 0 for item in result: - collection_type = item.get("CollectionType") - if collection_type in ["movies", "boxsets", "music", "tvshows"]: + collection_type = item.get("CollectionType", "mixed") + if collection_type in ["movies", "boxsets", "music", "tvshows", "mixed"]: name = item.get("Name") item_id = item.get("Id") From 00a7e92ef7dfbffe07e1720df6d9f53e094e604a Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 2 Oct 2022 08:07:40 -0400 Subject: [PATCH 2/2] Remove unused variable --- resources/lib/menu_functions.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/resources/lib/menu_functions.py b/resources/lib/menu_functions.py index 2a38212..3b626d6 100644 --- a/resources/lib/menu_functions.py +++ b/resources/lib/menu_functions.py @@ -462,7 +462,6 @@ def show_mixed_alpha_list(menu_params): return parent_id = menu_params.get("parent_id") - user_id = get_current_user_id() prefixes = '#' + string.ascii_uppercase @@ -1098,7 +1097,6 @@ def display_mixed_type(params, view): view_name = view.get("Name") item_limit = settings.getSetting("show_x_filtered_items") - user_id = get_current_user_id() # All Mixed content base_params = {