Skip to content

Downloading a Video

The YouTube DL Scraper allows you to scrape and download videos from multiple YouTube downloader websites. This guide demonstrates how to download a video using the scraper.

Import the YouTube Classe

To begin, import the necessary classes from the package:

from youtube_dl_scraper import YouTube
Alternatively

You cam import the YouTube class in other ways

from youtube_dl_scraper.core import YouTube
from youtube_dl_scraper.core.youtube import YouTube

Next intilize the YouTube Object

youtube = YouTube()
Tip

You can select the scrapers to use:

You can select the video scraper to use by using the video_scraper_name1 argument

youtube = YouTube(video_scraper_name="y2save")

You can select the caption scraper to use by using the caption_scraper_name2 argument

youtube = YouTube(caption_scraper_name="downsub")

Now lets download a video for this example we'll download: Coding levels explaind by thedevgeniusyt .

video = youtube.scrape_video('https://youtu.be/dhlx4hGmgPY?si=3LOCbAqotNz3w0Ab')

Now we have a Video Object which contains video data This makes it easy for us to get the video infomation like title, duration e.t.c

print(video.title) # (1)!
print(video.duration) # (2)!
print(video.fduration) # (3)!
print(video.thumbnail) # (4)!
  1. Output: 'coding levels explained:what makes a beginner, intermediate and expert programmer?'
  2. Output: 185
  3. Output: '3.08 min'
  4. Output: python 'https://i.ytimg.com/vi/dhlx4hGmgPY/sddefault.jpg'

And to download the highest quality video

# This returns the downloaded file path
print(video.get_highest_resolution().download()) # (1)!
  1. Output: 'coding-levels-explained-what-makes-a-beginner-interm... .mp4'

  1. The curretly avaliable video scrapers are SaveTube and Y2Save

  2. The only curretly avaliable caption scraper is DownSub