diff --git a/Src/Api/Guardaserie/Core/Class/ScrapeSerie.py b/Src/Api/Guardaserie/Core/Class/ScrapeSerie.py index 3efee8a..537a46c 100644 --- a/Src/Api/Guardaserie/Core/Class/ScrapeSerie.py +++ b/Src/Api/Guardaserie/Core/Class/ScrapeSerie.py @@ -45,7 +45,8 @@ class GetSerieInfo: try: # Make an HTTP request to the series URL - response = httpx.get(self.url, headers=self.headers) + print(self.url) + response = httpx.get(self.url, headers=self.headers, timeout=10) response.raise_for_status() # Parse HTML content of the page diff --git a/Src/Api/Guardaserie/series.py b/Src/Api/Guardaserie/series.py index 25e29b0..aef0cb0 100644 --- a/Src/Api/Guardaserie/series.py +++ b/Src/Api/Guardaserie/series.py @@ -62,6 +62,7 @@ def donwload_video(scape_info_serie: GetSerieInfo, index_season_selected: int, i output_filename = os.path.join(mp4_path, mp4_name) ).start() + def donwload_episode(scape_info_serie: GetSerieInfo, index_season_selected: int, donwload_all: bool = False) -> None: """ Download all episodes of a season. @@ -101,7 +102,6 @@ def donwload_episode(scape_info_serie: GetSerieInfo, index_season_selected: int, donwload_video(scape_info_serie, index_season_selected, i_episode) - def download_series(dict_serie: MediaItem) -> None: # Start message and set up video source diff --git a/Src/Api/Guardaserie/site.py b/Src/Api/Guardaserie/site.py index e7c3615..aed0d70 100644 --- a/Src/Api/Guardaserie/site.py +++ b/Src/Api/Guardaserie/site.py @@ -28,7 +28,9 @@ table_show_manager = TVShowManager() # Config +SITE_NAME = "guardaserie" ROOT_PATH = config_manager.get('DEFAULT', 'root_path') +DOMAIN_NOW = config_manager.get('SITE', SITE_NAME) @@ -38,7 +40,7 @@ def title_search(word_to_search) -> int: """ # Send request to search for titles - response = httpx.get(f"https://guardaserie.ceo/?story={word_to_search}&do=search&subaction=search", headers={'user-agent': get_headers()}) + response = httpx.get(f"https://guardaserie.{DOMAIN_NOW}/?story={word_to_search}&do=search&subaction=search", headers={'user-agent': get_headers()}) response.raise_for_status() # Create soup and find table diff --git a/Src/Lib/Hls/download_mp4.py b/Src/Lib/Hls/download_mp4.py index 942f37a..a60c4ad 100644 --- a/Src/Lib/Hls/download_mp4.py +++ b/Src/Lib/Hls/download_mp4.py @@ -31,44 +31,47 @@ REQUEST_TIMEOUT = config_manager.get_float('REQUESTS', 'timeout') def MP4_downloader(url: str, path: str, referer: str, add_desc: str): - if not os.path.exists(path): - console.log("[cyan]Video [red]already exists.") - sys.exit(0) - - # Make request to get content of video logging.info(f"Make request to fetch mp4 from: {url}") - response = httpx.get(url, stream=True, headers={'Referer': referer, 'user-agent': get_headers()}, verify=REQUEST_VERIFY, timeout=REQUEST_TIMEOUT) - total = int(response.headers.get('content-length', 0)) + headers = {'Referer': referer, 'user-agent': get_headers()} + + with httpx.Client(verify=REQUEST_VERIFY, timeout=REQUEST_TIMEOUT) as client: + with client.stream("GET", url, headers=headers) as response: + total = int(response.headers.get('content-length', 0)) + # Create bar format + if TQDM_USE_LARGE_BAR: + bar_format = (f"{Colors.YELLOW}Downloading {Colors.WHITE}({add_desc}{Colors.WHITE}): " + f"{Colors.RED}{{percentage:.2f}}% {Colors.MAGENTA}{{bar}} {Colors.WHITE}[ " + f"{Colors.YELLOW}{{n_fmt}}{Colors.WHITE} / {Colors.RED}{{total_fmt}} {Colors.WHITE}] " + f"{Colors.YELLOW}{{elapsed}} {Colors.WHITE}< {Colors.CYAN}{{remaining}} {Colors.WHITE}| " + f"{Colors.YELLOW}{{rate_fmt}}{{postfix}} {Colors.WHITE}]") + else: + bar_format = (f"{Colors.YELLOW}Proc{Colors.WHITE}: {Colors.RED}{{percentage:.2f}}% " + f"{Colors.WHITE}| {Colors.CYAN}{{remaining}}{{postfix}} {Colors.WHITE}]") - # Create bar format - if TQDM_USE_LARGE_BAR: - bar_format=f"{Colors.YELLOW}Downloading {Colors.WHITE}({add_desc}{Colors.WHITE}): {Colors.RED}{{percentage:.2f}}% {Colors.MAGENTA}{{bar}} {Colors.WHITE}[ {Colors.YELLOW}{{n_fmt}}{Colors.WHITE} / {Colors.RED}{{total_fmt}} {Colors.WHITE}] {Colors.YELLOW}{{elapsed}} {Colors.WHITE}< {Colors.CYAN}{{remaining}} {Colors.WHITE}| {Colors.YELLOW}{{rate_fmt}}{{postfix}} {Colors.WHITE}]" - else: - bar_format=f"{Colors.YELLOW}Proc{Colors.WHITE}: {Colors.RED}{{percentage:.2f}}% {Colors.WHITE}| {Colors.CYAN}{{remaining}}{{postfix}} {Colors.WHITE}]" - - # Create progress bar - progress_bar = tqdm( - total=total, - unit='iB', - ascii='░▒█', - bar_format=bar_format, - unit_scale=True, - unit_divisor=1024 - ) - - - # Download file - with open(path, 'wb') as file, progress_bar as bar: - for data in response.iter_content(chunk_size=1024): - size = file.write(data) - bar.update(size) + # Create progress bar + progress_bar = tqdm( + total=total, + unit='iB', + ascii='░▒█', + bar_format=bar_format, + unit_scale=True, + unit_divisor=1024 + ) + # Download file + with open(path, 'wb') as file, progress_bar as bar: + for chunk in response.iter_bytes(chunk_size=1024): + if chunk: + size = file.write(chunk) + bar.update(size) # Get summary console.print(Panel( - f"[bold green]Download completed![/bold green]\n" - f"File size: [bold red]{format_size(os.path.getsize(path))}[/bold red]\n" - f"Duration: [bold]{print_duration_table(path, show=False)}[/bold]", - title=f"{os.path.basename(path.replace('.mp4', ''))}", border_style="green")) + f"[bold green]Download completed![/bold green]\n" + f"File size: [bold red]{format_size(os.path.getsize(path))}[/bold red]\n" + f"Duration: [bold]{print_duration_table(path, show=False)}[/bold]", + title=f"{os.path.basename(path.replace('.mp4', ''))}", + border_style="green" + )) \ No newline at end of file diff --git a/config.json b/config.json index 7a7aada..b9592a1 100644 --- a/config.json +++ b/config.json @@ -45,6 +45,7 @@ "SITE": { "streamingcommunity": "foo", "animeunity": "to", - "altadefinizione": "vodka" + "altadefinizione": "vodka", + "guardaserie": "ceo" } } \ No newline at end of file