Created
November 6, 2016 17:46
-
-
Save mxwell/f3924afb098186e699192c4594bcc7f3 to your computer and use it in GitHub Desktop.
Wrapped configuration of youtube_dl, that worked on OS based on Ubuntu 14.04
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
#! /usr/bin/env python3 | |
import argparse | |
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 ...') | |
def get_mp3(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([url.replace("https://", "http://")]) | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("url") | |
args = parser.parse_args() | |
print("handling url %s" % args.url) | |
get_mp3(args.url) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment