diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-03-26 15:43:58 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-03-26 15:43:58 +0100 |
commit | 25c310da4b7936a184ceacd8f5c3f53580b8fb05 (patch) | |
tree | f7dbbc3dee498b1eac0d6b04a9a874decd7da817 | |
parent | Merge pull request #52 from enkore/stable (diff) | |
parent | YoutubeCom: Fix file naming quirks (diff) | |
download | pyload-25c310da4b7936a184ceacd8f5c3f53580b8fb05.tar.xz |
Merge pull request #53 from enkore/stable
Implement »YoutubeCom: Accept a start time parameter«
-rw-r--r-- | module/plugins/hoster/YoutubeCom.py | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/module/plugins/hoster/YoutubeCom.py b/module/plugins/hoster/YoutubeCom.py index a9fed5638..8b8764367 100644 --- a/module/plugins/hoster/YoutubeCom.py +++ b/module/plugins/hoster/YoutubeCom.py @@ -2,11 +2,34 @@ # -*- coding: utf-8 -*- import re +import subprocess +import os +import os.path from urllib import unquote from module.utils import html_unescape from module.plugins.Hoster import Hoster +def which(program): + """Works exactly like the unix command which + + Courtesy of http://stackoverflow.com/a/377028/675646""" + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + for path in os.environ["PATH"].split(os.pathsep): + path = path.strip('"') + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + + return None + class YoutubeCom(Hoster): __name__ = "YoutubeCom" __type__ = "hoster" @@ -112,7 +135,30 @@ class YoutubeCom(Hoster): #set file name file_suffix = self.formats[fmt][0] if fmt in self.formats else ".flv" file_name_pattern = '<meta name="title" content="(.+?)">' - name = re.search(file_name_pattern, html).group(1).replace("/", "") + file_suffix + name = re.search(file_name_pattern, html).group(1).replace("/", "") pyfile.name = html_unescape(name) - - self.download(url)
\ No newline at end of file + + time = re.search(r"t=((\d+)m)?(\d+)s", pyfile.url) + ffmpeg = which("ffmpeg") + if ffmpeg and time: + m, s = time.groups()[1:] + if not m: + m = "0" + + pyfile.name += " (starting at %s:%s)" % (m, s) + pyfile.name += file_suffix + + filename = self.download(url) + + if ffmpeg and time: + inputfile = filename + "_" + os.rename(filename, inputfile) + + subprocess.call([ + ffmpeg, + "-ss", "00:%s:%s" % (m, s), + "-i", inputfile, + "-vcodec", "copy", + "-acodec", "copy", + filename]) + os.remove(inputfile) |