Warning: Undefined array key "HTTP_REFERER" in /hosting/xtmci/inc/lib.inc.php on line 80
xtmci.com
xtmci

Python: The popular object-oriented high-level programming language

Tue May 12 7:44 pm EDT 2026
xtmci@atomicmail.io

Downloading YouTube videos using Python

Python's yt-dlp module allows you to download YouTube videos in quick and easy steps. First of all, install the module via pip command:

py.exe -m pip install --upgrade pip
py.exe -m pip install yt-dlp

Find out the format ID of the YouTube video you want to download. Run the yt-dlp.exe script with the self-explanatory --list-formats switch and the URL of the video:

yt-dlp.exe --list-formats https://www.youtube.com/watch?v=UAh12th345A
  • --list-formats Lists all available formats for the video.

Write a Python script like the following one:

import yt_dlp

url = 'https://www.youtube.com/watch?v=UAh12th345A'

options = {
  # The format ID you've found earlier.
  # In this case, it's for a 3840x2160 resolution mp4 file.
  'format': '401', 

  # Saves the file as a '(title).(extension)' format.
  'outtmpl': '%(title)s.%(ext)s'
}

# Downloads the file using the options and URL.
yt_dlp.YoutubeDL(options).download([url])