diff options
| author | pants <niklasjo2004@gmail.com> | 2026-09-21 14:17:03 -0700 |
|---|---|---|
| committer | pants <niklasjo2004@gmail.com> | 2026-09-21 14:17:03 -0700 |
| commit | 7b21727285e50b0b050c4ddd70d07542229c5366 (patch) | |
| tree | 5d369153c5df5b41f3750d25479a68f20169c8ff /python/ytdl/download_audio.py | |
init
Diffstat (limited to 'python/ytdl/download_audio.py')
| -rw-r--r-- | python/ytdl/download_audio.py | 33 |
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") |
