Skip to content

Instantly share code, notes, and snippets.

@roldan
Created December 26, 2025 23:56
Show Gist options
  • Select an option

  • Save roldan/61e2bee24225f383c9a96b3f1cb5d486 to your computer and use it in GitHub Desktop.

Select an option

Save roldan/61e2bee24225f383c9a96b3f1cb5d486 to your computer and use it in GitHub Desktop.
Download audio from youtube videos
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