Download YouTube video using Python to a certain directory

前端 未结 10 2234
醉话见心
醉话见心 2020-12-07 17:08

I have tried the following code to download a video in YouTube and it is working, but I want to save the video at a particular location. Now it is saving the video in

10条回答
  •  死守一世寂寞
    2020-12-07 17:42

    downloading videos from youtube in python 3.x for the reference you can check https://python-pytube.readthedocs.io/en/latest/user/quickstart.html#downloading-a-video

    from pytube import YouTube
    import os
    
    def downloadYouTube(videourl, path):
    
        yt = YouTube(videourl)
        yt = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
        if not os.path.exists(path):
            os.makedirs(path)
        yt.download(path)
    
    downloadYouTube('https://www.youtube.com/watch?v=zNyYDHCg06c', './videos/FindingNemo1')
    

提交回复
热议问题