Skip to content

Commit

Permalink
fix(cli): properly handle keyboard interrupt in downloads
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Shatford <[email protected]>
  • Loading branch information
jordanshatford committed Oct 28, 2023
1 parent 63b97a3 commit f742f83
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions apps/cli/ydcli/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ def prompt_for_download_options() -> DownloadOptions:
*[Choice(f.name, f) for f in VideoFormat],
],
default=VideoFormat.MP4,
).ask()
).unsafe_ask()
quality = questionary.select(
'Quality:',
[Choice(q.name, q) for q in DownloadQuality],
default=DownloadQuality.BEST,
).ask()
).unsafe_ask()
embedding = questionary.checkbox(
'Embed:',
[
Choice('Metadata', checked=True),
Choice('Thumbnail'),
Choice('Subtitles'),
],
).ask()
).unsafe_ask()
return DownloadOptions(
format=fmt,
quality=quality,
Expand All @@ -44,12 +44,18 @@ def prompt_for_download_options() -> DownloadOptions:

# Run the download for a video
def run() -> int:
path = questionary.path(
'Directory to store downloads:',
only_directories=True,
default='./downloads',
).unsafe_ask()
output_dir = os.path.abspath(path)
questionary.print(f'Downloading files to: {output_dir}')
url = questionary.text(
message='Video URL:', validate=validate_youtube_url,
).ask()
).unsafe_ask()
options = prompt_for_download_options()
# Download and wait for video
output_dir = os.path.join(os.getcwd(), '__downloads__')
manager = DownloadManager(output_dir)
manager.add_using_url(url, options)
manager.wait_for_all()
Expand Down

1 comment on commit f742f83

@vercel
Copy link

@vercel vercel bot commented on f742f83 Oct 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.