diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2014-12-14 21:59:59 +0100 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2014-12-14 21:59:59 +0100 |
commit | cae97f6521a846392e665d8743d4c000fb7d7173 (patch) | |
tree | 91d60fa94a86827ba6da12eda92cd27af2f2241c /youtube_dl | |
parent | 6cbf345f28f5950fb274c70be12f5d91679bf787 (diff) |
Improve and test ffmpeg version detection
Diffstat (limited to 'youtube_dl')
-rw-r--r-- | youtube_dl/utils.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 5e92bcc71..f9938616d 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1262,18 +1262,25 @@ def check_executable(exe, args=[]): def get_exe_version(exe, args=['--version'], - version_re=r'version\s+([0-9._-a-zA-Z]+)', - unrecognized='present'): + version_re=None, unrecognized='present'): """ Returns the version of the specified executable, or False if the executable is not present """ try: - out, err = subprocess.Popen( + out, _ = subprocess.Popen( [exe] + args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate() except OSError: return False - firstline = out.partition(b'\n')[0].decode('ascii', 'ignore') - m = re.search(version_re, firstline) + if isinstance(out, bytes): # Python 2.x + out = out.decode('ascii', 'ignore') + return detect_exe_version(out, version_re, unrecognized) + + +def detect_exe_version(output, version_re=None, unrecognized='present'): + assert isinstance(output, compat_str) + if version_re is None: + version_re = r'version\s+([-0-9._a-zA-Z]+)' + m = re.search(version_re, output) if m: return m.group(1) else: |