Download YouTube video using Python to a certain directory

前端 未结 10 2231
醉话见心
醉话见心 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:56

    I guess you are a bit confused, try this code, end to end

        from __future__ import unicode_literals
        import youtube_dl
        import urllib
        import shutil
        ydl_opts = {}
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.download(['https://www.youtube.com/watch?v=n06H7OcPd-g'])
    
        #Moving your source file to destination folder
        source_file = 'C:\Users\Sharmili Nag\Aahatein - Agnee (splitsvilla 4 theme song) Best audio quality-n06H7OcPd-g.mp4'
        destination_folder = 'C:\Users\Sharmili Nag\Desktop\Aahatein - Agnee (splitsvilla 4 theme song) Best audio quality-n06H7OcPd-g.mp4'
        shutil.move(source_file, destination_folder)
    

    In case this code worked out for you, kindly mark the answer as correct.

提交回复
热议问题