Skip to content

Instantly share code, notes, and snippets.

@lakshyaraj2006
Created November 4, 2025 03:08
Show Gist options
  • Select an option

  • Save lakshyaraj2006/1980f4f3ca7c3ab5420298e9288fa13b to your computer and use it in GitHub Desktop.

Select an option

Save lakshyaraj2006/1980f4f3ca7c3ab5420298e9288fa13b to your computer and use it in GitHub Desktop.
Download youtube playlist
@echo off
echo Installing a Python package...
pip install yt-dlp
echo Package installation complete.
pause
from yt_dlp import YoutubeDL
import os
def progress_hook(d):
if d['status'] == 'downloading':
total = d.get('total_bytes') or d.get('total_bytes_estimate')
downloaded = d.get('downloaded_bytes', 0)
if total:
percent = downloaded / total * 100
print(f"Downloading {d['filename']}... {percent:.2f}%")
elif d['status'] == 'finished':
print(f"Finished downloading {d['filename']}")
playlist_url = input("Enter Playlist URL: ")
with YoutubeDL({'quiet': True}) as ydl:
info_dict = ydl.extract_info(playlist_url, download=False)
playlist_title = info_dict.get('title', 'Playlist')
entries = info_dict.get('entries', [])
save_dir = playlist_title
os.makedirs(save_dir, exist_ok=True)
ydl_opts = {
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4',
'outtmpl': os.path.join(save_dir, '%(title)s.%(ext)s'),
'noplaylist': True,
'progress_hooks': [progress_hook],
'merge_output_format': 'mp4', # ensures final file is MP4
}
with YoutubeDL(ydl_opts) as ydl:
for entry in entries:
video_url = entry.get('webpage_url')
if video_url:
ydl.download([video_url])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment