From 83d92f31bebf76bb275925f14cdf69fd9fa85514 Mon Sep 17 00:00:00 2001 From: Henrique Date: Wed, 18 Dec 2024 18:58:52 -0300 Subject: [PATCH] Added all Downloader options to built-in YouTube downloader and fixed variable errors --- streamsnapper/platforms/youtube.py | 36 +++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/streamsnapper/platforms/youtube.py b/streamsnapper/platforms/youtube.py index 5a9c769..6fcc298 100644 --- a/streamsnapper/platforms/youtube.py +++ b/streamsnapper/platforms/youtube.py @@ -538,6 +538,9 @@ def download( audio_stream: Optional[Dict[str, Any]] = None, output_path: Union[str, PathLike] = Path.cwd(), ffmpeg_path: Union[str, PathLike, Literal['local']] = 'local', + max_connections: Union[int, Literal['auto']] = 'auto', + connection_speed: float = 80, + overwrite: bool = True, show_progress_bar: bool = True, timeout: Optional[int] = None, logging: bool = False, @@ -554,6 +557,9 @@ def download( audio_stream: The audio stream generated by .analyze_audio_streams(). (default: None) output_path: The output path to save the downloaded video and/or audio to. If a directory is provided, the file name will be generated based on the video title and ID, like 'title - [id].extension'. If a file is provided, the file will be saved with the provided name. (default: Path.cwd()) ffmpeg_path: The path to the ffmpeg executable. If 'local', the ffmpeg executable will be searched in the PATH environment variable. (default: 'local') + max_connections: The maximum number of connections to use for downloading the file. (default: 'auto') + connection_speed: The connection speed in Mbps. (default: 80) + overwrite: Overwrite the file if it already exists. Otherwise, a "_1", "_2", etc. suffix will be added. (default: True) show_progress_bar: Show or hide the download progress bar. (default: True) timeout: Timeout in seconds for the download process. Or None for no timeout. (default: None) logging: Enable or disable ffmpeg logging. (default: False) @@ -591,13 +597,21 @@ def download( output_video_path = Path(tmp_path, f'.tmp-video-{self.general_info["id"]}.{video_stream["extension"]}') video_downloader = Downloader( - max_connections='auto', show_progress_bar=show_progress_bar, overwrite=True, timeout=timeout + max_connections=max_connections, + connection_speed=connection_speed, + overwrite=overwrite, + show_progress_bar=show_progress_bar, + timeout=timeout, ) video_downloader.download(video_stream['url'], output_video_path) output_audio_path = Path(tmp_path, f'.tmp-audio-{self.general_info["id"]}.{audio_stream["extension"]}') audio_downloader = Downloader( - max_connections='auto', show_progress_bar=show_progress_bar, overwrite=True, timeout=timeout + max_connections=max_connections, + connection_speed=connection_speed, + overwrite=overwrite, + show_progress_bar=show_progress_bar, + timeout=timeout, ) audio_downloader.download(audio_stream['url'], output_audio_path) @@ -615,17 +629,29 @@ def download( output_path, f'{self.general_info["cleanTitle"]} [{self.general_info["id"]}].{video_stream["extension"]}' ) - downloader = Downloader(max_connections='auto', show_progress_bar=show_progress_bar, overwrite=True, timeout=timeout) + downloader = Downloader( + max_connections=max_connections, + connection_speed=connection_speed, + overwrite=overwrite, + show_progress_bar=show_progress_bar, + timeout=timeout, + ) downloader.download(video_stream['url'], output_path) - return Path(downloader.output_file_path) + return Path(downloader.output_path) elif audio_stream: if output_path.is_dir(): output_path = Path( output_path, f'{self.general_info["cleanTitle"]} [{self.general_info["id"]}].{audio_stream["extension"]}' ) - downloader = Downloader(max_connections='auto', show_progress_bar=show_progress_bar, overwrite=True, timeout=timeout) + downloader = Downloader( + max_connections=max_connections, + connection_speed=connection_speed, + overwrite=overwrite, + show_progress_bar=show_progress_bar, + timeout=timeout, + ) downloader.download(audio_stream['url'], output_path) return Path(downloader.output_path)