diff --git a/StreamingCommunity/Api/Player/maxstream.py b/StreamingCommunity/Api/Player/maxstream.py index d5bae17..ff90416 100644 --- a/StreamingCommunity/Api/Player/maxstream.py +++ b/StreamingCommunity/Api/Player/maxstream.py @@ -48,11 +48,7 @@ class VideoSource: return self.redirect_url - except httpx.RequestError as e: - logging.error(f"Error during the initial request: {e}") - raise - - except AttributeError as e: + except Exception as e: logging.error(f"Error parsing HTML: {e}") raise @@ -98,12 +94,8 @@ class VideoSource: return self.maxstream_url - except httpx.RequestError as e: - logging.error(f"Error during the request to the redirect URL: {e}") - raise - - except AttributeError as e: - logging.error(f"Error parsing HTML: {e}") + except Exception as e: + logging.error(f"Error during the request: {e}") raise def get_m3u8_url(self): diff --git a/StreamingCommunity/Api/Site/1337xx/site.py b/StreamingCommunity/Api/Site/1337xx/site.py index 7d0284c..b309e23 100644 --- a/StreamingCommunity/Api/Site/1337xx/site.py +++ b/StreamingCommunity/Api/Site/1337xx/site.py @@ -16,7 +16,6 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class from StreamingCommunity.Api.Template.config_loader import site_constant -from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager @@ -40,14 +39,6 @@ def title_search(word_to_search: str) -> int: media_search_manager.clear() table_show_manager.clear() - # Check if domain is working - domain_to_use, base_url = search_domain(site_constant.FULL_URL) - - if domain_to_use is None or base_url is None: - console.log("[bold red]Error: Unable to determine valid domain or base URL.[/bold red]") - console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]") - sys.exit(1) - search_url = f"{site_constant.FULL_URL}/search/{word_to_search}/1/" console.print(f"[cyan]Search url: [yellow]{search_url}") @@ -57,6 +48,7 @@ def title_search(word_to_search: str) -> int: except Exception as e: console.print(f"Site: {site_constant.SITE_NAME}, request search error: {e}") + return 0 # Create soup and find table soup = BeautifulSoup(response.text, "html.parser") diff --git a/StreamingCommunity/Api/Site/altadefinizione/__init__.py b/StreamingCommunity/Api/Site/altadefinizione/__init__.py new file mode 100644 index 0000000..22e4b35 --- /dev/null +++ b/StreamingCommunity/Api/Site/altadefinizione/__init__.py @@ -0,0 +1,61 @@ +# 21.05.24 + +from urllib.parse import quote_plus + + +# External library +from rich.console import Console +from rich.prompt import Prompt + + +# Internal utilities +from StreamingCommunity.Api.Template import get_select_title + + +# Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant +#from .site import title_search, table_show_manager, media_search_manager +#from .film import download_film +#from .series import download_series + + +# Variable +indice = 4 +_useFor = "film_serie" +_deprecate = True +_priority = 1 +_engineDownload = "hls" + +msg = Prompt() +console = Console() + + +def search(string_to_search: str = None, get_onylDatabase: bool = False): + """ + Main function of the application for film and series. + """ + if string_to_search is None: + string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{site_constant.SITE_NAME}").strip() + + len_database = title_search(quote_plus(string_to_search)) + + # Return list of elements + if get_onylDatabase: + return media_search_manager + + if len_database > 0: + + # Select title from list + select_title = get_select_title(table_show_manager, media_search_manager) + + if select_title.type == 'tv': + download_series(select_title) + + else: + download_film(select_title) + + else: + console.print(f"\n[red]Nothing matching was found for[white]: [purple]{string_to_search}") + + # Retry + search() \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/animeunity/site.py b/StreamingCommunity/Api/Site/animeunity/site.py index b7f6da2..7d765c7 100644 --- a/StreamingCommunity/Api/Site/animeunity/site.py +++ b/StreamingCommunity/Api/Site/animeunity/site.py @@ -19,7 +19,6 @@ from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance # Logic class from StreamingCommunity.Api.Template.config_loader import site_constant -from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager @@ -102,14 +101,6 @@ def title_search(title: str) -> int: media_search_manager.clear() table_show_manager.clear() - # Check if domain is working - domain_to_use, base_url = search_domain(site_constant.FULL_URL) - - if domain_to_use is None or base_url is None: - console.print("[bold red]Error: Unable to determine valid domain or base URL.[/bold red]") - console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]") - sys.exit(1) - # Create parameter for request data = get_token() cookies = {'animeunity_session': data.get('animeunity_session')} @@ -132,6 +123,7 @@ def title_search(title: str) -> int: except Exception as e: console.print(f"Site: {site_constant.SITE_NAME}, request search error: {e}") + return 0 # Inizializza la lista delle scelte if site_constant.TELEGRAM_BOT: diff --git a/StreamingCommunity/Api/Site/cb01new/site.py b/StreamingCommunity/Api/Site/cb01new/site.py index b1658ae..ea0c328 100644 --- a/StreamingCommunity/Api/Site/cb01new/site.py +++ b/StreamingCommunity/Api/Site/cb01new/site.py @@ -17,7 +17,6 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class from StreamingCommunity.Api.Template.config_loader import site_constant -from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager @@ -41,15 +40,7 @@ def title_search(word_to_search: str) -> int: media_search_manager.clear() table_show_manager.clear() - # Check if domain is working - domain_to_use, base_url = search_domain(site_constant.FULL_URL) - - if domain_to_use is None or base_url is None: - console.print("[bold red]Error: Unable to determine valid domain or base URL.[/bold red]") - console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]") - sys.exit(1) - - search_url = f"{site_constant.FULL_URL}/?s={word_to_search}" + search_url = f"{site_constant.FULL_URL}/?story={word_to_search}&do=search&subaction=search" console.print(f"[cyan]Search url: [yellow]{search_url}") try: @@ -58,20 +49,18 @@ def title_search(word_to_search: str) -> int: except Exception as e: console.print(f"Site: {site_constant.SITE_NAME}, request search error: {e}") + return 0 # Create soup and find table soup = BeautifulSoup(response.text, "html.parser") - for div in soup.find_all("div", class_ = "card-content"): + for div in soup.find_all("div", class_ = "short-main"): try: - - url = div.find("h3").find("a").get("href") - title = div.find("h3").find("a").get_text(strip=True) - desc = div.find("p").find("strong").text + url = div.find("a").get("href") + title = div.find("a").get_text(strip=True) title_info = { 'name': title, - 'desc': desc, 'url': url } diff --git a/StreamingCommunity/Api/Site/ddlstreamitaly/site.py b/StreamingCommunity/Api/Site/ddlstreamitaly/site.py index fe4d69a..f3e2fb4 100644 --- a/StreamingCommunity/Api/Site/ddlstreamitaly/site.py +++ b/StreamingCommunity/Api/Site/ddlstreamitaly/site.py @@ -18,7 +18,6 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class from StreamingCommunity.Api.Template.config_loader import site_constant -from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager @@ -42,14 +41,6 @@ def title_search(word_to_search: str) -> int: media_search_manager.clear() table_show_manager.clear() - # Check if domain is working - domain_to_use, base_url = search_domain(site_constant.FULL_URL) - - if domain_to_use is None or base_url is None: - console.print("[bold red]Error: Unable to determine valid domain or base URL.[/bold red]") - console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]") - sys.exit(1) - search_url = f"{site_constant.FULL_URL}/search/?&q={word_to_search}&quick=1&type=videobox_video&nodes=11" console.print(f"[cyan]Search url: [yellow]{search_url}") @@ -59,6 +50,7 @@ def title_search(word_to_search: str) -> int: except Exception as e: console.print(f"Site: {site_constant.SITE_NAME}, request search error: {e}") + return 0 # Create soup and find table soup = BeautifulSoup(response.text, "html.parser") diff --git a/StreamingCommunity/Api/Site/guardaserie/site.py b/StreamingCommunity/Api/Site/guardaserie/site.py index b2441a7..6fee90f 100644 --- a/StreamingCommunity/Api/Site/guardaserie/site.py +++ b/StreamingCommunity/Api/Site/guardaserie/site.py @@ -16,7 +16,6 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class from StreamingCommunity.Api.Template.config_loader import site_constant -from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager @@ -41,14 +40,6 @@ def title_search(word_to_search: str) -> int: media_search_manager.clear() table_show_manager.clear() - # Check if domain is working - domain_to_use, base_url = search_domain(site_constant.FULL_URL) - - if domain_to_use is None or base_url is None: - console.print("[bold red]Error: Unable to determine valid domain or base URL.[/bold red]") - console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]") - sys.exit(1) - search_url = f"{site_constant.FULL_URL}/?story={word_to_search}&do=search&subaction=search" console.print(f"[cyan]Search url: [yellow]{search_url}") @@ -58,6 +49,7 @@ def title_search(word_to_search: str) -> int: except Exception as e: console.print(f"Site: {site_constant.SITE_NAME}, request search error: {e}") + return 0 # Create soup and find table soup = BeautifulSoup(response.text, "html.parser") diff --git a/StreamingCommunity/Api/Site/streamingcommunity/site.py b/StreamingCommunity/Api/Site/streamingcommunity/site.py index cb8bac4..1564315 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/site.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/site.py @@ -17,7 +17,6 @@ from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance # Logic class from StreamingCommunity.Api.Template.config_loader import site_constant -from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager @@ -38,13 +37,6 @@ def title_search(title_search: str) -> int: Returns: int: The number of titles found. """ - domain_to_use, base_url = search_domain(site_constant.FULL_URL) - - if domain_to_use is None or base_url is None: - console.print("[bold red]Error: Unable to determine valid domain or base URL.[/bold red]") - console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]") - sys.exit(1) - if site_constant.TELEGRAM_BOT: bot = get_bot_instance() @@ -60,6 +52,7 @@ def title_search(title_search: str) -> int: except Exception as e: console.print(f"Site: {site_constant.SITE_NAME}, request search error: {e}") + return 0 # Prepara le scelte per l'utente if site_constant.TELEGRAM_BOT: diff --git a/StreamingCommunity/Api/Template/Class/SearchType.py b/StreamingCommunity/Api/Template/Class/SearchType.py index 5b480a5..dcf1b28 100644 --- a/StreamingCommunity/Api/Template/Class/SearchType.py +++ b/StreamingCommunity/Api/Template/Class/SearchType.py @@ -98,4 +98,4 @@ class MediaManager: self.media_list.clear() def __str__(self): - return f"MediaManager(num_media={len(self.media_list)})" + return f"MediaManager(num_media={len(self.media_list)})" \ No newline at end of file diff --git a/StreamingCommunity/Api/Template/Util/__init__.py b/StreamingCommunity/Api/Template/Util/__init__.py index c3e219a..937eb36 100644 --- a/StreamingCommunity/Api/Template/Util/__init__.py +++ b/StreamingCommunity/Api/Template/Util/__init__.py @@ -1,6 +1,5 @@ # 23.11.24 -from .get_domain import search_domain from .manage_ep import ( manage_selection, map_episode_title, diff --git a/StreamingCommunity/Api/Template/Util/get_domain.py b/StreamingCommunity/Api/Template/Util/get_domain.py deleted file mode 100644 index 52db475..0000000 --- a/StreamingCommunity/Api/Template/Util/get_domain.py +++ /dev/null @@ -1,100 +0,0 @@ -# 18.06.24 - -import certifi -from urllib.parse import urlparse, unquote - - -# External libraries -import httpx -from rich.console import Console - - -# Internal utilities -from StreamingCommunity.Util.headers import get_headers -from StreamingCommunity.Util.config_json import config_manager - - -# Variable -console = Console() -VERIFY = config_manager.get("REQUESTS", "verify") -MAX_TIMEOUT = config_manager.get_int("REQUESTS", "timeout") - - -def get_tld(url_str): - """Extract the TLD (Top-Level Domain) from the URL.""" - try: - url_str = unquote(url_str) - parsed = urlparse(url_str) - domain = parsed.netloc.lower() - - if domain.startswith('www.'): - domain = domain[4:] - parts = domain.split('.') - - return parts[-1] if len(parts) >= 2 else None - - except Exception: - return None - -def get_base_domain(url_str): - """Extract base domain without protocol, www and path.""" - try: - parsed = urlparse(url_str) - domain = parsed.netloc.lower() - if domain.startswith('www.'): - domain = domain[4:] - - # Check if domain has multiple parts separated by dots - parts = domain.split('.') - if len(parts) > 2: - return '.'.join(parts[:-1]) - - return parts[0] - - except Exception: - return None - -def validate_url(url, base_url): - """Validate if URL is accessible and matches expected base domain.""" - console.print(f"\n[cyan]Starting validation for URL[white]: [yellow]{url}") - - # Verify URL structure matches base_url structure - base_domain = get_base_domain(base_url) - url_domain = get_base_domain(url) - - if base_domain != url_domain: - console.print(f"[red]Domain structure mismatch: {url_domain} != {base_domain}") - return False, None - - client = httpx.Client( - http1=True, - verify=certifi.where(), - headers=get_headers(), - timeout=MAX_TIMEOUT - ) - - # Make request to web site - response = client.get(url, follow_redirects=False) - - if response.status_code >= 400: - console.print(f"[red]Check failed: HTTP {response.status_code}") - console.print(f"[red]Response content: {response.text}") - return False, None - - return True, base_domain - -def search_domain(base_url: str): - """Search for valid domain matching site name and base URL.""" - try: - is_correct, redirect_tld = validate_url(base_url, base_url) - - if is_correct: - tld = redirect_tld or get_tld(base_url) - return tld, base_url - - else: - return None, None - - except Exception as e: - console.print(f"[red]Error testing initial URL: {str(e)}") - return None, None \ No newline at end of file diff --git a/StreamingCommunity/Api/Template/Util/manage_ep.py b/StreamingCommunity/Api/Template/Util/manage_ep.py index 8a804c4..c3a60af 100644 --- a/StreamingCommunity/Api/Template/Util/manage_ep.py +++ b/StreamingCommunity/Api/Template/Util/manage_ep.py @@ -218,6 +218,7 @@ def validate_episode_selection(list_episode_select: List[int], episodes_count: i input_episodes = input(f"Enter valid episode numbers (1-{episodes_count}): ") list_episode_select = list(map(int, input_episodes.split(','))) + def display_episodes_list(episodes_manager) -> str: """ Display episodes list and handle user input. diff --git a/StreamingCommunity/Api/Template/config_loader.py b/StreamingCommunity/Api/Template/config_loader.py index d9da377..fe3e16e 100644 --- a/StreamingCommunity/Api/Template/config_loader.py +++ b/StreamingCommunity/Api/Template/config_loader.py @@ -31,10 +31,6 @@ class SiteConstant: def ROOT_PATH(self): return config_manager.get('OUT_FOLDER', 'root_path') - @property - def DOMAIN_NOW(self): - return config_manager.get_site(self.SITE_NAME, 'domain') - @property def FULL_URL(self): return config_manager.get_site(self.SITE_NAME, 'full_url').rstrip('/') diff --git a/StreamingCommunity/Util/config_json.py b/StreamingCommunity/Util/config_json.py index 2cab36a..b2bc7f5 100644 --- a/StreamingCommunity/Util/config_json.py +++ b/StreamingCommunity/Util/config_json.py @@ -421,9 +421,6 @@ class ConfigManager: config_manager = ConfigManager() config_manager.read_config() - -import sys - def get_use_large_bar(): """ Determines whether the large bar feature should be enabled.