Siddesh
Siddesh

Reputation: 199

Python Video Download to client's browser directly

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')

Upvotes: 1

Views: 1560

Answers (2)

user16342343
user16342343

Reputation:

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")```

Upvotes: 1

watakushi
watakushi

Reputation: 51

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! :)

Upvotes: 0

Related Questions