Python utility to automate video downloading for offline research and viewing.
Python
yt-dlp, FFmpeg
CLI (Command Line Interface)
Automation, Error Handling, Metadata Parsing
import yt_dlp
ydl_opts = {
'format': 'bestvideo[height<=1080]+bestaudio/best[height<=1080]',
'outtmpl': './videos/%(title)s.%(ext)s',
'merge_output_format': 'mp4',
'quiet': True
}
while True:
link = input("Paste YouTube link here (q to quit): ")
if link.lower() == 'q':
print("Canceled")
break
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(link, download=False)
print(f"Title: {info.get('title')}")
print(f"Channel: {info.get('uploader')}")
print(f"Views: {info.get('view_count')}")
confirm = input("Download this video? (y/n): ").lower()
if confirm == 'y':
print("Downloading...")
ydl.download([link])
print(">>> Download Complete! <<<")
else:
print("Canceled. Let's try another link.")
except Exception as e:
print(f"Error: Could not find that video. ({e})")
The script utilizes yt-dlp for its robust handling of dynamic YouTube headers. I implemented a try/except block to ensure the program remains active even when encountering corrupted strings or bad URLs. Metadata is fetched prior to the download request to provide a user-confirmation gate, preventing unnecessary bandwidth consumption.
This project was born out of a specific need: Offline Education. As a self-taught builder in circuit design and CAD, I often find myself in environments without stable high-speed internet (specifically during my summers guiding in Wyoming).
I use this tool to build a local library of technical lectures, engineering walkthroughs, and coding tutorials. By automating the download of 1080p reference material, I ensure that my learning and technical development continue uninterrupted, regardless of my location or connectivity.