diff --git a/Src/Api/page.py b/Src/Api/page.py index 3ff0f95..09b29d5 100644 --- a/Src/Api/page.py +++ b/Src/Api/page.py @@ -3,6 +3,7 @@ # Class import from Src.Util.headers import get_headers from Src.Util.console import console +from Src.Util.config import config, config_manager # General import import requests, sys, json @@ -10,12 +11,26 @@ from bs4 import BeautifulSoup def domain_version(): - domain_req = requests.get("https://api.telegra.ph/getPage/Link-Aggiornato-StreamingCommunity-01-17") - domain = domain_req.json()['result']['description'].split(".")[1] - console.print("[green]Getting rules...") - console.print(f"[blue]Test domain [white]=> [red]{domain}") - site_url = f"https://streamingcommunity.{domain}" + site_url = f"https://streamingcommunity.{config['domain']}" + domain = None + + try: + requests.get(site_url, headers={'user-agent': get_headers()}) + except: + + domain_req = requests.get("https://api.telegra.ph/getPage/Link-Aggiornato-StreamingCommunity-01-17") + domain = domain_req.json()['result']['description'].split(".")[1] + console.print("[green]Getting rules...") + + console.print(f"[blue]Test domain [white]=> [red]{domain}") + config_manager.update_config('domain', domain) + + if domain != None: + site_url = f"https://streamingcommunity.{domain}" + console.print(f"[blue]Use domain [white]=> [red]{domain}") + else: + domain = config['domain'] try: site_request = requests.get(site_url, headers={'user-agent': get_headers()}) @@ -26,10 +41,9 @@ def domain_version(): return domain, version except Exception as e: - console.log("[red]Couldn't get the version, there's a problem with the domain. Try again.") + console.log("[red]Couldn't get the version, there's a problem with the domain. Try again." , e) sys.exit(0) - def search(title_search, domain): req = requests.get(f"https://streamingcommunity.{domain}/api/search?q={title_search}", headers={'user-agent': get_headers()}) diff --git a/Src/Util/config.py b/Src/Util/config.py index 1280b8c..4963f99 100644 --- a/Src/Util/config.py +++ b/Src/Util/config.py @@ -1,10 +1,23 @@ import json from pathlib import Path -def load_config(file_path): - with open(file_path, 'r') as file: - config_file = json.load(file) - return config_file +class ConfigManager: + def __init__(self, file_path): + self.file_path = file_path -config_path = Path(__file__).parent.parent.parent / 'config.json' # path for config.json (in root directory) -config = load_config(config_path) \ No newline at end of file + def load_config(self): + with open(self.file_path, 'r') as file: + config_file = json.load(file) + return config_file + + def update_config(self, key, new_value): + config = self.load_config() + config[key] = new_value + with open(self.file_path, 'w') as file: + json.dump(config, file, indent=4) + + +# Example usage: +config_path = Path(__file__).parent.parent.parent / 'config.json' +config_manager = ConfigManager(config_path) +config = config_manager.load_config() diff --git a/config.json b/config.json index 095db6f..6e93a61 100644 --- a/config.json +++ b/config.json @@ -1,9 +1,10 @@ { - "root_path": "videos", - "movies_folder_name": "Movies", - "series_folder_name": "Series", - "download_subtitles": true, - "download_default_language": true, - "selected_language": "English", - "max_worker": 20 + "root_path": "videos", + "movies_folder_name": "Movies", + "series_folder_name": "Series", + "download_subtitles": true, + "download_default_language": true, + "selected_language": "English", + "max_worker": 20, + "domain": "forum" } \ No newline at end of file