Add domain to config #78

This commit is contained in:
Ghost 2024-03-19 17:57:33 +01:00
parent b7760bd3ce
commit f1ed9cf664
3 changed files with 48 additions and 20 deletions

View File

@ -3,6 +3,7 @@
# Class import # Class import
from Src.Util.headers import get_headers from Src.Util.headers import get_headers
from Src.Util.console import console from Src.Util.console import console
from Src.Util.config import config, config_manager
# General import # General import
import requests, sys, json import requests, sys, json
@ -10,12 +11,26 @@ from bs4 import BeautifulSoup
def domain_version(): def domain_version():
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_req = requests.get("https://api.telegra.ph/getPage/Link-Aggiornato-StreamingCommunity-01-17")
domain = domain_req.json()['result']['description'].split(".")[1] domain = domain_req.json()['result']['description'].split(".")[1]
console.print("[green]Getting rules...") console.print("[green]Getting rules...")
console.print(f"[blue]Test domain [white]=> [red]{domain}") console.print(f"[blue]Test domain [white]=> [red]{domain}")
config_manager.update_config('domain', domain)
if domain != None:
site_url = f"https://streamingcommunity.{domain}" site_url = f"https://streamingcommunity.{domain}"
console.print(f"[blue]Use domain [white]=> [red]{domain}")
else:
domain = config['domain']
try: try:
site_request = requests.get(site_url, headers={'user-agent': get_headers()}) site_request = requests.get(site_url, headers={'user-agent': get_headers()})
@ -26,10 +41,9 @@ def domain_version():
return domain, version return domain, version
except Exception as e: 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) sys.exit(0)
def search(title_search, domain): def search(title_search, domain):
req = requests.get(f"https://streamingcommunity.{domain}/api/search?q={title_search}", headers={'user-agent': get_headers()}) req = requests.get(f"https://streamingcommunity.{domain}/api/search?q={title_search}", headers={'user-agent': get_headers()})

View File

@ -1,10 +1,23 @@
import json import json
from pathlib import Path from pathlib import Path
def load_config(file_path): class ConfigManager:
with open(file_path, 'r') as file: def __init__(self, file_path):
self.file_path = file_path
def load_config(self):
with open(self.file_path, 'r') as file:
config_file = json.load(file) config_file = json.load(file)
return config_file return config_file
config_path = Path(__file__).parent.parent.parent / 'config.json' # path for config.json (in root directory) def update_config(self, key, new_value):
config = load_config(config_path) 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()

View File

@ -5,5 +5,6 @@
"download_subtitles": true, "download_subtitles": true,
"download_default_language": true, "download_default_language": true,
"selected_language": "English", "selected_language": "English",
"max_worker": 20 "max_worker": 20,
"domain": "forum"
} }