more download audio testing
Browse files- pytube/cli.py +1 -4
- tests/test_cli.py +25 -5
pytube/cli.py
CHANGED
@@ -450,10 +450,7 @@ def download_audio(
|
|
450 |
Target directory for download
|
451 |
"""
|
452 |
audio = (
|
453 |
-
youtube.streams.filter(only_audio=True, subtype=filetype)
|
454 |
-
.order_by("abr")
|
455 |
-
.desc()
|
456 |
-
.first()
|
457 |
)
|
458 |
|
459 |
if audio is None:
|
|
|
450 |
Target directory for download
|
451 |
"""
|
452 |
audio = (
|
453 |
+
youtube.streams.filter(only_audio=True, subtype=filetype).order_by("abr").last()
|
|
|
|
|
|
|
454 |
)
|
455 |
|
456 |
if audio is None:
|
tests/test_cli.py
CHANGED
@@ -324,7 +324,8 @@ def test_ffmpeg_downloader(unique_name, download, run, unlink):
|
|
324 |
)
|
325 |
# Then
|
326 |
download.assert_called()
|
327 |
-
run.assert_called_with(
|
|
|
328 |
"ffmpeg",
|
329 |
"-i",
|
330 |
f"target/video_name",
|
@@ -333,19 +334,38 @@ def test_ffmpeg_downloader(unique_name, download, run, unlink):
|
|
333 |
"-codec",
|
334 |
"copy",
|
335 |
f"target/safe_title.video_subtype",
|
336 |
-
]
|
|
|
337 |
unlink.assert_called()
|
338 |
|
339 |
|
|
|
340 |
@mock.patch("pytube.cli.YouTube.__init__", return_value=None)
|
341 |
-
def
|
|
|
342 |
parser = argparse.ArgumentParser()
|
343 |
args = parse_args(parser, ["http://youtube.com/watch?v=9bZkp7q19f0", "-a", "mp4"])
|
344 |
cli._parse_args = MagicMock(return_value=args)
|
345 |
-
|
346 |
cli.main()
|
|
|
347 |
youtube.assert_called()
|
348 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
|
350 |
|
351 |
@mock.patch("pytube.cli.YouTube.__init__", return_value=None)
|
|
|
324 |
)
|
325 |
# Then
|
326 |
download.assert_called()
|
327 |
+
run.assert_called_with(
|
328 |
+
[
|
329 |
"ffmpeg",
|
330 |
"-i",
|
331 |
f"target/video_name",
|
|
|
334 |
"-codec",
|
335 |
"copy",
|
336 |
f"target/safe_title.video_subtype",
|
337 |
+
]
|
338 |
+
)
|
339 |
unlink.assert_called()
|
340 |
|
341 |
|
342 |
+
@mock.patch("pytube.cli.download_audio")
|
343 |
@mock.patch("pytube.cli.YouTube.__init__", return_value=None)
|
344 |
+
def test_download_audio_args(youtube, download_audio):
|
345 |
+
# Given
|
346 |
parser = argparse.ArgumentParser()
|
347 |
args = parse_args(parser, ["http://youtube.com/watch?v=9bZkp7q19f0", "-a", "mp4"])
|
348 |
cli._parse_args = MagicMock(return_value=args)
|
349 |
+
# When
|
350 |
cli.main()
|
351 |
+
# Then
|
352 |
youtube.assert_called()
|
353 |
+
download_audio.assert_called()
|
354 |
+
|
355 |
+
|
356 |
+
@mock.patch("pytube.cli._download")
|
357 |
+
@mock.patch("pytube.cli.YouTube")
|
358 |
+
def test_download_audio(youtube, download):
|
359 |
+
# Given
|
360 |
+
youtube_instance = youtube.return_value
|
361 |
+
audio_stream = MagicMock()
|
362 |
+
youtube_instance.streams.filter.return_value.order_by.return_value.last.return_value = (
|
363 |
+
audio_stream
|
364 |
+
)
|
365 |
+
# When
|
366 |
+
cli.download_audio(youtube_instance, "filetype", "target")
|
367 |
+
# Then
|
368 |
+
download.assert_called_with(audio_stream, target="target")
|
369 |
|
370 |
|
371 |
@mock.patch("pytube.cli.YouTube.__init__", return_value=None)
|