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 C:/Users/Download
. If I want to save the video in the desktop, what changes do I need in the code?
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'])
Click the Video Trim icon, which is the icon of a photo with a pencil at the top-center. Drag the left guide to the place you want your clip to begin, and the right guide to where you want your clip to end. Click Save as at the top. Choose a saving location (and name, if you want) and click Save.
Using pytube in a Python script To download a video using the library in a script, you'll need to import the YouTube class from the library and pass an argument of the video URL. From there, you can access the streams and download them.
I found out a really cool python module that allows you to download videos from youtube easily. TO install it:
pip install pytube
Now, You can download your video like this -
from pytube import YouTube yt = YouTube("https://www.youtube.com/watch?v=n06H7OcPd-g") yt = yt.get('mp4', '720p') yt.download('/path/to/download/directory')
Boom, Now you can easily scrape such videos using Python easily; Now, We Drink!
Thanks to @Chiramisu's comment, You can use the following one-liner to download the highest quality video:
YouTube('video_url').streams.first().download('save_path')
For Windows, please specify path with double backslashes ex:
YouTube('video_url').streams.first().download('C:\\Users\\username\\save_path')
If pytube doesn't seem to work for you, try using youtube-dl:
pip install --upgrade youtube-dl
Now Download Videos:
from __future__ import unicode_literals import youtube_dl ydl_opts = {} with youtube_dl.YoutubeDL(ydl_opts) as ydl: ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])
More info on ytdl in python here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With