diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index f7a08a2..843c161 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -1157,6 +1157,22 @@ msgctxt "#30454" msgid " - Totally Unwatched" msgstr " - Totally Unwatched" +msgctxt "#30455" +msgid "TV Shows - Random" +msgstr "TV Shows - Random" + +msgctxt "#30456" +msgid "All - Random" +msgstr "All - Random" + +msgctxt "#30457" +msgid "All - Recently Added" +msgstr "All - Recently Added" + +msgctxt "#30458" +msgid "All - Favorites" +msgstr "All - Favorites" + msgctxt "#30666" msgid "Segment Skipper" msgstr "Segment Skipper" diff --git a/resources/lib/menu_functions.py b/resources/lib/menu_functions.py index e1c8b1d..087476d 100644 --- a/resources/lib/menu_functions.py +++ b/resources/lib/menu_functions.py @@ -1356,12 +1356,20 @@ def show_widgets(): add_menu_directory_item(translate_string(30287) + item_limit_text, 'plugin://plugin.video.jellycon/?mode=WIDGET_CONTENT&type=recent_tvshows') + add_menu_directory_item(translate_string(30455) + item_limit_text, + 'plugin://plugin.video.jellycon/?mode=WIDGET_CONTENT&type=random_tvshows') add_menu_directory_item(translate_string(30263) + item_limit_text, 'plugin://plugin.video.jellycon/?mode=WIDGET_CONTENT&type=recent_episodes') add_menu_directory_item(translate_string(30264) + item_limit_text, 'plugin://plugin.video.jellycon/?mode=WIDGET_CONTENT&type=inprogress_episodes') add_menu_directory_item(translate_string(30265) + item_limit_text, 'plugin://plugin.video.jellycon/?mode=WIDGET_CONTENT&type=nextup_episodes') + add_menu_directory_item(translate_string(30457) + item_limit_text, + 'plugin://plugin.video.jellycon/?mode=WIDGET_CONTENT&type=recent_all') + add_menu_directory_item(translate_string(30458), + 'plugin://plugin.video.jellycon/?mode=WIDGET_CONTENT&type=favorites_all') + add_menu_directory_item(translate_string(30456) + item_limit_text, + 'plugin://plugin.video.jellycon/?mode=WIDGET_CONTENT&type=random_all') xbmcplugin.endOfDirectory(int(sys.argv[1])) diff --git a/resources/lib/widgets.py b/resources/lib/widgets.py index b09a21c..b0aa1b4 100644 --- a/resources/lib/widgets.py +++ b/resources/lib/widgets.py @@ -67,6 +67,85 @@ def set_random_movies(): home_window.set_property("random-movies", movies_list_string) home_window.set_property("random-movies-changed", new_widget_hash) +@timer +def set_random_tvshows(): + log.debug("set_random_tvshows Called") + + settings = xbmcaddon.Addon() + item_limit = settings.getSetting("show_x_filtered_items") + hide_watched = settings.getSetting("hide_watched") == "true" + user_id = get_current_user_id() + + url_params = {} + url_params["Recursive"] = True + url_params["limit"] = item_limit + if hide_watched: + url_params["IsPlayed"] = False + url_params["SortBy"] = "Random" + url_params["IncludeItemTypes"] = "Series" + url_params["ImageTypeLimit"] = 0 + + url = get_jellyfin_url("/Users/{}/Items".format(user_id), url_params) + + results = api.get(url) + + random_tvshows_list = [] + if results is not None: + items = results.get("Items", []) + for item in items: + random_tvshows_list.append(item.get("Id")) + + random.shuffle(random_tvshows_list) + tvshow_list_string = ",".join(random_tvshows_list) + home_window = HomeWindow() + m = hashlib.md5() + m.update(tvshow_list_string.encode()) + new_widget_hash = m.hexdigest() + + log.debug("set_random_tvshows: {0}".format(tvshow_list_string)) + log.debug("set_random_tvshows: {0}".format(new_widget_hash)) + home_window.set_property("random-tvshows", tvshow_list_string) + home_window.set_property("random-tvshows-changed", new_widget_hash) + +@timer +def set_random_all(): + log.debug("set_random_all Called") + + settings = xbmcaddon.Addon() + item_limit = settings.getSetting("show_x_filtered_items") + hide_watched = settings.getSetting("hide_watched") == "true" + user_id = get_current_user_id() + + url_params = {} + url_params["Recursive"] = True + url_params["limit"] = item_limit + if hide_watched: + url_params["IsPlayed"] = False + url_params["SortBy"] = "Random" + url_params["IncludeItemTypes"] = "Movie,Series" + url_params["ImageTypeLimit"] = 0 + + url = get_jellyfin_url("/Users/{}/Items".format(user_id), url_params) + + results = api.get(url) + + random_items = [] + if results is not None: + items = results.get("Items", []) + for item in items: + random_items.append(item.get("Id")) + + random.shuffle(random_items) + item_list_string = ",".join(random_items) + home_window = HomeWindow() + m = hashlib.md5() + m.update(item_list_string.encode()) + new_widget_hash = m.hexdigest() + + log.debug("set_random_all: {0}".format(item_list_string)) + log.debug("set_random_all: {0}".format(new_widget_hash)) + home_window.set_property("random-all", item_list_string) + home_window.set_property("random-all-changed", new_widget_hash) def set_background_image(force=False): log.debug("set_background_image Called forced={0}".format(force)) @@ -333,6 +412,11 @@ def get_widget_content(handle, params): xbmcplugin.setContent(handle, 'movies') url_params["Ids"] = home_window.get_property("random-movies") + elif widget_type == "random_tvshows": + home_window = HomeWindow() + xbmcplugin.setContent(handle, 'tvshows') + url_params["Ids"] = home_window.get_property("random-tvshows") + elif widget_type == "recent_tvshows": xbmcplugin.setContent(handle, 'episodes') url_verb = '/Users/{}/Items/Latest'.format(user_id) @@ -397,6 +481,8 @@ def get_widget_content(handle, params): inprogress_url_params["IncludeItemTypes"] = "Episode" inprogress_url_params["Limit"] = item_limit + + elif widget_type == "movie_recommendations": suggested_items_url_params = {} suggested_items_url_params["userId"] = user_id @@ -436,6 +522,39 @@ def get_widget_content(handle, params): log.debug("Recommended Items : {0}".format(len(ids))) url_params["Ids"] = id_list + elif widget_type == "random_all": + home_window = HomeWindow() + xbmcplugin.setContent(handle, 'movies') + url_params["Ids"] = home_window.get_property("random-all") + + elif widget_type == "recent_all": + xbmcplugin.setContent(handle, 'movies') + url_verb = '/Users/{}/Items/Latest'.format(user_id) + url_params["GroupItems"] = True + url_params["Recursive"] = True + url_params["SortBy"] = "DateCreated" + url_params["SortOrder"] = "Descending" + url_params["Limit"] = 45 + url_params["Filters"] = "IsNotFolder" + url_params["Fields"] = get_default_filters() + if hide_watched: + url_params["IsPlayed"] = False + url_params["IsVirtualUnaired"] = False + url_params["IncludeItemTypes"] = "Episode, Movie" + url_params["ImageTypeLimit"] = 1 + + elif widget_type == "favorites_all": + home_window = HomeWindow() + xbmcplugin.setContent(handle, 'movies') + + url_params.update({ + "Filters": "IsFavorite", + "IncludeItemTypes": "Movie,Series", + "Recursive": True, + "SortBy": "Name", + "SortOrder": "Ascending", + }) + items_url = get_jellyfin_url(url_verb, url_params) if (url_params.get('IncludeItemTypes', '') == 'Episode' or diff --git a/service.py b/service.py index d68b84b..582585d 100644 --- a/service.py +++ b/service.py @@ -11,7 +11,7 @@ import xbmcgui from resources.lib.lazylogger import LazyLogger from resources.lib.play_utils import Service, PlaybackService, send_progress from resources.lib.kodi_utils import HomeWindow -from resources.lib.widgets import set_background_image, set_random_movies +from resources.lib.widgets import set_background_image, set_random_movies, set_random_tvshows, set_random_all from resources.lib.websocket_client import WebSocketClient from resources.lib.menu_functions import set_library_window_values from resources.lib.server_detect import check_server, check_connection_speed @@ -64,6 +64,8 @@ last_progress_update = time.time() last_content_check = time.time() last_background_update = 0 last_random_movie_update = 0 +last_random_tvshow_update = 0 +last_random_all_update = 0 # start the library update monitor library_change_monitor = LibraryChangeMonitor() @@ -145,6 +147,14 @@ while home_window.get_property('exit') == 'False': last_random_movie_update = time.time() set_random_movies() + if user_changed or (random_movie_list_interval != 0 and (time.time() - last_random_tvshow_update) > random_movie_list_interval): + last_random_tvshow_update = time.time() + set_random_tvshows() + + if user_changed or (random_movie_list_interval != 0 and (time.time() - last_random_all_update) > random_movie_list_interval): + last_random_all_update = time.time() + set_random_all() + if user_changed or (newcontent_interval != 0 and (time.time() - last_content_check) > newcontent_interval): last_content_check = time.time() library_change_monitor.check_for_updates() @@ -187,7 +197,7 @@ if play_next_service: # call stop on the context menu monitor if context_monitor: context_monitor.stop_monitor() - + if intro_skipper: intro_skipper.stop_service()