Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate filter #70

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions pytube/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _parse_args(
"--itag", type=int, help="The itag for the desired stream",
)
parser.add_argument(
"-r", "--resolution", type=str, help="The resolution for the desired stream",
"-r", "--resolution", type=int, help="The resolution for the desired stream",
)
parser.add_argument(
"-l",
Expand Down Expand Up @@ -271,34 +271,28 @@ def ffmpeg_process(

if resolution == "best":
highest_quality_stream = (
youtube.streams.filter(progressive=False).order_by("resolution").last()
youtube.streams.is_adaptive().order_by("resolution").last()
)
mp4_stream = (
youtube.streams.filter(progressive=False, subtype="mp4")
.order_by("resolution")
.last()
youtube.streams.is_adaptive().subtype("mp4").order_by("resolution").last()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks so good 🙌

Copy link
Member Author

Choose a reason for hiding this comment

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

Haha ikr!

)
if highest_quality_stream.resolution == mp4_stream.resolution:
video_stream = mp4_stream
else:
video_stream = highest_quality_stream
else:
video_stream = youtube.streams.filter(
progressive=False, resolution=resolution, subtype="mp4"
).first()
video_stream = (
youtube.streams.is_adaptive().res(resolution).subtype("mp4").first()
)
if not video_stream:
video_stream = youtube.streams.filter(
progressive=False, resolution=resolution
).first()
video_stream = youtube.streams.is_adaptive().res(resolution).first()
if video_stream is None:
print(f"Could not find a stream with resolution: {resolution}")
print("Try one of these:")
display_streams(youtube)
sys.exit()

audio_stream = youtube.streams.get_audio_only(video_stream.subtype)
if not audio_stream:
audio_stream = youtube.streams.filter(only_audio=True).order_by("abr").last()
audio_stream = youtube.streams.get_best_audio(video_stream.subtype)
if not audio_stream:
print("Could not find an audio only stream")
sys.exit()
Expand Down Expand Up @@ -370,13 +364,13 @@ def download_by_itag(youtube: YouTube, itag: int, target: Optional[str] = None)


def download_by_resolution(
youtube: YouTube, resolution: str, target: Optional[str] = None
youtube: YouTube, resolution: int, target: Optional[str] = None
) -> None:
"""Start downloading a YouTube video.

:param YouTube youtube:
A valid YouTube object.
:param str resolution:
:param int resolution:
YouTube video resolution.
:param str target:
Target directory for download
Expand Down
Loading