summaryrefslogtreecommitdiff
path: root/python/ytdl/download_audio.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/ytdl/download_audio.py')
-rw-r--r--python/ytdl/download_audio.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/python/ytdl/download_audio.py b/python/ytdl/download_audio.py
new file mode 100644
index 0000000..5f6bd74
--- /dev/null
+++ b/python/ytdl/download_audio.py
@@ -0,0 +1,33 @@
+import yt_dlp
+import os
+
+def download_and_convert_to_opus(url, output_filename):
+ # Use yt-dlp to download the video with audio only
+ ydl_opts = {
+ 'format': 'bestaudio/best',
+ 'outtmpl': '%(extractor)s-%(id)s.%(ext)s', # Save as a temporary file
+ 'restrictfilenames': True,
+ }
+
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
+ info_dict = ydl.extract_info(url, download=True)
+ temp_file = ydl.prepare_filename(info_dict)
+
+ # Convert to OPUS using FFmpeg
+ ffmpeg_command = [
+ 'ffmpeg',
+ '-i', temp_file,
+ '-c:a', 'libopus',
+ '-b:a', '128k',
+ output_filename
+ ]
+
+ os.system(' '.join(ffmpeg_command))
+
+ # Clean up the temporary file
+ os.remove(temp_file)
+
+# Example usage:
+url = input("input video url: ")
+filename = input("filename for ripped audio: ")
+download_and_convert_to_opus(url, filename + ".opus")