From b5dc790ec9b6c45ed87b32818279e02218f4a3ec Mon Sep 17 00:00:00 2001 From: Lovi <62809003+Lovi-0@users.noreply.github.com> Date: Thu, 3 Oct 2024 15:01:00 +0200 Subject: [PATCH] Auto update domain --- Src/Api/Template/Util/get_domain.py | 27 ++++++++++++++++++++++++--- config.json | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Src/Api/Template/Util/get_domain.py b/Src/Api/Template/Util/get_domain.py index 4e85fbf..4f0bdf2 100644 --- a/Src/Api/Template/Util/get_domain.py +++ b/Src/Api/Template/Util/get_domain.py @@ -11,7 +11,7 @@ from googlesearch import search # Internal utilities from Src.Util.headers import get_headers -from Src.Util.console import console +from Src.Util.console import console, msg from Src.Util._jsonConfig import config_manager @@ -90,10 +90,31 @@ def search_domain(site_name: str, base_url: str): final_url = get_final_redirect_url(first_url) console.print(f"\n[bold yellow]Suggestion:[/bold yellow] [white](Experimental)\n" f"[cyan]New final URL[white]: [green]{final_url}") + + def extract_domain(url): + parsed_url = urlparse(url) + domain = parsed_url.netloc + return domain.split(".")[-1] + + new_domain_extract = extract_domain(str(final_url)) + + if msg.ask(f"[red]Do you want to auto update config.json - '[green]{site_name}[red]' with domain: [green]{new_domain_extract}", choices=["y", "n"], default="y").lower() == "y": + + # Update domain in config.json + config_manager.config['SITE'][site_name]['domain'] = new_domain_extract + config_manager.write_config() + + # Return config domain + console.print(f"[cyan]Return domain: [red]{new_domain_extract} \n") + return new_domain_extract, f"{base_url}.{new_domain_extract}" + + else: + console.print("[bold red]\nManually change the domain in the JSON file.[/bold red]") + sys.exit(0) + else: console.print("[bold red]No valid URL to follow redirects.[/bold red]") - - sys.exit(0) + sys.exit(0) # Ensure the URL is in string format before parsing parsed_url = urlparse(str(response_follow.url)) diff --git a/config.json b/config.json index ec0eb5e..42ffd64 100644 --- a/config.json +++ b/config.json @@ -60,7 +60,7 @@ "streamingcommunity": { "video_workers": 6, "audio_workers": 6, - "domain": "buzz" + "domain": "computer" }, "animeunity": { "domain": "to"