diff --git a/README.md b/README.md index 4c9afd4..24638be 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ # 📋 Table of Contents -- 🌐 [Website available](https://www.npoint.io/docs/e67633acc3816cc70132) - 🔄 [Update Domains](#update-domains) - 🛠️ [Installation](#installation) - 📦 [PyPI Installation](#1-pypi-installation) @@ -448,32 +447,39 @@ You can download VLC Media Player from the [official website](https://www.videol - `get_only_link`: Return M3U8 playlist/index URL instead of downloading -## 🔄 Update Domains +## Update Domains -To update the domains for the supported websites: +There are two ways to update the domains for the supported websites: -1. Visit the configuration endpoint: https://www.npoint.io/docs/e67633acc3816cc70132 +### 1. Using Local Configuration -2. You'll find a JSON structure similar to: +1. Create a `domains.json` file in the root directory of the project + +2. Add your domain configuration in the following format: ```json { "altadefinizione": { "domain": "si", "full_url": "https://altadefinizione.si/" - }, + }, ... } ``` + +3. Set `use_api` to `false` in the `DEFAULT` section of your `config.json`: + ```json + { + "DEFAULT": { + "use_api": false + } + } + ``` -3. Update the following fields for each website as needed: - - `domain`: The new domain extension - - `full_url`: The complete URL including the new domain +### 2. Using API (Legacy) -4. Save your changes on the npoint.io interface +The API-based domain updates are currently deprecated. To use it anyway, set `use_api` to `true` in your `config.json` file. -5. Re-run the script to use the updated domain information - -Note: The script will automatically fetch the latest domain information from the configuration endpoint when executed. +Note: If `use_api` is set to `false` and no `domains.json` file is found, the script will raise an error. # COMMAND diff --git a/StreamingCommunity/Util/_jsonConfig.py b/StreamingCommunity/Util/_jsonConfig.py index 591f5b5..f2ecf25 100644 --- a/StreamingCommunity/Util/_jsonConfig.py +++ b/StreamingCommunity/Util/_jsonConfig.py @@ -28,11 +28,30 @@ class ConfigManager: else: base_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) self.file_path = os.path.join(base_path, file_name) + self.domains_path = os.path.join(base_path, 'domains.json') self.config = {} self.configSite = {} self.cache = {} - + + # Read initial config to get use_api setting + self._read_initial_config() + console.print(f"[bold cyan]📂 Configuration file path:[/bold cyan] [green]{self.file_path}[/green]") + + def _read_initial_config(self) -> None: + """Read initial configuration to get use_api setting.""" + try: + if os.path.exists(self.file_path): + with open(self.file_path, 'r') as f: + self.config = json.load(f) + self.use_api = self.config.get('DEFAULT', {}).get('use_api', True) + else: + self.use_api = True # Default to True if config file doesn't exist + console.print("[bold yellow]⚠️ Configuration file not found. Using default settings.[/bold yellow]") + + except Exception as e: + self.use_api = True # Default to True in case of error + logging.error(f"❌ Error reading initial configuration: {e}") def read_config(self) -> None: """Read the configuration file.""" @@ -91,20 +110,41 @@ class ConfigManager: sys.exit(0) def update_site_config(self) -> None: - """Fetch and update the site configuration with data from the API.""" - api_url = "https://api.npoint.io/e67633acc3816cc70132" - try: - console.print("[bold cyan]🌍 Fetching SITE data from API...[/bold cyan]") - response = requests.get(api_url) + """Fetch and update the site configuration with data from the API or local file.""" + if self.use_api: + headers = { + "apikey": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inp2Zm5ncG94d3Jnc3duenl0YWRoIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDAxNTIxNjMsImV4cCI6MjA1NTcyODE2M30.FNTCCMwi0QaKjOu8gtZsT5yQttUW8QiDDGXmzkn89QE", + "Authorization": f"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inp2Zm5ncG94d3Jnc3duenl0YWRoIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDAxNTIxNjMsImV4cCI6MjA1NTcyODE2M30.FNTCCMwi0QaKjOu8gtZsT5yQttUW8QiDDGXmzkn89QE", + "Content-Type": "application/json" + } - if response.status_code == 200: - self.configSite = response.json() # Store API data in separate configSite - console.print("[bold green]✅ SITE data successfully fetched.[/bold green]") - else: - console.print(f"[bold red]❌ Failed to fetch SITE data. HTTP Status code: {response.status_code}[/bold red]") + try: + console.print("[bold cyan]🌍 Fetching SITE data from API...[/bold cyan]") + response = requests.get("https://zvfngpoxwrgswnzytadh.supabase.co/rest/v1/public", headers=headers) - except Exception as e: - console.print(f"[bold red]❌ Error fetching SITE data: {e}[/bold red]") + if response.status_code == 200: + self.configSite = response.json()[0]['data'] + console.print("[bold green]✅ SITE data successfully fetched.[/bold green]") + else: + console.print(f"[bold red]❌ Failed to fetch SITE data. HTTP Status code: {response.status_code}[/bold red]") + + except Exception as e: + console.print(f"[bold red]❌ Error fetching SITE data: {e}[/bold red]") + else: + try: + if os.path.exists(self.domains_path): + console.print("[bold cyan]📖 Reading domains from local file...[/bold cyan]") + with open(self.domains_path, 'r') as f: + self.configSite = json.load(f) + console.print("[bold green]✅ Domains loaded successfully from local file.[/bold green]") + else: + error_msg = "❌ domains.json not found and API usage is disabled" + console.print(f"[bold red]{error_msg}[/bold red]") + raise FileNotFoundError(error_msg) + + except Exception as e: + console.print(f"[bold red]❌ Error reading domains file: {e}[/bold red]") + raise def read_key(self, section: str, key: str, data_type: type = str, from_site: bool = False) -> Any: """Read a key from the configuration. diff --git a/config.json b/config.json index b0412b7..76cd172 100644 --- a/config.json +++ b/config.json @@ -17,6 +17,7 @@ "user": "admin", "pass": "adminadmin" }, + "use_api": true, "add_siteName": false, "disable_searchDomain": false, "not_close": false,