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
You should put it inside ydl_opts
:
ydl_opts = {
'outtmpl': os.path.join(download_path, '%(title)s-%(id)s.%(ext)s'),
}
In your case, download_path
should be 'C:/Users/Desktop'
. Use %(title)s.%(ext)s
instead of %(title)s-%(id)s.%(ext)s
if you prefer a file name without video ID.
Or you can just os.chdir(path)
to change the directory to where you want the download to be before you start your download.
from __future__ import unicode_literals
import youtube_dl
import os
ydl_opts = {}
os.chdir('C:/Users/Desktop')
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['https://www.youtube.com/watch?v=n06H7OcPd-g'])