-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyt2mp3.py
More file actions
43 lines (37 loc) · 1.02 KB
/
yt2mp3.py
File metadata and controls
43 lines (37 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# github.com/OneDevelopmentPL
import argparse
import yt_dlp
import sys
import os
parser = argparse.ArgumentParser(description="Download YouTube audio as MP3")
parser.add_argument("--url", required=True, help="YouTube video URL")
args = parser.parse_args()
print("[INFO] Starting YouTube audio download...")
print(f"[INFO] URL: {args.url}")
ydl_opts = {
"format": "bestaudio/best",
"noplaylist": True,
"outtmpl": "%(title)s.%(ext)s",
"remote_components": ["ejs:github"],
"quiet": False,
"no_warnings": False,
"force_ipv4": True,
"extractor_args": {
"youtube": {
"player_client": ["web"]
}
},
"postprocessors": [{
"key": "FFmpegExtractAudio",
"preferredcodec": "mp3",
"preferredquality": "192",
}],
}
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([args.url])
except Exception as e:
print("[ERROR] Download failed.")
print(f"[DETAILS] {e}")
sys.exit(1)
print("[SUCCESS] MP3 download completed successfully.")