Upgraded stopped option handling for HLS

This commit is contained in:
Gra 2025-02-01 12:29:24 +01:00
parent 8faeeefdd7
commit a6836744b5
9 changed files with 62 additions and 10 deletions

View File

@ -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: ")

View File

@ -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)

View File

@ -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()
@ -71,6 +72,11 @@ def download_video(index_episode_selected: int, scape_info_serie: GetSerieInfo,
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: ")
console.print(r_proc)
@ -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:

View File

@ -71,6 +71,13 @@ def download_video(index_season_selected: int, index_episode_selected: int, scap
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: ")
console.print(r_proc)
@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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:
"""

View File

@ -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:

View File

@ -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}
if self.download_interrupted:
return {'type': type, 'nFailed': self.info_nFailed, 'stopped': bool(True)}
return {'type': type, 'nFailed': self.info_nFailed, 'stopped': bool(False)}