I'm always excited to take on new projects and collaborate with innovative minds.

Phone

+1 762 259 2814

Website

ahmettasdemir.com

Social Links

Back to resourcesPython · Tools

Download YouTube Videos with Python (yt-dlp)

Here is a clean, ready-to-run Python script that downloads a whole list of YouTube videos in the quality you choose, using the excellent yt-dlp library. Paste your links in a text file, run the script, and you are done.

Downloading YouTube videos with Python and yt-dlp

1. Install the package

yt-dlp is the actively maintained successor to youtube-dl. Install it with pip:

pip install yt-dlp

If you also want the video and audio merged into a single file, you need ffmpeg. Without it, yt-dlp may save audio and video separately. Install ffmpeg from its official releases, or simply drop ffmpeg.exe in the same folder as the script.

2. Prepare your links

Create a plain text file (for example links.txt) and put one YouTube URL per line.

3. The script

Save the following as download.py and run it with python download.py. It will ask for your text file, an output folder and a quality, then download everything.

import os
from yt_dlp import YoutubeDL

def read_urls(file_path):
    """Read one YouTube URL per line from a text file."""
    with open(file_path, "r", encoding="utf-8") as f:
        return [line.strip() for line in f if line.strip()]

def pick_format(quality):
    """Map a friendly quality name to a yt-dlp format string."""
    quality = quality.lower()
    if quality in ("best", "worst"):
        return quality
    height = quality.replace("p", "")
    return f"bestvideo[height<={height}]+bestaudio/best[height<={height}]"

def download(urls, output_dir, quality):
    os.makedirs(output_dir, exist_ok=True)
    options = {
        "format": pick_format(quality),
        "outtmpl": os.path.join(output_dir, "%(title)s.%(ext)s"),
        "merge_output_format": "mp4",
        "ignoreerrors": True,
    }
    with YoutubeDL(options) as ydl:
        ydl.download(urls)

if __name__ == "__main__":
    txt_path = input("Path to the .txt file with YouTube links: ").strip()
    output_dir = input("Folder to save the videos: ").strip()
    quality = input("Quality (best / worst / 1080p / 720p / 480p / 360p): ").strip() or "best"

    links = read_urls(txt_path)
    print(f"Found {len(links)} link(s). Starting download...")
    download(links, output_dir, quality)
    print("Done.")

4. Quality options

Pass any of these when the script asks:

  • best — highest available quality (recommended).
  • 1080p / 720p / 480p / 360p — cap the resolution to keep file sizes down.
  • worst — smallest file, lowest quality.

Only download content you own or have permission to use, and respect YouTube’s Terms of Service. This script is shared for learning and personal use.

© 2026 All Rights Reserved by ahmettasdemir.com.
Your experience on this site will be improved by allowing cookies. Cookie Policy