Skip to content

Commit 9c62837

Browse files
authored
Merge pull request #35 from bharateshwq/youtube_playlist_downloader
feat: implement YouTube playlist downloader with mp3/mp4 support
2 parents 8d961ad + b1acfb6 commit 9c62837

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 🎬 YouTube Playlist Downloader
2+
3+
Download all videos from a YouTube playlist using `yt-dlp`.
4+
5+
## ✅ Features
6+
7+
- Downloads entire playlists.
8+
- Supports **MP4** (video) and **MP3** (audio).
9+
- Automatically names files based on video titles.
10+
- Saves to `downloads/mp4` or `downloads/mp3`.
11+
12+
## 📦 Requirements
13+
14+
- Python 3.7+
15+
- `yt-dlp`
16+
- `ffmpeg` (for MP3 conversion)
17+
18+
### Install dependencies:
19+
20+
```bash
21+
pip install yt-dlp
22+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yt-dlp>=2024.4.9
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import os
2+
import sys
3+
import yt_dlp
4+
5+
def download_playlist(playlist_url, download_format):
6+
if download_format not in ['mp3', 'mp4']:
7+
print("Invalid format. Choose 'mp3' or 'mp4'.")
8+
return
9+
10+
output_dir = os.path.join("downloads", download_format)
11+
os.makedirs(output_dir, exist_ok=True)
12+
13+
ydl_opts = {
14+
'outtmpl': os.path.join(output_dir, '%(title)s.%(ext)s'),
15+
'quiet': False,
16+
}
17+
18+
if download_format == 'mp3':
19+
ydl_opts.update({
20+
'format': 'bestaudio/best',
21+
'postprocessors': [{
22+
'key': 'FFmpegExtractAudio',
23+
'preferredcodec': 'mp3',
24+
'preferredquality': '192',
25+
}],
26+
})
27+
elif download_format == 'mp4':
28+
ydl_opts.update({
29+
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4',
30+
'merge_output_format': 'mp4',
31+
})
32+
33+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
34+
ydl.download([playlist_url])
35+
36+
37+
if __name__ == "__main__":
38+
if len(sys.argv) < 3:
39+
print("Usage: python download_playlist.py <playlist_url> <mp3|mp4>")
40+
sys.exit(1)
41+
42+
playlist_url = sys.argv[1]
43+
download_format = sys.argv[2].lower()
44+
download_playlist(playlist_url, download_format)
45+

0 commit comments

Comments
 (0)