From 7628fb554b6b740fc9ce53f78e93ce5254dd6fec Mon Sep 17 00:00:00 2001 From: enkore Date: Tue, 26 Mar 2013 00:57:37 +0100 Subject: Add module.utils.which --- module/utils.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/module/utils.py b/module/utils.py index 8748b7693..895768cba 100644 --- a/module/utils.py +++ b/module/utils.py @@ -195,6 +195,26 @@ def html_unescape(text): """Removes HTML or XML character references and entities from a text string""" return re.sub("&#?\w+;", fixup, text) +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 + if __name__ == "__main__": print freeSpace(".") -- cgit v1.2.3 From 8c655c6835e864c81d71a0e15a4d79bdb3cdfa1d Mon Sep 17 00:00:00 2001 From: enkore Date: Tue, 26 Mar 2013 01:00:15 +0100 Subject: YoutubeCom: Add support for time specification, if ffmpeg is installed and in PATH --- module/plugins/hoster/YoutubeCom.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/module/plugins/hoster/YoutubeCom.py b/module/plugins/hoster/YoutubeCom.py index a9fed5638..9f21ddf79 100644 --- a/module/plugins/hoster/YoutubeCom.py +++ b/module/plugins/hoster/YoutubeCom.py @@ -2,9 +2,11 @@ # -*- coding: utf-8 -*- import re +import subprocess +import os from urllib import unquote -from module.utils import html_unescape +from module.utils import html_unescape, which from module.plugins.Hoster import Hoster class YoutubeCom(Hoster): @@ -114,5 +116,25 @@ class YoutubeCom(Hoster): file_name_pattern = '' name = re.search(file_name_pattern, html).group(1).replace("/", "") + file_suffix pyfile.name = html_unescape(name) - - self.download(url) \ No newline at end of file + + filename = self.download(url) + + ffmpeg = which("ffmpeg") + if ffmpeg: + time = re.search(r"t=((\d+)m)?(\d+)s", pyfile.url) + if time: + m, s = time.groups()[1:] + if not m: + m = "0" + + inputfile = filename + "_" + os.rename(filename, inputfile) + + subprocess.call([ + which("ffmpeg"), + "-ss", "00:%s:%s" % (m, s), + "-i", inputfile, + "-vcodec", "copy", + "-acodec", "copy", + filename]) + os.remove(inputfile) -- cgit v1.2.3 From 703422d3e7ae56ff74c5ab95a5dd9f5f92a6bd83 Mon Sep 17 00:00:00 2001 From: enkore Date: Tue, 26 Mar 2013 13:41:36 +0100 Subject: Move which function to YoutubeCom plugin --- module/plugins/hoster/YoutubeCom.py | 23 ++++++++++++++++++++++- module/utils.py | 20 -------------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/module/plugins/hoster/YoutubeCom.py b/module/plugins/hoster/YoutubeCom.py index 9f21ddf79..4bc608b05 100644 --- a/module/plugins/hoster/YoutubeCom.py +++ b/module/plugins/hoster/YoutubeCom.py @@ -4,11 +4,32 @@ import re import subprocess import os +import os.path from urllib import unquote -from module.utils import html_unescape, which +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" diff --git a/module/utils.py b/module/utils.py index 895768cba..8748b7693 100644 --- a/module/utils.py +++ b/module/utils.py @@ -195,26 +195,6 @@ def html_unescape(text): """Removes HTML or XML character references and entities from a text string""" return re.sub("&#?\w+;", fixup, text) -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 - if __name__ == "__main__": print freeSpace(".") -- cgit v1.2.3 From fafd901d97eaa80f3d67c92cd95074fa61ed3262 Mon Sep 17 00:00:00 2001 From: enkore Date: Tue, 26 Mar 2013 13:45:29 +0100 Subject: YoutubeCom: Show start time in package name --- module/plugins/hoster/YoutubeCom.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/module/plugins/hoster/YoutubeCom.py b/module/plugins/hoster/YoutubeCom.py index 4bc608b05..f01094c7d 100644 --- a/module/plugins/hoster/YoutubeCom.py +++ b/module/plugins/hoster/YoutubeCom.py @@ -138,24 +138,26 @@ class YoutubeCom(Hoster): name = re.search(file_name_pattern, html).group(1).replace("/", "") + file_suffix pyfile.name = html_unescape(name) + time = re.search(r"t=((\d+)m)?(\d+)s", pyfile.url) + if time: + m, s = time.groups()[1:] + if not m: + m = "0" + + pyfile.name += " (starting at %s:%s)" % (m, s) + filename = self.download(url) ffmpeg = which("ffmpeg") if ffmpeg: - time = re.search(r"t=((\d+)m)?(\d+)s", pyfile.url) - if time: - m, s = time.groups()[1:] - if not m: - m = "0" - - inputfile = filename + "_" - os.rename(filename, inputfile) - - subprocess.call([ - which("ffmpeg"), - "-ss", "00:%s:%s" % (m, s), - "-i", inputfile, - "-vcodec", "copy", - "-acodec", "copy", - filename]) - os.remove(inputfile) + 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) -- cgit v1.2.3 From ba5b01cc56ab2d99f51ee3b6bd21bac90e2c806d Mon Sep 17 00:00:00 2001 From: enkore Date: Tue, 26 Mar 2013 13:48:34 +0100 Subject: YoutubeCom: fix program flow quirks --- module/plugins/hoster/YoutubeCom.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/plugins/hoster/YoutubeCom.py b/module/plugins/hoster/YoutubeCom.py index f01094c7d..ce9fe4945 100644 --- a/module/plugins/hoster/YoutubeCom.py +++ b/module/plugins/hoster/YoutubeCom.py @@ -139,7 +139,8 @@ class YoutubeCom(Hoster): pyfile.name = html_unescape(name) time = re.search(r"t=((\d+)m)?(\d+)s", pyfile.url) - if time: + ffmpeg = which("ffmpeg") + if ffmpeg and time: m, s = time.groups()[1:] if not m: m = "0" @@ -148,8 +149,7 @@ class YoutubeCom(Hoster): filename = self.download(url) - ffmpeg = which("ffmpeg") - if ffmpeg: + if ffmpeg and time: inputfile = filename + "_" os.rename(filename, inputfile) -- cgit v1.2.3 From 1b935cc92a420b264dabe5160c64eba165200c73 Mon Sep 17 00:00:00 2001 From: enkore Date: Tue, 26 Mar 2013 13:50:19 +0100 Subject: YoutubeCom: Fix file naming quirks --- module/plugins/hoster/YoutubeCom.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/plugins/hoster/YoutubeCom.py b/module/plugins/hoster/YoutubeCom.py index ce9fe4945..8b8764367 100644 --- a/module/plugins/hoster/YoutubeCom.py +++ b/module/plugins/hoster/YoutubeCom.py @@ -135,7 +135,7 @@ class YoutubeCom(Hoster): #set file name file_suffix = self.formats[fmt][0] if fmt in self.formats else ".flv" file_name_pattern = '' - 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) time = re.search(r"t=((\d+)m)?(\d+)s", pyfile.url) @@ -146,6 +146,7 @@ class YoutubeCom(Hoster): m = "0" pyfile.name += " (starting at %s:%s)" % (m, s) + pyfile.name += file_suffix filename = self.download(url) -- cgit v1.2.3