From 7b21727285e50b0b050c4ddd70d07542229c5366 Mon Sep 17 00:00:00 2001 From: pants Date: Mon, 21 Sep 2026 14:17:03 -0700 Subject: init --- python/ytdl/download_audio.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 python/ytdl/download_audio.py (limited to 'python/ytdl/download_audio.py') 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") -- cgit v1.2.3