mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-07-21 01:20:00 +00:00
Fix update bug and get domain.
This commit is contained in:
parent
eb95a4e5ac
commit
0ab1ab8798
@ -38,12 +38,12 @@ def title_search(title_search: str) -> int:
|
|||||||
|
|
||||||
# Find new domain if prev dont work
|
# Find new domain if prev dont work
|
||||||
max_timeout = config_manager.get_int("REQUESTS", "timeout")
|
max_timeout = config_manager.get_int("REQUESTS", "timeout")
|
||||||
#domain_to_use, _ = search_domain(SITE_NAME, f"https://{SITE_NAME}")
|
domain_to_use, _ = search_domain(SITE_NAME, f"https://{SITE_NAME}")
|
||||||
|
|
||||||
# Send request to search for title
|
# Send request to search for title
|
||||||
try:
|
try:
|
||||||
response = client.get(
|
response = client.get(
|
||||||
url=f"https://{SITE_NAME}.{DOMAIN_NOW}/?story={title_search.replace(' ', '+')}&do=search&subaction=search&titleonly=3",
|
url=f"https://{SITE_NAME}.{domain_to_use}/?story={title_search.replace(' ', '+')}&do=search&subaction=search&titleonly=3",
|
||||||
headers={
|
headers={
|
||||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
|
||||||
'accept-language': 'it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7',
|
'accept-language': 'it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7',
|
||||||
|
@ -69,7 +69,6 @@ def search_domain(site_name: str, base_url: str):
|
|||||||
Parameters:
|
Parameters:
|
||||||
- site_name (str): The name of the site to search the domain for.
|
- site_name (str): The name of the site to search the domain for.
|
||||||
- base_url (str): The base URL to construct complete URLs.
|
- base_url (str): The base URL to construct complete URLs.
|
||||||
- follow_redirects (bool): To follow redirect url or not.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
tuple: The found domain and the complete URL.
|
tuple: The found domain and the complete URL.
|
||||||
@ -80,47 +79,67 @@ def search_domain(site_name: str, base_url: str):
|
|||||||
domain = str(config_manager.get_dict("SITE", site_name)['domain'])
|
domain = str(config_manager.get_dict("SITE", site_name)['domain'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
# Test the current domain
|
# Test the current domain
|
||||||
response_follow = httpx.get(f"{base_url}.{domain}", headers={'user-agent': get_headers()}, timeout=max_timeout, follow_redirects=True)
|
with httpx.Client(
|
||||||
response_follow.raise_for_status()
|
headers={
|
||||||
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
|
||||||
|
'accept-language': 'it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7',
|
||||||
|
'User-Agent': get_headers()
|
||||||
|
},
|
||||||
|
follow_redirects=True,
|
||||||
|
timeout=max_timeout
|
||||||
|
) as client:
|
||||||
|
response_follow = client.get(f"{base_url}.{domain}")
|
||||||
|
response_follow.raise_for_status()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
query = base_url.split("/")[-1]
|
query = base_url.split("/")[-1]
|
||||||
first_url = google_search(query)
|
|
||||||
console.print(f"[green]First url from google seach[white]: [red]{first_url}")
|
# Perform a Google search with multiple results
|
||||||
|
search_results = list(search(query, num_results=5))
|
||||||
|
#console.print(f"[green]Google search results[white]: {search_results}")
|
||||||
|
|
||||||
if first_url:
|
# Iterate through search results
|
||||||
final_url = get_final_redirect_url(first_url, max_timeout)
|
for first_url in search_results:
|
||||||
|
console.print(f"[green]Checking url[white]: [red]{first_url}")
|
||||||
if final_url != None:
|
|
||||||
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:
|
# Check if the base URL matches the Google search result
|
||||||
console.print("[bold red]\nManually change the domain in the JSON file.[/bold red]")
|
parsed_first_url = urlparse(first_url)
|
||||||
raise
|
|
||||||
|
|
||||||
else:
|
# Compare base url from google search with base url from config.json
|
||||||
console.print("[bold red]No valid URL to follow redirects.[/bold red]")
|
if parsed_first_url.netloc.split(".")[0] == base_url:
|
||||||
|
console.print(f"[red]URL does not match base URL. Skipping.[/red]")
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
final_url = get_final_redirect_url(first_url, max_timeout)
|
||||||
|
|
||||||
|
if final_url is not None:
|
||||||
|
#console.print(f"\n[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"[cyan]\nDo you want to auto site[white]: [red]{site_name}[cyan] with domain[white]: [red]{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
|
||||||
|
return new_domain_extract, f"{base_url}.{new_domain_extract}"
|
||||||
|
|
||||||
|
except Exception as redirect_error:
|
||||||
|
console.print(f"[red]Error following redirect for {first_url}: {redirect_error}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# If no matching URL is found
|
||||||
|
console.print("[bold red]No valid URL found matching the base URL.[/bold red]")
|
||||||
|
raise Exception("No matching domain found")
|
||||||
|
|
||||||
# Ensure the URL is in string format before parsing
|
# Ensure the URL is in string format before parsing
|
||||||
parsed_url = urlparse(str(response_follow.url))
|
parsed_url = urlparse(str(response_follow.url))
|
||||||
@ -128,10 +147,9 @@ def search_domain(site_name: str, base_url: str):
|
|||||||
tld = parse_domain.split('.')[-1]
|
tld = parse_domain.split('.')[-1]
|
||||||
|
|
||||||
if tld is not None:
|
if tld is not None:
|
||||||
|
|
||||||
# Update domain in config.json
|
# Update domain in config.json
|
||||||
config_manager.config['SITE'][site_name]['domain'] = tld
|
config_manager.config['SITE'][site_name]['domain'] = tld
|
||||||
config_manager.write_config()
|
config_manager.write_config()
|
||||||
|
|
||||||
# Return config domain
|
# Return config domain
|
||||||
return tld, f"{base_url}.{tld}"
|
return tld, f"{base_url}.{tld}"
|
@ -56,7 +56,7 @@ def update():
|
|||||||
percentual_stars = 0
|
percentual_stars = 0
|
||||||
|
|
||||||
# Check installed version
|
# Check installed version
|
||||||
if __version__ != last_version:
|
if str(__version__).replace('v', '') != str(last_version).replace('v', '') :
|
||||||
console.print(f"[red]New version available: [yellow]{last_version}")
|
console.print(f"[red]New version available: [yellow]{last_version}")
|
||||||
else:
|
else:
|
||||||
console.print(f"[red]Everything is up to date")
|
console.print(f"[red]Everything is up to date")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user