Update get_domain

This commit is contained in:
Lovi 2025-01-06 18:50:24 +01:00
parent 0dac3f55d8
commit d929a79941
5 changed files with 69 additions and 70 deletions

View File

@ -2,7 +2,7 @@ name: Update domain
on: on:
schedule: schedule:
- cron: '0 */8 * * *' - cron: '0 */6 * * *'
workflow_dispatch: workflow_dispatch:
jobs: jobs:

View File

@ -406,7 +406,7 @@ The `run-container` command mounts also the `config.json` file, so any change to
| [Ilcorsaronero](https://ilcorsaronero.link/) | ✅ | | [Ilcorsaronero](https://ilcorsaronero.link/) | ✅ |
| [CB01New](https://cb01new.quest/) | ✅ | | [CB01New](https://cb01new.quest/) | ✅ |
| [DDLStreamItaly](https://ddlstreamitaly.co/) | ✅ | | [DDLStreamItaly](https://ddlstreamitaly.co/) | ✅ |
| [GuardaSerie](https://guardaserie.help/) | ✅ | | [GuardaSerie](https://guardaserie.academy/) | ✅ |
| [MostraGuarda](https://mostraguarda.stream/) | ✅ | | [MostraGuarda](https://mostraguarda.stream/) | ✅ |
| [StreamingCommunity](https://streamingcommunity.prof/) | ✅ | | [StreamingCommunity](https://streamingcommunity.prof/) | ✅ |

View File

@ -37,9 +37,9 @@ def get_base_domain(url_str):
domain = domain[4:] domain = domain[4:]
return domain.split('.')[0] return domain.split('.')[0]
def validate_url(url, base_url, max_timeout): def validate_url(url, base_url, max_timeout, max_retries=5):
""" """
Validate if URL is accessible and matches expected base domain Validate if URL is accessible and matches expected base domain, with retry mechanism for 403 errors.
""" """
console.print(f"\n[cyan]Starting validation for URL[white]: [yellow]{url}") console.print(f"\n[cyan]Starting validation for URL[white]: [yellow]{url}")
@ -53,55 +53,63 @@ def validate_url(url, base_url, max_timeout):
console.print(f"[green]Check {check_num} passed: HTTP {response.status_code}") console.print(f"[green]Check {check_num} passed: HTTP {response.status_code}")
return True return True
try: retries = 0
# Check 1: Initial request without following redirects while retries < max_retries:
console.print("[cyan]Performing initial connection check...") try:
with httpx.Client( # Check 1: Initial request without following redirects
headers={'User-Agent': get_headers()}, #console.print("[cyan]Performing initial connection check...")
follow_redirects=False, with httpx.Client(
timeout=max_timeout headers={'User-Agent': get_headers()},
) as client: follow_redirects=False,
response = client.get(url) timeout=max_timeout
if not check_response(response, 1): ) as client:
return False, None response = client.get(url)
if not check_response(response, 1):
if response.status_code == 403:
retries += 1
console.print(f"[yellow]Retrying... Attempt {retries}/{max_retries}")
continue # Retry on 403 error
return False, None
# Check 2: Follow redirects and verify final domain # Check 2: Follow redirects and verify final domain
console.print("[cyan]Checking redirect destination...") #console.print("[cyan]Checking redirect destination...")
with httpx.Client( with httpx.Client(
headers={'User-Agent': get_headers()}, headers={'User-Agent': get_headers()},
follow_redirects=True, follow_redirects=True,
timeout=max_timeout timeout=max_timeout
) as client: ) as client:
response = client.get(url)
if not check_response(response, 2):
return False, None
response = client.get(url) # Compare base domains
if not check_response(response, 2): original_base = get_base_domain(url)
return False, None final_base = get_base_domain(str(response.url))
# Compare base domains """console.print(f"[cyan]Comparing domains:")
original_base = get_base_domain(url) console.print(f"Original base domain: [yellow]{original_base}.{get_tld(str(url))}")
final_base = get_base_domain(str(response.url)) console.print(f"Final base domain: [yellow]{final_base}.{get_tld(str(response.url))}")"""
console.print(f"[cyan]Comparing domains:") if original_base != final_base:
console.print(f"Original base domain: [yellow]{original_base}.{get_tld(str(url))}") return False, None
console.print(f"Final base domain: [yellow]{final_base}.{get_tld(str(response.url))}")
if original_base != final_base: expected_base = get_base_domain(base_url)
return False, None if final_base != expected_base:
return False, None
expected_base = get_base_domain(base_url) if get_tld(str(url)) != get_tld(str(response.url)):
if final_base != expected_base: return True, get_tld(str(response.url))
return False, None
if get_tld(str(url)) != get_tld(str(response.url)): #console.print(f"[green]All checks passed: URL is valid and matches expected domain")
return True, get_tld(str(response.url)) return True, None
console.print(f"[green]All checks passed: URL is valid and matches expected domain") except Exception as e:
return True, None console.print(f"[red]Error during validation: {str(e)}")
return False, None
except Exception as e: console.print(f"[red]Maximum retries reached for URL: {url}")
console.print(f"[red]Error during validation: {str(e)}") return False, None
return False, None
def search_domain(site_name: str, base_url: str, get_first: bool = False): def search_domain(site_name: str, base_url: str, get_first: bool = False):
""" """
@ -111,10 +119,8 @@ def search_domain(site_name: str, base_url: str, get_first: bool = False):
domain = str(config_manager.get_dict("SITE", site_name)['domain']) domain = str(config_manager.get_dict("SITE", site_name)['domain'])
test_url = f"{base_url}.{domain}" test_url = f"{base_url}.{domain}"
console.print(f"\n[cyan]Testing initial URL[white]: [yellow]{test_url}")
try: try:
is_correct, redirect_tld = validate_url(test_url, base_url, max_timeout) is_correct, redirect_tld = validate_url(test_url, base_url, max_timeout, max_retries=5)
if is_correct and redirect_tld is not None: if is_correct and redirect_tld is not None:
config_manager.config['SITE'][site_name]['domain'] = redirect_tld config_manager.config['SITE'][site_name]['domain'] = redirect_tld

View File

@ -97,14 +97,12 @@ def update_readme(site_names, domain_to_use):
alias = f"{site_name.lower()}" alias = f"{site_name.lower()}"
if alias in site_names: if alias in site_names:
print("Update line: ", line)
if site_name == "animeunity": if site_name == "animeunity":
updated_line = f"| [{site_name}](https://www.{alias}.{domain_to_use}/) | ✅ |\n" updated_line = f"| [{site_name}](https://www.{alias}.{domain_to_use}/) | ✅ |\n"
else: else:
updated_line = f"| [{site_name}](https://{alias}.{domain_to_use}/) | ✅ |\n" updated_line = f"| [{site_name}](https://{alias}.{domain_to_use}/) | ✅ |\n"
print("To: ", updated_line.strip()) print("Update: ", updated_line.strip())
updated_lines.append(updated_line) updated_lines.append(updated_line)
continue continue
@ -124,11 +122,6 @@ if __name__ == "__main__":
else: else:
domain_to_use, _ = search_domain(site_name=site_name, base_url=f"https://{site_name}", get_first=True) domain_to_use, _ = search_domain(site_name=site_name, base_url=f"https://{site_name}", get_first=True)
# Update readme update_readme(alias, domain_to_use)
if original_domain != domain_to_use:
print("\n")
print("Return domain: ", domain_to_use)
update_readme(alias, domain_to_use)
print("------------------------------------") print("------------------------------------")
time.sleep(3) time.sleep(3)

View File

@ -64,7 +64,7 @@
"domain": "prof" "domain": "prof"
}, },
"guardaserie": { "guardaserie": {
"domain": "help" "domain": "academy"
}, },
"mostraguarda": { "mostraguarda": {
"domain": "stream" "domain": "stream"