restore resolution comparison
Browse files- pytube/cli.py +10 -1
- tests/test_cli.py +5 -1
pytube/cli.py
CHANGED
|
@@ -266,9 +266,18 @@ def ffmpeg_process(
|
|
| 266 |
target = target or os.getcwd()
|
| 267 |
|
| 268 |
if resolution == "best":
|
| 269 |
-
|
| 270 |
youtube.streams.filter(progressive=False).order_by("resolution").last()
|
| 271 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
else:
|
| 273 |
video_stream = youtube.streams.filter(
|
| 274 |
progressive=False, resolution=resolution, subtype="mp4"
|
|
|
|
| 266 |
target = target or os.getcwd()
|
| 267 |
|
| 268 |
if resolution == "best":
|
| 269 |
+
highest_quality_stream = (
|
| 270 |
youtube.streams.filter(progressive=False).order_by("resolution").last()
|
| 271 |
)
|
| 272 |
+
mp4_stream = (
|
| 273 |
+
youtube.streams.filter(progressive=False, subtype="mp4")
|
| 274 |
+
.order_by("resolution")
|
| 275 |
+
.last()
|
| 276 |
+
)
|
| 277 |
+
if highest_quality_stream.resolution == mp4_stream.resolution:
|
| 278 |
+
video_stream = mp4_stream
|
| 279 |
+
else:
|
| 280 |
+
video_stream = highest_quality_stream
|
| 281 |
else:
|
| 282 |
video_stream = youtube.streams.filter(
|
| 283 |
progressive=False, resolution=resolution, subtype="mp4"
|
tests/test_cli.py
CHANGED
|
@@ -380,7 +380,11 @@ def test_ffmpeg_process_audio_fallback_none_should_exit(_ffmpeg_downloader, yout
|
|
| 380 |
streams = MagicMock()
|
| 381 |
youtube.streams = streams
|
| 382 |
stream = MagicMock()
|
| 383 |
-
streams.filter.return_value.order_by.return_value.last.side_effect = [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
streams.get_audio_only.return_value = None
|
| 385 |
# When
|
| 386 |
with pytest.raises(SystemExit):
|
|
|
|
| 380 |
streams = MagicMock()
|
| 381 |
youtube.streams = streams
|
| 382 |
stream = MagicMock()
|
| 383 |
+
streams.filter.return_value.order_by.return_value.last.side_effect = [
|
| 384 |
+
stream,
|
| 385 |
+
stream,
|
| 386 |
+
None,
|
| 387 |
+
]
|
| 388 |
streams.get_audio_only.return_value = None
|
| 389 |
# When
|
| 390 |
with pytest.raises(SystemExit):
|