fix for missing filename extension
Browse files- pytube/cli.py +5 -14
- tests/test_cli.py +4 -3
pytube/cli.py
CHANGED
@@ -222,7 +222,7 @@ def _download(
|
|
222 |
stream: Stream, target: Optional[str] = None, filename: Optional[str] = None
|
223 |
) -> None:
|
224 |
filesize_megabytes = stream.filesize // 1048576
|
225 |
-
print(f"{stream.default_filename} | {filesize_megabytes} MB")
|
226 |
stream.download(output_path=target, filename=filename)
|
227 |
sys.stdout.write("\n")
|
228 |
|
@@ -317,7 +317,6 @@ def _ffmpeg_downloader(audio_stream: Stream, video_stream: Stream, target: str)
|
|
317 |
:param Path target:
|
318 |
A valid Path object
|
319 |
"""
|
320 |
-
|
321 |
video_unique_name = _unique_name(
|
322 |
safe_filename(video_stream.title), video_stream.subtype, "video", target=target
|
323 |
)
|
@@ -325,25 +324,17 @@ def _ffmpeg_downloader(audio_stream: Stream, video_stream: Stream, target: str)
|
|
325 |
safe_filename(video_stream.title), audio_stream.subtype, "audio", target=target
|
326 |
)
|
327 |
_download(stream=video_stream, target=target, filename=video_unique_name)
|
|
|
328 |
_download(stream=audio_stream, target=target, filename=audio_unique_name)
|
329 |
|
330 |
-
video_path = os.path.join(target, video_unique_name)
|
331 |
-
audio_path = os.path.join(target, audio_unique_name)
|
332 |
final_path = os.path.join(
|
333 |
target, f"{safe_filename(video_stream.title)}.{video_stream.subtype}"
|
334 |
)
|
335 |
|
336 |
subprocess.run( # nosec
|
337 |
-
[
|
338 |
-
"ffmpeg",
|
339 |
-
"-i",
|
340 |
-
f"{video_path}",
|
341 |
-
"-i",
|
342 |
-
f"{audio_path}",
|
343 |
-
"-codec",
|
344 |
-
"copy",
|
345 |
-
f"{final_path}",
|
346 |
-
]
|
347 |
)
|
348 |
os.unlink(video_path)
|
349 |
os.unlink(audio_path)
|
|
|
222 |
stream: Stream, target: Optional[str] = None, filename: Optional[str] = None
|
223 |
) -> None:
|
224 |
filesize_megabytes = stream.filesize // 1048576
|
225 |
+
print(f"{filename or stream.default_filename} | {filesize_megabytes} MB")
|
226 |
stream.download(output_path=target, filename=filename)
|
227 |
sys.stdout.write("\n")
|
228 |
|
|
|
317 |
:param Path target:
|
318 |
A valid Path object
|
319 |
"""
|
|
|
320 |
video_unique_name = _unique_name(
|
321 |
safe_filename(video_stream.title), video_stream.subtype, "video", target=target
|
322 |
)
|
|
|
324 |
safe_filename(video_stream.title), audio_stream.subtype, "audio", target=target
|
325 |
)
|
326 |
_download(stream=video_stream, target=target, filename=video_unique_name)
|
327 |
+
print("Loading audio...")
|
328 |
_download(stream=audio_stream, target=target, filename=audio_unique_name)
|
329 |
|
330 |
+
video_path = os.path.join(target, f"{video_unique_name}.{video_stream.subtype}")
|
331 |
+
audio_path = os.path.join(target, f"{audio_unique_name}.{audio_stream.subtype}")
|
332 |
final_path = os.path.join(
|
333 |
target, f"{safe_filename(video_stream.title)}.{video_stream.subtype}"
|
334 |
)
|
335 |
|
336 |
subprocess.run( # nosec
|
337 |
+
["ffmpeg", "-i", video_path, "-i", audio_path, "-codec", "copy", final_path,]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
)
|
339 |
os.unlink(video_path)
|
340 |
os.unlink(audio_path)
|
tests/test_cli.py
CHANGED
@@ -403,6 +403,7 @@ def test_ffmpeg_downloader(unique_name, download, run, unlink):
|
|
403 |
audio_stream = MagicMock()
|
404 |
video_stream = MagicMock()
|
405 |
video_stream.id = "video_id"
|
|
|
406 |
video_stream.subtype = "video_subtype"
|
407 |
unique_name.side_effect = ["video_name", "audio_name"]
|
408 |
|
@@ -416,12 +417,12 @@ def test_ffmpeg_downloader(unique_name, download, run, unlink):
|
|
416 |
[
|
417 |
"ffmpeg",
|
418 |
"-i",
|
419 |
-
|
420 |
"-i",
|
421 |
-
|
422 |
"-codec",
|
423 |
"copy",
|
424 |
-
|
425 |
]
|
426 |
)
|
427 |
unlink.assert_called()
|
|
|
403 |
audio_stream = MagicMock()
|
404 |
video_stream = MagicMock()
|
405 |
video_stream.id = "video_id"
|
406 |
+
audio_stream.subtype = "audio_subtype"
|
407 |
video_stream.subtype = "video_subtype"
|
408 |
unique_name.side_effect = ["video_name", "audio_name"]
|
409 |
|
|
|
417 |
[
|
418 |
"ffmpeg",
|
419 |
"-i",
|
420 |
+
"target/video_name.video_subtype",
|
421 |
"-i",
|
422 |
+
"target/audio_name.audio_subtype",
|
423 |
"-codec",
|
424 |
"copy",
|
425 |
+
"target/safe_title.video_subtype",
|
426 |
]
|
427 |
)
|
428 |
unlink.assert_called()
|