Created
November 4, 2025 03:08
-
-
Save lakshyaraj2006/1980f4f3ca7c3ab5420298e9288fa13b to your computer and use it in GitHub Desktop.
Download youtube playlist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| echo Installing a Python package... | |
| pip install yt-dlp | |
| echo Package installation complete. | |
| pause |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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