diff --git a/StreamingCommunity/Api/Site/altadefinizionegratis/film.py b/StreamingCommunity/Api/Site/altadefinizionegratis/film.py index 609802d..67135a8 100644 --- a/StreamingCommunity/Api/Site/altadefinizionegratis/film.py +++ b/StreamingCommunity/Api/Site/altadefinizionegratis/film.py @@ -64,6 +64,9 @@ def download_film(select_title: MediaItem) -> str: if msg.ask("[green]Do you want to continue [white]([red]y[white])[green] or return at home[white]([red]n[white]) ", choices=['y', 'n'], default='y', show_choices=True) == "n": frames = get_call_stack() execute_search(frames[-4])""" + if r_proc == None: + if os.path.exists(os.path.join(mp4_path, title_name)): + os.remove(os.path.join(mp4_path, title_name)) if r_proc != None: console.print("[green]Result: ") diff --git a/StreamingCommunity/Api/Site/cb01new/film.py b/StreamingCommunity/Api/Site/cb01new/film.py index aa98e13..282a639 100644 --- a/StreamingCommunity/Api/Site/cb01new/film.py +++ b/StreamingCommunity/Api/Site/cb01new/film.py @@ -64,6 +64,10 @@ def download_film(select_title: MediaItem) -> str: frames = get_call_stack() execute_search(frames[-4])""" + if r_proc == None: + if os.path.exists(os.path.join(mp4_path, title_name)): + os.remove(os.path.join(mp4_path, title_name)) + if r_proc != None: console.print("[green]Result: ") console.print(r_proc) diff --git a/StreamingCommunity/Api/Site/ddlstreamitaly/series.py b/StreamingCommunity/Api/Site/ddlstreamitaly/series.py index ec18bf1..95ee7ea 100644 --- a/StreamingCommunity/Api/Site/ddlstreamitaly/series.py +++ b/StreamingCommunity/Api/Site/ddlstreamitaly/series.py @@ -28,7 +28,7 @@ from .costant import SERIES_FOLDER -def download_video(index_episode_selected: int, scape_info_serie: GetSerieInfo, video_source: VideoSource) -> str: +def download_video(index_episode_selected: int, scape_info_serie: GetSerieInfo, video_source: VideoSource) -> tuple[str,bool]: """ Download a single episode video. @@ -38,6 +38,7 @@ def download_video(index_episode_selected: int, scape_info_serie: GetSerieInfo, Return: - str: output path + - bool: kill handler status """ start_message() @@ -70,6 +71,11 @@ def download_video(index_episode_selected: int, scape_info_serie: GetSerieInfo, path=os.path.join(mp4_path, title_name), referer=f"{parsed_url.scheme}://{parsed_url.netloc}/", ) + + if r_proc == None: + if os.path.exists(os.path.join(mp4_path, title_name)): + os.remove(os.path.join(mp4_path, title_name)) + return "",True if r_proc != None: console.print("[green]Result: ") @@ -105,8 +111,11 @@ def download_thread(dict_serie: MediaItem): return # Download selected episodes + kill_handler = bool(False) for i_episode in list_episode_select: - download_video(i_episode, scape_info_serie, video_source) + if kill_handler: + break + kill_handler = download_video(i_episode, scape_info_serie, video_source)[1] def display_episodes_list(obj_episode_manager) -> str: diff --git a/StreamingCommunity/Api/Site/guardaserie/series.py b/StreamingCommunity/Api/Site/guardaserie/series.py index 70d8fa0..114ed08 100644 --- a/StreamingCommunity/Api/Site/guardaserie/series.py +++ b/StreamingCommunity/Api/Site/guardaserie/series.py @@ -70,6 +70,13 @@ def download_video(index_season_selected: int, index_episode_selected: int, scap if msg.ask("[green]Do you want to continue [white]([red]y[white])[green] or return at home[white]([red]n[white]) ", choices=['y', 'n'], default='y', show_choices=True) == "n": frames = get_call_stack() execute_search(frames[-4])""" + + # Removes file not completed and stops other downloads + if r_proc == None: + if os.path.exists(os.path.join(mp4_path, mp4_name)): + os.remove(os.path.join(mp4_path, mp4_name)) + return "",True + if r_proc != None: console.print("[green]Result: ") @@ -113,7 +120,10 @@ def download_episode(scape_info_serie: GetSerieInfo, index_season_selected: int, return # Download selected episodes + stopped = bool(False) for i_episode in list_episode_select: + if stopped: + break download_video(index_season_selected, i_episode, scape_info_serie) diff --git a/StreamingCommunity/Api/Site/mostraguarda/film.py b/StreamingCommunity/Api/Site/mostraguarda/film.py index b7889d9..c4b1268 100644 --- a/StreamingCommunity/Api/Site/mostraguarda/film.py +++ b/StreamingCommunity/Api/Site/mostraguarda/film.py @@ -94,6 +94,10 @@ def download_film(movie_details: Json_film) -> str: frames = get_call_stack() execute_search(frames[-4])""" + if r_proc == None: + if os.path.exists(os.path.join(mp4_path, title_name)): + os.remove(os.path.join(mp4_path, title_name)) + if r_proc != None: console.print("[green]Result: ") console.print(r_proc) diff --git a/StreamingCommunity/Api/Site/streamingcommunity/film.py b/StreamingCommunity/Api/Site/streamingcommunity/film.py index 436cca6..2b06174 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/film.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/film.py @@ -68,6 +68,10 @@ def download_film(select_title: MediaItem) -> str: frames = get_call_stack() execute_search(frames[-4])""" + if r_proc == None: + if os.path.exists(os.path.join(mp4_path, title_name)): + os.remove(os.path.join(mp4_path, title_name)) + if r_proc != None: console.print("[green]Result: ") console.print(r_proc) diff --git a/StreamingCommunity/Api/Site/streamingcommunity/series.py b/StreamingCommunity/Api/Site/streamingcommunity/series.py index 36da453..5de0267 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/series.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/series.py @@ -28,7 +28,7 @@ from .costant import SITE_NAME, SERIES_FOLDER -def download_video(index_season_selected: int, index_episode_selected: int, scrape_serie: ScrapeSerie, video_source: VideoSource) -> str: +def download_video(index_season_selected: int, index_episode_selected: int, scrape_serie: ScrapeSerie, video_source: VideoSource) -> tuple[str,bool]: """ Download a single episode video. @@ -38,6 +38,7 @@ def download_video(index_season_selected: int, index_episode_selected: int, scra Return: - str: output path + - bool: kill handler status """ start_message() index_season_selected = dynamic_format_number(index_season_selected) @@ -70,6 +71,12 @@ def download_video(index_season_selected: int, index_episode_selected: int, scra frames = get_call_stack() execute_search(frames[-4])""" + if r_proc == None: + if os.path.exists(os.path.join(mp4_path, mp4_name)): + os.remove(os.path.join(mp4_path, mp4_name)) + return "",True + + if r_proc != None: console.print("[green]Result: ") console.print(r_proc) @@ -112,9 +119,12 @@ def download_episode(index_season_selected: int, scrape_serie: ScrapeSerie, vide console.print(f"[red]{str(e)}") return - # Download selected episodes + # Download selected episodes if not stopped + stopped = bool(False) for i_episode in list_episode_select: - download_video(index_season_selected, i_episode, scrape_serie, video_source) + if stopped: + break + stopped=download_video(index_season_selected, i_episode, scrape_serie, video_source)[1] def download_series(select_season: MediaItem, version: str) -> None: """ diff --git a/StreamingCommunity/Lib/Downloader/HLS/downloader.py b/StreamingCommunity/Lib/Downloader/HLS/downloader.py index 4a004b9..2ab36fe 100644 --- a/StreamingCommunity/Lib/Downloader/HLS/downloader.py +++ b/StreamingCommunity/Lib/Downloader/HLS/downloader.py @@ -416,7 +416,7 @@ class ContentDownloader: # Download the video streams and print status info_dw = video_m3u8.download_streams(f"{Colors.MAGENTA}video", "video") list_MissingTs.append(info_dw) - + self.stopped=list_MissingTs.pop() # Print duration information of the downloaded video #print_duration_table(downloaded_video[0].get('path')) @@ -447,7 +447,7 @@ class ContentDownloader: # Download the audio segments and print status info_dw = audio_m3u8.download_streams(f"{Colors.MAGENTA}audio {Colors.RED}{obj_audio.get('language')}", f"audio_{obj_audio.get('language')}") list_MissingTs.append(info_dw) - + self.stopped=list_MissingTs.pop() # Print duration information of the downloaded audio #print_duration_table(obj_audio.get('path')) @@ -710,6 +710,8 @@ class ContentJoiner: class HLS_Downloader: + stopped = bool(False) + def __init__(self, output_filename: str=None, m3u8_playlist: str=None, m3u8_index: str=None, is_playlist_url: bool=True, is_index_url: bool=True): """ Initializes the HLS_Downloader class. @@ -820,9 +822,11 @@ class HLS_Downloader: return None else: + if self.stopped: + return self.stopped return { 'path': self.output_filename, - 'url': self.m3u8_playlist + 'url': self.m3u8_playlist, } else: @@ -847,9 +851,11 @@ class HLS_Downloader: return None else: + if self.stopped: + return None return { 'path': self.output_filename, - 'url': self.m3u8_index + 'url': self.m3u8_index, } else: diff --git a/StreamingCommunity/Lib/Downloader/HLS/segments.py b/StreamingCommunity/Lib/Downloader/HLS/segments.py index d33d7f1..4229738 100644 --- a/StreamingCommunity/Lib/Downloader/HLS/segments.py +++ b/StreamingCommunity/Lib/Downloader/HLS/segments.py @@ -570,4 +570,6 @@ class M3U8_Segments: console.print("[yellow]⚠ Warning:[/yellow] Too many retries detected! Consider reducing the number of [cyan]workers[/cyan] in the [magenta]config.json[/magenta] file. This will impact [bold]performance[/bold]. \n") # Info to return - return {'type': type, 'nFailed': self.info_nFailed} \ No newline at end of file + if self.download_interrupted: + return {'type': type, 'nFailed': self.info_nFailed, 'stopped': bool(True)} + return {'type': type, 'nFailed': self.info_nFailed, 'stopped': bool(False)} \ No newline at end of file