Update 2022
I no longer Maintains mhyt
library.
you can try youtube_dl
option:
To install:
pip install youtube_dl
# or for faster download and more improvements:
#pip install yt-dlp
And use:
from youtube_dl import YoutubeDL
# or for yt_dlp:
# from yt_dlp import YoutubeDL
ydl_opts = {
'format': 'm4a/bestaudio/best',
'postprocessors': [{ # Extract audio using ffmpeg
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
}]
}
with YoutubeDL() as ydl:
ydl.download(["https://www.youtube.com/watch?v=0BVqFYParRs"])
ORIGINAL ANSWER:
I have created a library that makes it simpler.
To install:
pip install mhyt
# or $ sudo pip install mhyt
And use it like:
from mhyt import yt_download file = "file.mp3" tmp_file =
os.path.splitext(file)[0]+".webm"
yt_download("url","file.format",ismucic=True)