Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

YouTube Downloader with pytubefix

Simple Python CLI to download from YouTube. Uses pytubefix, a maintained fork of pytube. Option 3 now asks you which resolution to grab, then merges the best audio with it.

Features

  • 1. Audio Only: downloads highest bitrate audio, saves as .m4a
  • 2. Video Only: downloads highest resolution MP4 video, no audio
  • 3. Best Quality with choice: lists all available MP4 resolutions, you pick one, then it downloads that video plus best audio and merges to a single MP4 with ffmpeg
  • 4. Progressive: downloads classic YouTube MP4 with audio and video together, max 720p, no ffmpeg needed

Requirements

  • Python 3.8 or newer
  • pip install pytubefix
  • ffmpeg in PATH (required only for option 3)

Installation

pip install pytubefix

Install ffmpeg:

  • Windows: winget install ffmpeg
  • macOS: brew install ffmpeg
  • Linux: sudo apt install ffmpeg

Verify: ffmpeg -version

Usage

python yt_downloader.py
  1. Paste YouTube URL
  2. Choose 1 to 4
  3. If you choose 3, you will see:
Available qualities:
1. 2160p (60fps, avc1)
2. 1440p (60fps, avc1)
3. 1080p (60fps, avc1)
4. 720p (30fps, avc1)
Choose 1-4 [Enter for best 2160p]:

Press Enter for the best, or type 2 for 1440p, etc.

Files go to ./downloads/

What each mode does

1. Audio Only

Selects only_audio streams, orders by abr, downloads first. Renames to .m4a. This is AAC audio, not MP3. To get MP3, run: ffmpeg -i file.m4a file.mp3

2. Video Only

Selects only_video MP4 streams, orders by resolution, downloads first. No audio track included.

3. Best Quality

  • Builds a unique list of MP4 video-only resolutions
  • Lets you pick
  • Downloads best audio separately
  • Checks for ffmpeg first. If missing, it stops and keeps the two files
  • Merges with: ffmpeg -y -i video -i audio -c:v copy -c:a aac -movflags +faststart output.mp4
  • Output name includes resolution: Video Title_1080p.mp4

4. Progressive

Selects progressive MP4 streams. These are pre-merged by YouTube and capped at 720p. If none exist, the script exits with a message.

Output examples

downloads/
  My Song.m4a
  video_only_My Video.mp4
  My Video_2160p.mp4
  My Video_1080p.mp4
  Old Video.mp4

Troubleshooting

  • RegexMatchError or VideoUnavailable: YouTube changed. Update: pip install -U pytubefix
  • ffmpeg not found: option 3 will not merge. Install ffmpeg and ensure it is in PATH
  • No MP4 video-only streams: some videos are VP9 or AV1 only. Remove file_extension="mp4" in the filter to see them, then output to .mkv
  • No progressive stream: common for 1080p and above. Use option 3
  • Slow speeds: YouTube throttles. Try again later or use option 4

Quality notes

YouTube's true best is often VP9 in webm, not H.264 in MP4. This script filters for MP4 for phone compatibility. If you want 4K HDR VP9:

  1. Change filter(only_video=True, file_extension="mp4") to filter(only_video=True)
  2. Change output extension to .mkv
  3. ffmpeg will copy both streams with no re-encode

Legal

Download only content you own or have permission to save. You are responsible for following YouTube Terms of Service and copyright law in Pakistan and your region.

Customizing

  • Change folder: edit out_dir = "downloads"
  • Auto-pick without prompt: set video = unique[resolutions[0]] and skip input
  • Force 1080p max: filter by if int(s.resolution[:-1]) <= 1080

About

Simple Python CLI to download from YouTube. Uses pytubefix, a maintained fork of pytube. Option 3 now asks you which resolution to grab, then merges the best audio with it.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages