Skip to content

Instantly share code, notes, and snippets.

@judexzhu
Forked from benzap/youtube2mp3.py
Created June 19, 2021 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save judexzhu/05b60274d0a0c113a42f5ba6e454649c to your computer and use it in GitHub Desktop.
Save judexzhu/05b60274d0a0c113a42f5ba6e454649c to your computer and use it in GitHub Desktop.
Youtube to MP3 Downloader Script
#!/bin/env python
# Requires: youtube_dl module
# Requires: ffmpeg
# Usage:
#
# python youtube2mp3.py <URL>, ...
#
# Example:
#
# python youtube2mp3.py https://www.youtube.com/watch?v=dQw4w9WgXcQ
import youtube_dl
import sys
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
if __name__ == "__main__":
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
filenames = sys.argv[1:]
ydl.download(filenames)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment