我试着用yt下载一个youtube视频。python文件通过使用subprocess.Open
函数将视频的URL手动传递到python脚本,从而使用yt下载youtube视频。
import subprocess
from moviepy.editor import *
import os
import moviepy.editor as mp
# Download files through url and saves it in yt-vidoes dir
command = "yt-dlp "
URL = 'https://www.youtube.com/watch?v=C_rsdqKA6ok'
parameters = ' --output yt-videos/%(title)s'
def download_video():
downloading = subprocess.Popen(command + URL)
downloading.wait()
print(downloading.returncode)
download_video()
它在Windows上运行良好,但在Ubuntu上我得到了以下错误:
Traceback (most recent call last):
File "/home/purelogics/Arslan/shorts_bot/moveis/movies.py", line 17, in <module>
download_video()
File "/home/purelogics/Arslan/shorts_bot/moveis/movies.py", line 13, in download_video
downloading = subprocess.Popen(command + URL)
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.10/3.10.8/lib/python3.10/subprocess.py", line 971, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.10/3.10.8/lib/python3.10/subprocess.py", line 1847, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'yt-dlp https://www.youtube.com/watch?v=C_rsdqKA6ok'
发布于 2022-11-17 15:54:55
来自医生们
将一些参数作为序列传递给外部程序的例子是: Popen("/usr/bin/git“、"commit”、"-m“、”修复一个bug“)。在POSIX上,如果args是字符串,则字符串被解释为要执行的程序的名称或路径。但是,只有在不向程序传递参数的情况下才能做到这一点。
因此,您希望将一个列表传递给Popen,其中列表的第一个元素是可执行文件,第二个元素是参数。现在,它正在尝试找到一个名为yt-dlp https://www.youtube.com/watch?v=C_rsdqKA6ok
的文件来执行。
https://stackoverflow.com/questions/74473623
复制相似问题