【发布时间】:2021-09-09 22:18:50
【问题描述】:
我正在使用PyTube and Flask 构建一个 Youtube 视频下载器。我想要做的是最终用户收到视频文件,但我从不将其存储到服务器中。
目前代码如下:
def download_video():
if request.method == "POST":
url = YouTube(session['link']) # Getting user input
itag = request.form.get("itag") # Getting user input
video = url.streams.get_by_itag(itag)
file = video.download(path) # Downloading the video into a folder
return send_file(file, as_attachment=True)
return redirect(url_for("home"))
代码运行良好,唯一的缺点是它被存储到服务器中,这以后可能会成为问题。
我已经尝试将它下载到 /dev/null/,这在本地似乎可以工作,但是当部署到 Heroku 时,我会得到一个 Internal Server Error。
非常感谢任何输入。谢谢!
【问题讨论】:
标签: flask storage pytube storing-data