Created
July 18, 2019 16:27
-
-
Save dataserver/34aa9ee2ab6daf25a99c1933c71b6b7c to your computer and use it in GitHub Desktop.
python to download youtbe music as mp3
This file contains 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
# require | |
# https://ffmpeg.org/download.html | |
# to convert to .mp3 | |
from __future__ import unicode_literals | |
import youtube_dl | |
class MyLogger(object): | |
def debug(self, msg): | |
pass | |
def warning(self, msg): | |
pass | |
def error(self, msg): | |
print(msg) | |
def my_hook(d): | |
if d['status'] == 'finished': | |
print('Done downloading, now converting ...') | |
inputed_url = input("enter url:") | |
ydl_opts = { | |
'format': 'bestaudio/best', | |
'postprocessors': [{ | |
'key': 'FFmpegExtractAudio', | |
'preferredcodec': 'mp3', | |
'preferredquality': '192', | |
}], | |
'logger': MyLogger(), | |
'progress_hooks': [my_hook], | |
} | |
with youtube_dl.YoutubeDL(ydl_opts) as ydl: | |
ydl.download([inputed_url]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment