Search code examples
pythonpytube

Pytube isn't downloading videos


I have pytube (pytube==12.0.0) installed. When I run my code it just does nothing, and then finishes executing. It doesn't give any errors, but it also doesn't download the video. This might have something to do with the fact that I have a filter installed on my computer, I've had issues with that before when using the heroku cli, because it was using a proxy. I haven't been able to find anything on how to fix that though.

My code is:

import pytube

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

youtube = pytube.YouTube(url)

video = youtube.streams.get_highest_resolution()

video.download('/Downloads')

Solution

  • Stupid mistake - video.download('/Downloads') wasn't the right file path. This is the code that works:

    import pytube
    
    url = 'https://www.youtube.com/watch?v=4SFhwxzfXNc'
    
    youtube = pytube.YouTube(url)
    
    video = youtube.streams.get_highest_resolution()
    
    video.download('C:/Users/user1/Downloads')