From 48eac3643b5f9fb52cfb004ce54ec31211eab73c Mon Sep 17 00:00:00 2001 From: Alhaziel01 Date: Thu, 26 Aug 2021 16:20:25 +0200 Subject: [PATCH] Test Semplificazione Ordine server e piccoli fix --- core/autoplay.py | 14 +++++------ core/servertools.py | 45 +++++++++++------------------------ core/tmdb.py | 2 ++ platformcode/platformtools.py | 32 ++++++++++++------------- 4 files changed, 39 insertions(+), 54 deletions(-) diff --git a/core/autoplay.py b/core/autoplay.py index d5eace64..9aae4d4b 100644 --- a/core/autoplay.py +++ b/core/autoplay.py @@ -39,14 +39,14 @@ def start(itemlist, item): if not config.is_xbmc(): return itemlist - # Save the current value of "Action and Player Mode" in preferences - user_config_setting_action = config.get_setting("default_action") - # user_config_setting_player = config.get_setting("player_mode") - - # Enable the "View in high quality" action (if the server returns more than one quality, eg gdrive) - if not user_config_setting_action: config.set_setting("default_action", 2) - if config.get_setting('autoplay'): + # Save the current value of "Action and Player Mode" in preferences + user_config_setting_action = config.get_setting("default_action") + # user_config_setting_player = config.get_setting("player_mode") + + # Enable the "View in high quality" action (if the server returns more than one quality, eg gdrive) + if not user_config_setting_action: config.set_setting("default_action", 2) + from core.servertools import sort_servers autoplay_list = sort_servers(itemlist) diff --git a/core/servertools.py b/core/servertools.py index 75d0c058..66d01c0b 100644 --- a/core/servertools.py +++ b/core/servertools.py @@ -695,28 +695,19 @@ def sort_servers(servers_list): 'sd', '480p', '480', '360p', '360', '240p', '240'] sorted_list = [] - url_list_valid = [] - if config.get_setting('default_action') == 1: - favorite_quality.reverse() + inverted = False + + if config.get_setting('default_action') == 2: + inverted = True # Priorities when ordering itemlist: - # 0: Servers and Qualities - # 1: Qualities and Servers - # 2: Servers only - # 3: Only qualities - # 4: Do not order - - if config.get_setting('favorites_servers') and favorite_servers and config.get_setting('default_action') and not config.get_setting('quality_priority'): - priority = 0 # 0: Servers and Qualities - elif config.get_setting('favorites_servers') and favorite_servers and config.get_setting('default_action') and config.get_setting('quality_priority'): - priority = 1 # 0: Qualities and Servers - elif config.get_setting('favorites_servers') and favorite_servers: - priority = 2 # Servers only - elif config.get_setting('default_action'): - priority = 3 # Only qualities - else: - priority = 4 # Do not order + # 0: Only Qualities + # 1: Servers and Qualities + # 2: Qualities and Servers + priority = 0 + if config.get_setting('favorites_servers') and favorite_servers: priority = 1 + if config.get_setting('quality_priority'): priority = 2 for item in servers_list: element = dict() @@ -728,24 +719,16 @@ def sort_servers(servers_list): if item.server.lower() in blacklisted_servers: continue - - # if priority < 2: # 0: Servers and qualities or 1: Qualities and servers element["index_server"] = index(favorite_servers, item.server.lower()) - element["index_quality"] = index(favorite_quality, item.quality.lower()) - - - + element["index_quality"] = platformtools.calcResolution(item.quality) element['index_language'] = 0 if item.contentLanguage == 'ITA' else 1 - element['videoitem'] = item sorted_list.append(element) # We order according to priority - if priority == 0: sorted_list.sort(key=lambda row: (row['index_language'], row['index_server'], row['index_quality'])) # Servers and Qualities - elif priority == 1: sorted_list.sort(key=lambda row: (row['index_language'], row['index_quality'], row['index_server'])) # Qualities and Servers - elif priority == 2: sorted_list.sort(key=lambda row: (row['index_language'], row['index_server'])) # Servers only - elif priority == 3: sorted_list.sort(key=lambda row: (row['index_language'], row['index_quality'])) # Only qualities - else: sorted_list.sort(key=lambda row: (row['index_language'], row['index_quality'])) + if priority == 0: sorted_list.sort(key=lambda element: (element['index_language'], -element['index_quality'] if inverted else element['index_quality'] , element['videoitem'].server)) + elif priority == 1: sorted_list.sort(key=lambda element: (element['index_language'], element['index_server'], -element['index_quality'] if inverted else element['index_quality'])) # Servers and Qualities + elif priority == 2: sorted_list.sort(key=lambda element: (element['index_language'], -element['index_quality'] if inverted else element['index_quality'], element['index_server'])) # Qualities and Servers return [v['videoitem'] for v in sorted_list if v] diff --git a/core/tmdb.py b/core/tmdb.py index 6813dca1..20d49618 100644 --- a/core/tmdb.py +++ b/core/tmdb.py @@ -1564,10 +1564,12 @@ class Tmdb(object): :rtype: list of Dict """ ret = [] + if self.result['id']: if self.result['videos']: self.result["videos"] = self.result["videos"]['results'] else: + self.result["videos"] = [] # First video search in the search language url = "{}/{}/{}/videos?api_key={}&language={}".format(host, self.search_type, self.result['id'], api, self.search_language) diff --git a/platformcode/platformtools.py b/platformcode/platformtools.py index 37e68a4e..bbfc34d6 100644 --- a/platformcode/platformtools.py +++ b/platformcode/platformtools.py @@ -1057,23 +1057,23 @@ def get_seleccion(default_action, opciones, seleccion, video_urls): def calcResolution(option): - match = scrapertools.find_single_match(option, '([0-9]{2,4})x([0-9]{2,4})') - resolution = False + match = scrapertools.find_single_match(option, '([0-9]{2,4})(?:p|i|x[0-9]{2,4}|)') + resolution = 0 + if match: - resolution = int(match[0]) * int(match[1]) - else: - if '240p' in option: - resolution = 320 * 240 - elif '360p' in option: - resolution = 480 * 360 - elif ('480p' in option) or ('480i' in option): - resolution = 720 * 480 - elif ('576p' in option) or ('576p' in option): - resolution = 720 * 576 - elif ('720p' in option) or ('HD' in option): - resolution = 1280 * 720 - elif ('1080p' in option) or ('1080i' in option) or ('Full HD' in option): - resolution = 1920 * 1080 + resolution = int(match) + elif 'sd' in option.lower(): + resolution = 480 + elif 'hd' in option.lower(): + resolution = 720 + if 'full' in option.lower(): + resolution = 1080 + elif '2k' in option.lower(): + resolution = 1440 + elif '4k' in option.lower(): + resolution = 2160 + elif 'auto' in option.lower(): + resolution = 10000 return resolution