Commit
·
bb622c9
1
Parent(s):
996b2e8
try working yewtube it again
Browse files
main.py
CHANGED
|
@@ -80,27 +80,35 @@ def download_audio_bytes(youtube_url: str) -> bytes:
|
|
| 80 |
"""
|
| 81 |
Downloads the best audio-only format from a YouTube URL using yt-dlp and returns the raw audio data as bytes.
|
| 82 |
"""
|
| 83 |
-
#
|
| 84 |
-
video_id = youtube_url.split("v=")[-1]
|
| 85 |
-
# force an Invidious URL
|
| 86 |
-
safe_url = f"https://yewtu.be/watch?v={video_id}"
|
| 87 |
|
|
|
|
|
|
|
| 88 |
print(f"⟳ downloading via Invidious: {safe_url}")
|
| 89 |
|
| 90 |
-
|
| 91 |
ydl_opts = {
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
}
|
| 105 |
|
| 106 |
buffer = io.BytesIO() # Create an in-memory binary buffer
|
|
|
|
| 80 |
"""
|
| 81 |
Downloads the best audio-only format from a YouTube URL using yt-dlp and returns the raw audio data as bytes.
|
| 82 |
"""
|
| 83 |
+
# pull the video ID off the YouTube URL
|
| 84 |
+
video_id = youtube_url.split("v=")[-1].split("&")[0]
|
|
|
|
|
|
|
| 85 |
|
| 86 |
+
# build a *pure* Invidious URL
|
| 87 |
+
safe_url = f"https://yewtu.be/watch?v={video_id}"
|
| 88 |
print(f"⟳ downloading via Invidious: {safe_url}")
|
| 89 |
|
| 90 |
+
# minimal yt‑dlp opts that force the Invidious extractor
|
| 91 |
ydl_opts = {
|
| 92 |
+
"format": "bestaudio/best",
|
| 93 |
+
"noplaylist": True,
|
| 94 |
+
"quiet": True,
|
| 95 |
+
"no_warnings": True,
|
| 96 |
+
# spoof a browser
|
| 97 |
+
"http_headers": {
|
| 98 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
|
| 99 |
+
},
|
| 100 |
+
# tell yt-dlp “you’re Invidious, not YouTube”
|
| 101 |
+
"extractor_args": {
|
| 102 |
+
"invidious": {
|
| 103 |
+
"server": "https://yewtu.be"
|
| 104 |
+
}
|
| 105 |
+
},
|
| 106 |
+
# if you have ffmpeg installed, pull out mp3
|
| 107 |
+
"postprocessors": [{
|
| 108 |
+
"key": "FFmpegExtractAudio",
|
| 109 |
+
"preferredcodec": "mp3",
|
| 110 |
+
"preferredquality": "128",
|
| 111 |
+
}],
|
| 112 |
}
|
| 113 |
|
| 114 |
buffer = io.BytesIO() # Create an in-memory binary buffer
|