Created
December 26, 2025 23:56
-
-
Save roldan/61e2bee24225f383c9a96b3f1cb5d486 to your computer and use it in GitHub Desktop.
Download audio from youtube videos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import yt_dlp | |
| def download_audio(url): | |
| ydl_opts = { | |
| 'format': 'bestaudio/best', | |
| 'postprocessors': [{ | |
| 'key': 'FFmpegExtractAudio', | |
| 'preferredcodec': 'mp3', | |
| 'preferredquality': '192', # kbps | |
| }], | |
| 'outtmpl': '%(id)s.%(ext)s', | |
| 'noplaylist': True, | |
| } | |
| try: | |
| with yt_dlp.YoutubeDL(ydl_opts) as ydl: | |
| ydl.download([url]) | |
| print("Download complete.") | |
| except Exception as e: | |
| print(f"An error occurred: {e}") | |
| urls = [ | |
| 'https://www.youtube.com/watch?v=xxx', | |
| 'https://www.youtube.com/watch?v=yyy', | |
| 'https://www.youtube.com/watch?v=zzz' | |
| ] | |
| for url in urls: | |
| download_audio(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment