From 29fa6ab0d09595ed3d43eddb76b56bbf277890c4 Mon Sep 17 00:00:00 2001 From: Ghost <62809003+Ghost6446@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:25:33 +0200 Subject: [PATCH] Fix resolution --- Src/Api/anime.py | 2 +- Src/Api/site.py | 8 ++++-- Src/Lib/FFmpeg/util/parser.py | 51 +++++++++++++++++++---------------- Src/Util/message.py | 15 ++++++++++- Src/Util/table.py | 7 ++--- run.py | 8 +++--- 6 files changed, 57 insertions(+), 34 deletions(-) diff --git a/Src/Api/anime.py b/Src/Api/anime.py index 6ce20e5..1c33276 100644 --- a/Src/Api/anime.py +++ b/Src/Api/anime.py @@ -149,7 +149,7 @@ class EpisodeDownloader: # Extract the ID of the selected episode episode_id = info_ep_select.get("id") - start_message() + start_message(True) console.print(f"[yellow]Download: [red]{episode_id} \n") # Get the embed URL for the episode diff --git a/Src/Api/site.py b/Src/Api/site.py index d61772e..81508b1 100644 --- a/Src/Api/site.py +++ b/Src/Api/site.py @@ -364,10 +364,14 @@ def anime_search(title_search: str) -> int: return media_search_manager.get_length() -def get_select_title() -> MediaItem: +def get_select_title(switch = False) -> MediaItem: """ Display a selection of titles and prompt the user to choose one. + Args: + - switch (bool): switch from film to anime + + Returns: MediaItem: The selected media item. """ @@ -396,7 +400,7 @@ def get_select_title() -> MediaItem: }) # Run the table and handle user input - last_command = table_show_manager.run(force_int_input=True, max_int_input=len(media_search_manager.media_list)) + last_command = table_show_manager.run(force_int_input=True, max_int_input=len(media_search_manager.media_list), switch=switch) # Handle user's quit command if last_command == "q": diff --git a/Src/Lib/FFmpeg/util/parser.py b/Src/Lib/FFmpeg/util/parser.py index 340064c..cc3fc78 100644 --- a/Src/Lib/FFmpeg/util/parser.py +++ b/Src/Lib/FFmpeg/util/parser.py @@ -37,6 +37,15 @@ CODEC_MAPPINGS = { } } +RESOLUTIONS = [ + (7680, 4320), + (3840, 2160), + (2560, 1440), + (1920, 1080), + (1280, 720), + (640, 480) + ] + def extract_resolution(uri: str) -> int: """ @@ -49,23 +58,13 @@ def extract_resolution(uri: str) -> int: - int: The video resolution if found, otherwise 0. """ - # Common video resolutions - resolutions = [ - 480, - 720, - 1080, - 2160, - 3840 - ] - - - for resolution in resolutions: - if str(resolution) in uri: + for resolution in RESOLUTIONS: + if str(resolution[1]) in uri: return resolution # Default resolution return (not best) - logging.error("No resolution find") - return 0 + logging.error("No resolution find with custom parsing.") + return -1 class M3U8_Codec(): @@ -233,17 +232,23 @@ class M3U8_Parser: try: for playlist in m3u8_obj.playlists: - # Try to access the 'resolution' key in playlist.stream_info + # Direct access resolutions in m3u8 obj try: - resolution = playlist.stream_info.get('resolution') - except: - # If the key 'resolution' does not exist, use extract_resolution - resolution = extract_resolution(playlist.uri) + self.video_playlist.append({ + "uri": playlist.uri, + "width": playlist.stream_info.get('resolution') + }) + + # Find resolutions in uri + except: + self.video_playlist.append({ + "uri": playlist.uri, + "width": extract_resolution(playlist.uri) + }) + + # Dont stop + continue - self.video_playlist.append({ - "uri": playlist.uri, - "width": resolution - }) # Check if all key is present to create codec if all(key in playlist.stream_info for key in ('bandwidth', 'resolution', 'codecs')): diff --git a/Src/Util/message.py b/Src/Util/message.py index be62d00..c794926 100644 --- a/Src/Util/message.py +++ b/Src/Util/message.py @@ -25,7 +25,7 @@ def get_os_system(): return os_system -def start_message(): +def start_message(switch = False): """ Display a start message. @@ -45,6 +45,18 @@ def start_message(): """ + if switch: + msg = """ + + _ _ _ _ + / \ _ __ (_)_ __ ___ ___ _ _ _ __ (_) |_ _ _ + / _ \ | '_ \| | '_ ` _ \ / _ \ | | | '_ \| | __| | | | + / ___ \| | | | | | | | | | __/ |_| | | | | | |_| |_| | + /_/ \_\_| |_|_|_| |_| |_|\___|\__,_|_| |_|_|\__|\__, | + |___/ + + """ + if CLEAN: if get_os_system() == 'Windows': os.system("cls") @@ -52,6 +64,7 @@ def start_message(): os.system("clear") if SHOW: + console.print(f"[bold yellow]{msg}") console.print(f"[magenta]Created by: Ghost6446\n") diff --git a/Src/Util/table.py b/Src/Util/table.py index a34a2db..9e16108 100644 --- a/Src/Util/table.py +++ b/Src/Util/table.py @@ -80,13 +80,14 @@ class TVShowManager: self.console.print(table) # Use self.console.print instead of print - def run(self, force_int_input: bool = False, max_int_input: int = 0) -> str: + def run(self, force_int_input: bool = False, max_int_input: int = 0, switch: bool = False) -> str: """ Run the TV show manager application. Args: - force_int_input(bool): If True, only accept integer inputs from 0 to max_int_input - - max_int_input (int): + - max_int_input (int): range of row to show + - switch (bool): switch from film to anime Returns: - str: Last command executed before breaking out of the loop. @@ -95,7 +96,7 @@ class TVShowManager: last_command = "" # Variable to store the last command executed while True: - start_message() + start_message(switch) # Display table self.display_data(self.tv_shows[self.slice_start:self.slice_end]) diff --git a/run.py b/run.py index c52d71c..4fe8e90 100644 --- a/run.py +++ b/run.py @@ -36,7 +36,7 @@ SWITCH_TO = config_manager.get_bool('DEFAULT', 'swith_anime') CLOSE_CONSOLE = config_manager.get_bool('DEFAULT', 'not_close') -def initialize(): +def initialize(switch = False): """ Initialize the application. Checks Python version, removes temporary folder, and displays start message. @@ -63,7 +63,7 @@ def initialize(): # Removing temporary folder remove_folder("tmp") remove_file("debug.log") - start_message() + start_message(switch) # Attempting GitHub update @@ -141,7 +141,7 @@ def main_anime(): """ # Get site domain and version - initialize() + initialize(True) # Make request to site to get content that corrsisponde to that string film_search = msg.ask("\n[cyan]Insert word to search in all site: ").strip() @@ -150,7 +150,7 @@ def main_anime(): if len_database != 0: # Select title from list - select_title = get_select_title() + select_title = get_select_title(True) # For series if select_title.type == 'TV':