Python视频下载到客户端直接浏览器

发布于 2025-01-20 18:56:08 字数 331 浏览 4 评论 0原文

我遇到了这个Pytube库从YouTube下载视频,现在将视频下载到运行脚本的本地系统中。

我认为:该应用应该首先获取视频并将其存储在服务器中,然后让用户下载它。我不知道这是正确的方法。

很想学习其他方法。...

这是样板板pytube代码:

import pytube

url = 'https://www.youtube.com/watch?v=4SFhwxzfXNc'

youtube = pytube.YouTube(url)
video = youtube.streams.first()
video.download('../Video')

I came across this Pytube library to download videos from YouTube, Now the video gets downloaded to the local system that runs the script but what I want to do is let user click a HTML button on a web app to download that video directly to their system.

What I thought: The app should first get the video and store it in a server and then let users download it. I don't know if this is the right approach.

Would love to learn other approaches....

Here is the boilerplate pytube code:

import pytube

url = 'https://www.youtube.com/watch?v=4SFhwxzfXNc'

youtube = pytube.YouTube(url)
video = youtube.streams.first()
video.download('../Video')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灼痛 2025-01-27 18:56:08

这将根据您的要求在 localhost 上工作,但这不适用于像 heroku 服务器这样的实时服务器。

import pytube

url = 'https://www.youtube.com/watch?v=4SFhwxzfXNc'

youtube = pytube.YouTube(url)
video = youtube.streams.first()
video.download(os.path.expanduser("~/Downloads")```

This will work on localhost as your requirements but this won't work on live server like heroku server.

import pytube

url = 'https://www.youtube.com/watch?v=4SFhwxzfXNc'

youtube = pytube.YouTube(url)
video = youtube.streams.first()
video.download(os.path.expanduser("~/Downloads")```
落叶缤纷 2025-01-27 18:56:08

我正在从事一个类似的项目。这对我有用:

import os
import pytube

url = 'https://www.youtube.com/watch?v=4SFhwxzfXNc'

youtube = pytube.YouTube(url)
video = youtube.streams.first()
video.download(os.path.expanduser("~/Downloads") #Or whatever destination location you want on the user's system

让我知道这是否是您想要的! :)

I'm working on a similar project. This worked for me:

import os
import pytube

url = 'https://www.youtube.com/watch?v=4SFhwxzfXNc'

youtube = pytube.YouTube(url)
video = youtube.streams.first()
video.download(os.path.expanduser("~/Downloads") #Or whatever destination location you want on the user's system

Let me know if this is what you were looking for! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文