Skip to content

Commit

Permalink
fix: improve cancel behavior in video quality selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Hetari committed Jun 28, 2024
1 parent 32030d6 commit 1abf621
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
8 changes: 8 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Uninstall the package 'pyutube' with the '-y' flag to confirm the uninstallation without user prompt
pip uninstall pyutube -y

# Build a wheel distribution package using the 'setup.py' file
python setup.py bdist_wheel

# Install the wheel distribution package located in the 'dist' directory
pip3 install dist/*
5 changes: 3 additions & 2 deletions pyutube/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ask_resolution,
rename_file,
is_file_exists,
CANCEL_PREFIX
)

import os
Expand Down Expand Up @@ -207,7 +208,7 @@ def get_selected_stream(self, video):
self.quality = ask_resolution(
resolutions, sizes) if self.quality is None else self.quality

return [] if self.quality.startswith("cancel") else streams, video_audio
return [] if self.quality.startswith(CANCEL_PREFIX) else streams, video_audio

def generate_filename(self, video, video_id):
"""
Expand Down Expand Up @@ -374,7 +375,7 @@ def download_video(self) -> bool:
# shorts and videos
streams, video_audio = self.get_selected_stream(video)

if not streams:
if not streams or self.quality.startswith(CANCEL_PREFIX):
error_console.print("❗ Cancel the download...")
sys.exit()

Expand Down
8 changes: 4 additions & 4 deletions pyutube/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from termcolor import colored


__version__ = "1.2.8"
__version__ = "1.2.9"
__app__ = "pyutube"
ABORTED_PREFIX = "aborted"
CANCEL_PREFIX = "cancel"
CANCEL_PREFIX = "Cancel"


# Set up the console
Expand Down Expand Up @@ -167,7 +167,7 @@ def file_type() -> str:
inquirer.List(
"file_type",
message="Choose the file type you want to download",
choices=['Audio', 'Video', "Cancel the download"],
choices=['Audio', 'Video', CANCEL_PREFIX],
),
]

Expand Down Expand Up @@ -203,7 +203,7 @@ def ask_resolution(resolutions: set, sizes) -> str:
# Generate the choices for the user prompt
resolution_choices = [
f"{size} ~= {resolution}" for size, resolution in size_resolution_mapping.items()
] + ["Cancel the download"]
] + [CANCEL_PREFIX]

questions = [
inquirer.List(
Expand Down

0 comments on commit 1abf621

Please sign in to comment.