From 9cc311ca5376bfcbcacf7ac492f5958acfac0682 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Mon, 19 Oct 2015 21:38:00 +0200 Subject: Added commandline options and config file --- youtube_podcaster/youtube/downloader.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'youtube_podcaster/youtube') diff --git a/youtube_podcaster/youtube/downloader.py b/youtube_podcaster/youtube/downloader.py index ca1327b..529902a 100644 --- a/youtube_podcaster/youtube/downloader.py +++ b/youtube_podcaster/youtube/downloader.py @@ -1,41 +1,44 @@ #!/usr/bin/env python3 -import youtube_dl import os +import mimetypes + +import youtube_dl class Downloader: instance = None def get_instance(file_format, location, base_url): - if Downloader.instance: - return Downloader.instance - else: + if not Downloader.instance: Downloader.instance = Downloader(file_format, location, base_url) - return Downloader.instance + return Downloader.instance def __init__(self, file_format, location, base_url): self.file_format = file_format self.location = location self.base_url = base_url + if file_format == "vorbis": + self.extension = "ogg" + def download(self, video, video_id, feed_id): - output = "%s/%s/%s.ogg" % (self.location, feed_id, video_id) + output = "%s/%s/%s.%s" % (self.location, feed_id, video_id, self.extension) options = {"format": "bestaudio/best", "outtmpl": output, "postprocessors": [{ "key": "FFmpegExtractAudio", "preferredcodec": self.file_format }], - "nooverwrites": True - } + "nooverwrites": True} + video_url = "https://www.youtube.com/watch?v=%s" % (video["snippet"]["resourceId"]["videoId"]) youtube_dl.YoutubeDL(options).download([video_url]) - url = "%s/%s/%s.ogg" % (self.base_url, feed_id, video_id) + url = "%s/%s/%s.%s" % (self.base_url, feed_id, video_id, self.extension) size = str(os.path.getsize(output)) - mime = "audio/ogg" + mime = mimetypes.guess_type(output)[0] return (url, size, mime) -- cgit v1.2.3