YouTube Video Downloader in Python Basic Version – Beginner Project with Code

🎯 Python Project: YouTube Video Downloader (Basic)





In this post, I’ll show you how to build a basic YouTube video downloader in Python using the pytubefix library. It's a perfect mini-project for beginners who want to practice working with third-party libraries, user input, and downloading web content.

✅ Project Overview

This script will:

  • Take a YouTube Video URL
  • Display video details (title, author, duration)
  • Download a reasonably good resolution video (usually 360p or 720p by default)

⚠️ Note: For truly high-resolution (1080p, 4K) downloads, you often need to download video and audio streams separately and merge them. That is an advanced project we will upload this one also soon!

🛠️ Prerequisites

First, install the pytubefix library using pip:

pip install pytubefix

💻 The Python Code


from pytubefix import YouTube
from pytubefix.cli import on_progress

# You can also use input() to take URL from user
# For example:
# url = input("Enter YouTube URL: ")

# Hardcoded URL example
url = "https://youtu.be/pnZ0lAjfFCQ?si=w5GrvuKd6XNLOrIY"

# Clean the URL if it has query parameters
if '?' in url:
    url = url.split('?')[0]

# Create YouTube object
yt = YouTube(url, on_progress_callback=on_progress)

# Print video details
print(f"Title   : {yt.title}")
print(f"Author  : {yt.author}")
print(f"Length  : {yt.length // 60} minutes {yt.length % 60} seconds")

# Get the highest resolution stream available in progressive format
stream = yt.streams.get_highest_resolution()
print(f"Downloading in: {stream.resolution}")

# Download the video
stream.download()
print("\n✅ Download complete!")

🧭 How It Works

  1. Import the Libraries: We use pytubefix to interact with YouTube and on_progress to show a progress bar during download.
  2. Define the URL: You can hardcode it or get it from input(). We clean it by removing extra query parameters to ensure compatibility.
  3. Create a YouTube Object: This object fetches all the video metadata.
  4. Print Video Info: The script displays the video's title, author, and duration in minutes and seconds.
  5. Select the Stream: We get the highest-resolution *progressive* stream available. Note that progressive streams include both video and audio in one file, but max out around 720p.
  6. Download: The video downloads to the current directory with progress displayed in the terminal.

🖥️ Expected Output Example

When you run this script, you might see something like:


Title   : Relaxing Music for Stress Relief
Author  : Calmed By Nature
Length  : 2 minutes 45 seconds
Downloading in: 720p

[####################] 100% Complete

✅ Download complete!

✨ Tips to Extend This Project

  • Take the URL from the user using input().
  • Specify a custom output folder with stream.download(output_path="your_folder").
  • Offer the user choices between audio-only or different resolutions.
  • For full HD and 4K videos: We will Upload Soon!
  • Wrap it in a simple command-line interface or GUI with Tkinter.

This basic project is a great starting point for learning how to automate downloads from YouTube with Python. You can expand it into more advanced features or integrate it into your own apps.


Happy Coding! Feel free to share questions or improvements in the comments!

Previous Post Next Post

Contact Form