From 3b9a34f69cfe6e0fe869b3649e24d5c69c321cee Mon Sep 17 00:00:00 2001 From: spoob Date: Sun, 10 Jan 2010 03:23:41 +0100 Subject: added youtube to mp3 converter --- module/plugins/hooks/Mp3Convert.py | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 module/plugins/hooks/Mp3Convert.py diff --git a/module/plugins/hooks/Mp3Convert.py b/module/plugins/hooks/Mp3Convert.py new file mode 100644 index 000000000..d70bb93f6 --- /dev/null +++ b/module/plugins/hooks/Mp3Convert.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . + + @author: mkaay + @interface-version: 0.1 +""" + +from module.plugins.Hook import Hook +from os.path import join, abspath +import subprocess +from os import remove + +class Mp3Convert(Hook): + def __init__(self, core): + Hook.__init__(self, core) + props = {} + props['name'] = "Mp3Convert" + props['version'] = "0.1" + props['description'] = """converts files like videos to mp3""" + props['author_name'] = ("spoob") + props['author_mail'] = ("spoob@pyload.org") + self.props = props + self.readConfig() + + def downloadFinished(self, pyfile): + plugin = pyfile.plugin.props['name'] + if plugin == "YoutubeCom": + filename = pyfile.status.filename[:-4] + cmd = ['ffmpeg -i "%s" -vn -ar 44100 -ac 2 -ab 192k "%s.mp3"' % (abspath(join(pyfile.folder, pyfile.status.filename)), abspath(join(pyfile.folder, filename)))] + converter = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + converter.wait() + if self.config["removeRegularFile"]: + remove(abspath(join(pyfile.folder, pyfile.status.filename))) + self.logger.info("Mp3Convert: Converterd %s to Mp3" % filename) + + def setup(self): + self.configParser.set(self.props["name"], {"option": "removeRegularFile", "type": "bool", "name": "Remove Regular Files"}, False) -- cgit v1.2.3