Skip to content

Commit

Permalink
Added all Downloader options to built-in YouTube downloader and fixed…
Browse files Browse the repository at this point in the history
… variable errors
  • Loading branch information
henrique-coder committed Dec 18, 2024
1 parent 5bc4b72 commit 83d92f3
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions streamsnapper/platforms/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit 83d92f3

Please sign in to comment.