From 5ba6291fd984a10a978680c43f2ad9a6f1157b3e Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 4 Jun 2022 21:56:40 -0400 Subject: [PATCH 1/2] Add genre and alpha picker to music --- .../resource.language.en_gb/strings.po | 4 + resources/lib/functions.py | 4 +- resources/lib/menu_functions.py | 92 +++++++++++++++++-- 3 files changed, 91 insertions(+), 9 deletions(-) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index c118339..c2f2b40 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -624,6 +624,10 @@ msgctxt "#30322" msgid "Auto resume" msgstr "Auto resume" +msgctxt "#30323" +msgid "Artists" +msgstr "Artists" + msgctxt "#30325" msgid " - Genres" msgstr "- Genres" diff --git a/resources/lib/functions.py b/resources/lib/functions.py index a9bf7f4..d20d027 100644 --- a/resources/lib/functions.py +++ b/resources/lib/functions.py @@ -21,7 +21,7 @@ from .kodi_utils import HomeWindow from .datamanager import clear_cached_server_data from .server_detect import check_server, check_connection_speed from .lazylogger import LazyLogger -from .menu_functions import display_main_menu, display_menu, show_movie_alpha_list, show_tvshow_alpha_list, show_genre_list, show_search, show_movie_pages +from .menu_functions import display_main_menu, display_menu, show_movie_alpha_list, show_tvshow_alpha_list, show_genre_list, show_search, show_movie_pages, show_artist_alpha_list from .server_sessions import show_server_sessions from .action_menu import ActionMenu from .dialogs import BitrateDialog @@ -92,6 +92,8 @@ def main_entry_point(): show_movie_alpha_list(params) elif mode == "TVSHOW_ALPHA": show_tvshow_alpha_list(params) + elif mode == "ARTIST_ALPHA": + show_artist_alpha_list(params) elif mode == "GENRES": show_genre_list(params) elif mode == "MOVIE_PAGES": diff --git a/resources/lib/menu_functions.py b/resources/lib/menu_functions.py index 35a8815..98e25f5 100644 --- a/resources/lib/menu_functions.py +++ b/resources/lib/menu_functions.py @@ -267,11 +267,15 @@ def show_genre_list(menu_params): item_type = menu_params.get("item_type") user_id = get_current_user_id() - kodi_type = "Movies" - jellyfin_type = "Movie" - if item_type is not None and item_type == "tvshow": - jellyfin_type = "Series" - kodi_type = "tvshows" + if item_type == 'Movie': + jellyfin_type = "Movie" + kodi_type = 'Movies' + elif item_type == 'tvshow': + jellyfin_type = 'Series' + kodi_type = 'tvshows' + elif item_type == 'MusicAlbum': + jellyfin_type = 'MusicAlbum' + kodi_type = 'albums' params = {} params["IncludeItemTypes"] = jellyfin_type @@ -303,9 +307,6 @@ def show_genre_list(menu_params): item_data['title'] = genre.get("Name") item_data['media_type'] = kodi_type - # art = getArt(item=genre, server=server) - # item_data['art'] = art - params = {} params["Recursive"] = True params["CollapseBoxSetItems"] = str(group_movies) @@ -464,6 +465,68 @@ def show_tvshow_alpha_list(menu_params): xbmcplugin.endOfDirectory(int(sys.argv[1])) +def show_artist_alpha_list(menu_params): + log.debug("== ENTER: showArtistAlphaList() ==") + + xbmcplugin.setContent(int(sys.argv[1]), 'artists') + + server = settings.getSetting('server_address') + if server is None: + return + + parent_id = menu_params.get("parent_id") + user_id = get_current_user_id() + + url_params = {} + url_params["IncludeItemTypes"] = "MusicArtist" + url_params["Recursive"] = True + url_params["UserId"] = user_id + url_params["SortBy"] = "Name" + url_params["SortOrder"] = "Ascending" + if parent_id is not None: + url_params["ParentId"] = parent_id + + prefixes = '#' + string.ascii_uppercase + + collections = [] + for alpha_name in prefixes: + item_data = {} + item_data['title'] = alpha_name + item_data['media_type'] = "Artists" + + params = {} + params["Fields"] = get_default_filters() + params["Recursive"] = True + params["IncludeItemTypes"] = "MusicArtist" + params["SortBy"] = "Name" + params["SortOrder"] = "Ascending" + params["ImageTypeLimit"] = 1 + + if parent_id is not None: + params["ParentId"] = parent_id + + if alpha_name == "#": + params["NameLessThan"] = "A" + else: + params["NameStartsWith"] = alpha_name + + url = get_jellyfin_url("/Users/{}/Items".format(user_id), params) + item_data['path'] = url + + art = {"thumb": "http://localhost:24276/{}".format(ensure_text(base64.b64encode(ensure_binary(url))))} + item_data['art'] = art + + collections.append(item_data) + + for collection in collections: + url = (sys.argv[0] + "?url=" + quote(collection['path']) + + "&mode=GET_CONTENT&media_type=" + collection["media_type"]) + log.debug("addMenuDirectoryItem: {0} ({1})".format(collection.get('title'), url)) + add_menu_directory_item(collection.get('title', translate_string(30250)), url, art=collection.get("art")) + + xbmcplugin.endOfDirectory(int(sys.argv[1])) + + def display_main_menu(): handle = int(sys.argv[1]) xbmcplugin.setContent(handle, 'files') @@ -743,6 +806,19 @@ def display_music_type(menu_params, view): url = sys.argv[0] + "?url=" + quote(path) + "&mode=GET_CONTENT&media_type=MusicArtists" add_menu_directory_item(view_name + translate_string(30321), url) + # genres + path = "plugin://plugin.video.jellycon/?mode=GENRES&item_type=MusicAlbum" + if view is not None: + path += "&parent_id=" + view.get("Id") + add_menu_directory_item(view_name + translate_string(30325), path) + + # Artist Alpha picker + path = "plugin://plugin.video.jellycon/?mode=ARTIST_ALPHA" + if view is not None: + path += "&parent_id=" + view.get("Id") + add_menu_directory_item('{} - {}{}'.format( + view_name, translate_string(30323), translate_string(30404)), path) + xbmcplugin.endOfDirectory(handle) From c241cc9df94d15b144908c3d6d5214b0f71475c8 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 4 Jun 2022 22:10:54 -0400 Subject: [PATCH 2/2] Ensure variables are initialized before use --- resources/lib/menu_functions.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/lib/menu_functions.py b/resources/lib/menu_functions.py index 98e25f5..54e27bc 100644 --- a/resources/lib/menu_functions.py +++ b/resources/lib/menu_functions.py @@ -267,6 +267,8 @@ def show_genre_list(menu_params): item_type = menu_params.get("item_type") user_id = get_current_user_id() + jellyfin_type = '' + kodi_type = '' if item_type == 'Movie': jellyfin_type = "Movie" kodi_type = 'Movies'