【发布时间】:2021-05-23 23:28:53
【问题描述】:
我正在尝试使用 youtube-dl Python API 使用 Flask 构建 YouTube 下载器。我一切正常,但我在实际下载视频时遇到了问题。
@app.route("/pytube/video/", methods=["POST", "GET"])
def pytube_video():
if request.method == "POST":
pytube_download("https://www.youtube.com/watch?v=kFZ-pW4G-s8", "313")
return send_file("./videos/test.mp4", as_attachment=True)
@app.route("/pytube/download/", methods=["POST", "GET"])
def pytube_download(url, format_id):
options = {
'format': format_id,
"outtmpl": "./videos/test.mp4",
}
with youtube_dl.YoutubeDL(options) as y:
y.download([url])
此过程有效,但可能会很慢,因为我是在本地下载视频然后发送它们。有没有办法让用户以更直接的方式下载视频,而不需要先在后端下载?
【问题讨论】:
标签: python python-3.x flask youtube-dl