From 0f7f09fe3ad6fed51f95691e301a38403d66ce38 Mon Sep 17 00:00:00 2001 From: Alessandro Perazzetta <482310+AlessandroPerazzetta@users.noreply.github.com> Date: Wed, 21 May 2025 22:33:15 +0200 Subject: [PATCH 1/4] refactor: streamline proxy checking in search function --- .../Api/Site/streamingcommunity/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/StreamingCommunity/Api/Site/streamingcommunity/__init__.py b/StreamingCommunity/Api/Site/streamingcommunity/__init__.py index a1b98d0..bff8654 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/__init__.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/__init__.py @@ -121,14 +121,16 @@ def search(string_to_search: str = None, get_onlyDatabase: bool = False, direct_ if site_constant.TELEGRAM_BOT: bot = get_bot_instance() + # Check proxy if not already set + finder = ProxyFinder(site_constant.FULL_URL) + proxy = finder.find_fast_proxy() + if direct_item: select_title_obj = MediaItem(**direct_item) process_search_result(select_title_obj, selections, proxy) return - # Check proxy if not already set - finder = ProxyFinder(site_constant.FULL_URL) - proxy = finder.find_fast_proxy() + actual_search_query = get_user_input(string_to_search) From afa83a1665a47506172d8c27922d19dd8a74991c Mon Sep 17 00:00:00 2001 From: Alessandro Perazzetta <482310+AlessandroPerazzetta@users.noreply.github.com> Date: Thu, 22 May 2025 11:57:41 +0200 Subject: [PATCH 2/4] refactor: update DNS check method, try a real dns resolution instead of checking dns provider --- StreamingCommunity/Util/os.py | 73 +++++++++++++++++++++-------------- StreamingCommunity/run.py | 17 ++++++-- 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/StreamingCommunity/Util/os.py b/StreamingCommunity/Util/os.py index 8da5de1..87e8249 100644 --- a/StreamingCommunity/Util/os.py +++ b/StreamingCommunity/Util/os.py @@ -283,44 +283,59 @@ class InternManager(): else: return f"{bytes / (1024 * 1024):.2f} MB/s" - def check_dns_provider(self): + # def check_dns_provider(self): + # """ + # Check if the system's current DNS server matches any known DNS providers. + + # Returns: + # bool: True if the current DNS server matches a known provider, + # False if no match is found or in case of errors + # """ + # dns_providers = { + # "Cloudflare": ["1.1.1.1", "1.0.0.1"], + # "Google": ["8.8.8.8", "8.8.4.4"], + # "OpenDNS": ["208.67.222.222", "208.67.220.220"], + # "Quad9": ["9.9.9.9", "149.112.112.112"], + # "AdGuard": ["94.140.14.14", "94.140.15.15"], + # "Comodo": ["8.26.56.26", "8.20.247.20"], + # "Level3": ["209.244.0.3", "209.244.0.4"], + # "Norton": ["199.85.126.10", "199.85.127.10"], + # "CleanBrowsing": ["185.228.168.9", "185.228.169.9"], + # "Yandex": ["77.88.8.8", "77.88.8.1"] + # } + + # try: + # resolver = dns.resolver.Resolver() + # nameservers = resolver.nameservers + + # if not nameservers: + # return False + + # for server in nameservers: + # for provider, ips in dns_providers.items(): + # if server in ips: + # return True + # return False + + # except Exception: + # return False + + def check_dns_resolve(self): """ - Check if the system's current DNS server matches any known DNS providers. + Check if the system's current DNS server can resolve a domain name. Returns: - bool: True if the current DNS server matches a known provider, - False if no match is found or in case of errors + bool: True if the current DNS server can resolve a domain name, + False if can't resolve or in case of errors """ - dns_providers = { - "Cloudflare": ["1.1.1.1", "1.0.0.1"], - "Google": ["8.8.8.8", "8.8.4.4"], - "OpenDNS": ["208.67.222.222", "208.67.220.220"], - "Quad9": ["9.9.9.9", "149.112.112.112"], - "AdGuard": ["94.140.14.14", "94.140.15.15"], - "Comodo": ["8.26.56.26", "8.20.247.20"], - "Level3": ["209.244.0.3", "209.244.0.4"], - "Norton": ["199.85.126.10", "199.85.127.10"], - "CleanBrowsing": ["185.228.168.9", "185.228.169.9"], - "Yandex": ["77.88.8.8", "77.88.8.1"] - } - try: resolver = dns.resolver.Resolver() - nameservers = resolver.nameservers - - if not nameservers: - return False - - for server in nameservers: - for provider, ips in dns_providers.items(): - if server in ips: - return True - return False - + # Simple DNS resolution test - will raise an exception if it fails + resolver.resolve("github.com") + return True except Exception: return False - class OsSummary: def __init__(self): self.ffmpeg_path = None diff --git a/StreamingCommunity/run.py b/StreamingCommunity/run.py index e37bd74..2db8a86 100644 --- a/StreamingCommunity/run.py +++ b/StreamingCommunity/run.py @@ -210,7 +210,19 @@ def main(script_id = 0): log_not = Logger() initialize() - if not internet_manager.check_dns_provider(): + # if not internet_manager.check_dns_provider(): + # print() + # console.print("[red]❌ ERROR: DNS configuration is required!") + # console.print("[red]The program cannot function correctly without proper DNS settings.") + # console.print("[yellow]Please configure one of these DNS servers:") + # console.print("[blue]• Cloudflare (1.1.1.1) 'https://developers.cloudflare.com/1.1.1.1/setup/windows/'") + # console.print("[blue]• Quad9 (9.9.9.9) 'https://docs.quad9.net/Setup_Guides/Windows/Windows_10/'") + # console.print("\n[yellow]⚠️ The program will not work until you configure your DNS settings.") + + # time.sleep(2) + # msg.ask("[yellow]Press Enter to continue ...") + + if not internet_manager.check_dns_resolve(): print() console.print("[red]❌ ERROR: DNS configuration is required!") console.print("[red]The program cannot function correctly without proper DNS settings.") @@ -219,8 +231,7 @@ def main(script_id = 0): console.print("[blue]• Quad9 (9.9.9.9) 'https://docs.quad9.net/Setup_Guides/Windows/Windows_10/'") console.print("\n[yellow]⚠️ The program will not work until you configure your DNS settings.") - time.sleep(2) - msg.ask("[yellow]Press Enter to continue ...") + os._exit(0) # Load search functions search_functions = load_search_functions() From e667d970e9a73fcc89f7a7cee03d668810f65cb3 Mon Sep 17 00:00:00 2001 From: Alessandro Perazzetta <482310+AlessandroPerazzetta@users.noreply.github.com> Date: Fri, 23 May 2025 12:24:51 +0200 Subject: [PATCH 3/4] refactor: update config handling in ConfigManager (removed globals and add parsing of file_name ) and run script for better flexibility, enable config argument to load custom config and reinitialize config_manager. --- StreamingCommunity/Util/config_json.py | 31 +++++++++++-------- StreamingCommunity/run.py | 42 ++++++++++++++++++-------- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/StreamingCommunity/Util/config_json.py b/StreamingCommunity/Util/config_json.py index bea1edc..60b70f5 100644 --- a/StreamingCommunity/Util/config_json.py +++ b/StreamingCommunity/Util/config_json.py @@ -30,20 +30,27 @@ class ConfigManager: Args: file_name (str, optional): Configuration file name. Default: 'config.json'. """ - # Determine the base path - use the current working directory - if getattr(sys, 'frozen', False): - # If the application is frozen (e.g., PyInstaller) - base_path = os.path.dirname(sys.executable) - else: - - # Get the actual path of the module file - current_file_path = os.path.abspath(__file__) - # Navigate upwards to find the project root - # Assuming this file is in a package structure like StreamingCommunity/Util/config_json.py - # We need to go up 2 levels to reach the project root - base_path = os.path.dirname(os.path.dirname(os.path.dirname(current_file_path))) + # Check if the file name is a full path or just a file name + if os.path.basename(file_name) == file_name: + # Determine the base path - use the current working directory + if getattr(sys, 'frozen', False): + # If the application is frozen (e.g., PyInstaller) + base_path = os.path.dirname(sys.executable) + + else: + # Get the actual path of the module file + current_file_path = os.path.abspath(__file__) + # Navigate upwards to find the project root + # Assuming this file is in a package structure like StreamingCommunity/Util/config_json.py + # We need to go up 2 levels to reach the project root + base_path = os.path.dirname(os.path.dirname(os.path.dirname(current_file_path))) + + else: + base_path = os.path.dirname(os.path.abspath(file_name)) + file_name = os.path.basename(file_name) + # Initialize file paths self.file_path = os.path.join(base_path, file_name) self.domains_path = os.path.join(base_path, 'domains.json') diff --git a/StreamingCommunity/run.py b/StreamingCommunity/run.py index 2db8a86..0cd0243 100644 --- a/StreamingCommunity/run.py +++ b/StreamingCommunity/run.py @@ -29,9 +29,9 @@ from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance, Teleg # Config -SHOW_TRENDING = config_manager.get_bool('DEFAULT', 'show_trending') -NOT_CLOSE_CONSOLE = config_manager.get_bool('DEFAULT', 'not_close') -TELEGRAM_BOT = config_manager.get_bool('DEFAULT', 'telegram_bot') +# SHOW_TRENDING = config_manager.get_bool('DEFAULT', 'show_trending') +# NOT_CLOSE_CONSOLE = config_manager.get_bool('DEFAULT', 'not_close') +# TELEGRAM_BOT = config_manager.get_bool('DEFAULT', 'telegram_bot') # Variable @@ -61,7 +61,7 @@ def load_search_functions(): loaded_functions = {} # Lista dei siti da escludere se TELEGRAM_BOT è attivo - excluded_sites = {"cb01new", "guardaserie", "ilcorsaronero", "mostraguarda"} if TELEGRAM_BOT else set() + excluded_sites = {"cb01new", "guardaserie", "ilcorsaronero", "mostraguarda"} if config_manager.get_bool('DEFAULT', 'telegram_bot') else set() # Find api home directory if getattr(sys, 'frozen', False): # Modalità PyInstaller @@ -142,7 +142,8 @@ def initialize(): sys.exit(0) # Trending tmbd - if SHOW_TRENDING: + # SHOW_TRENDING + if config_manager.get_bool('DEFAULT', 'show_trending'): print() tmdb.display_trending_films() tmdb.display_trending_tv_shows() @@ -200,10 +201,6 @@ def main(script_id = 0): "torrent": "white" } - if TELEGRAM_BOT: - bot = get_bot_instance() - bot.send_message(f"Avviato script {script_id}", None) - start = time.time() # Create logger @@ -244,6 +241,11 @@ def main(script_id = 0): parser.add_argument("script_id", nargs="?", default="unknown", help="ID dello script") + # Add arguments for the custom config file + parser.add_argument( + '--config', type=str, help='Load custom config file name (e.g., custom_config.json).' + ) + # Add arguments for the main configuration parameters parser.add_argument( '--add_siteName', type=bool, help='Enable or disable adding the site name to the file name (e.g., true/false).' @@ -279,6 +281,16 @@ def main(script_id = 0): # Parse command-line arguments args = parser.parse_args() + # If custom config file is specified, update config_manager + if args.config: + config_manager.__init__(args.config) + + # TELEGRAM_BOT: + if config_manager.get_bool('DEFAULT', 'telegram_bot'): + bot = get_bot_instance() + bot.send_message(f"Avviato script {script_id}", None) + + search_terms = args.search # Map command-line arguments to the config values config_updates = {} @@ -332,7 +344,8 @@ def main(script_id = 0): for key, label in choice_labels.items()] ) + "[white])" - if TELEGRAM_BOT: + # TELEGRAM_BOT + if config_manager.get_bool('DEFAULT', 'telegram_bot'): category_legend_str = "Categorie: \n" + " | ".join([ f"{category.capitalize()}" for category in color_map.keys() ]) @@ -357,18 +370,21 @@ def main(script_id = 0): run_function(input_to_function[category], search_terms=search_terms) else: - if TELEGRAM_BOT: + # TELEGRAM_BOT + if config_manager.get_bool('DEFAULT', 'telegram_bot'): bot.send_message(f"Categoria non valida", None) console.print("[red]Invalid category.") - if NOT_CLOSE_CONSOLE: + # NOT_CLOSE_CONSOLE + if config_manager.get_bool('DEFAULT', 'not_close'): restart_script() else: force_exit() - if TELEGRAM_BOT: + # TELEGRAM_BOT + if config_manager.get_bool('DEFAULT', 'telegram_bot'): bot.send_message(f"Chiusura in corso", None) # Delete script_id From 66b54c348212d7e879f198ad3fb198f752499493 Mon Sep 17 00:00:00 2001 From: Alessandro Perazzetta <482310+AlessandroPerazzetta@users.noreply.github.com> Date: Sun, 1 Jun 2025 13:59:46 +0200 Subject: [PATCH 4/4] Fix merge conflict from previous branch --- StreamingCommunity/Util/os.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/StreamingCommunity/Util/os.py b/StreamingCommunity/Util/os.py index 81acd79..2d8f7d1 100644 --- a/StreamingCommunity/Util/os.py +++ b/StreamingCommunity/Util/os.py @@ -323,23 +323,12 @@ class InternManager(): def check_dns_resolve(self): """ Check if the system's current DNS server can resolve a domain name. -<<<<<<< HEAD -======= Works on both Windows and Unix-like systems. ->>>>>>> b8e28a30c0a58ff74e7fbfab03cf03810421cd90 Returns: bool: True if the current DNS server can resolve a domain name, False if can't resolve or in case of errors """ -<<<<<<< HEAD - try: - resolver = dns.resolver.Resolver() - # Simple DNS resolution test - will raise an exception if it fails - resolver.resolve("github.com") - return True - except Exception: -======= test_domains = ["github.com", "google.com", "microsoft.com", "amazon.com"] try: @@ -348,7 +337,6 @@ class InternManager(): socket.gethostbyname(domain) return True except (socket.gaierror, socket.error): ->>>>>>> b8e28a30c0a58ff74e7fbfab03cf03810421cd90 return False class OsSummary: