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
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()})

View File

@ -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)
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()

View File

@ -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"
}