Improve and test ffmpeg version detection
This commit is contained in:
parent
6cbf345f28
commit
cae97f6521
2 changed files with 37 additions and 18 deletions
|
@ -16,39 +16,40 @@ import json
|
||||||
import xml.etree.ElementTree
|
import xml.etree.ElementTree
|
||||||
|
|
||||||
from youtube_dl.utils import (
|
from youtube_dl.utils import (
|
||||||
|
args_to_str,
|
||||||
clean_html,
|
clean_html,
|
||||||
DateRange,
|
DateRange,
|
||||||
|
detect_exe_version,
|
||||||
encodeFilename,
|
encodeFilename,
|
||||||
|
escape_rfc3986,
|
||||||
|
escape_url,
|
||||||
find_xpath_attr,
|
find_xpath_attr,
|
||||||
fix_xml_ampersands,
|
fix_xml_ampersands,
|
||||||
orderedSet,
|
|
||||||
OnDemandPagedList,
|
|
||||||
InAdvancePagedList,
|
InAdvancePagedList,
|
||||||
|
intlist_to_bytes,
|
||||||
|
js_to_json,
|
||||||
|
limit_length,
|
||||||
|
OnDemandPagedList,
|
||||||
|
orderedSet,
|
||||||
parse_duration,
|
parse_duration,
|
||||||
|
parse_filesize,
|
||||||
|
parse_iso8601,
|
||||||
read_batch_urls,
|
read_batch_urls,
|
||||||
sanitize_filename,
|
sanitize_filename,
|
||||||
shell_quote,
|
shell_quote,
|
||||||
smuggle_url,
|
smuggle_url,
|
||||||
str_to_int,
|
str_to_int,
|
||||||
|
strip_jsonp,
|
||||||
struct_unpack,
|
struct_unpack,
|
||||||
timeconvert,
|
timeconvert,
|
||||||
unescapeHTML,
|
unescapeHTML,
|
||||||
unified_strdate,
|
unified_strdate,
|
||||||
unsmuggle_url,
|
unsmuggle_url,
|
||||||
|
uppercase_escape,
|
||||||
url_basename,
|
url_basename,
|
||||||
urlencode_postdata,
|
urlencode_postdata,
|
||||||
xpath_with_ns,
|
|
||||||
parse_iso8601,
|
|
||||||
strip_jsonp,
|
|
||||||
uppercase_escape,
|
|
||||||
limit_length,
|
|
||||||
escape_rfc3986,
|
|
||||||
escape_url,
|
|
||||||
js_to_json,
|
|
||||||
intlist_to_bytes,
|
|
||||||
args_to_str,
|
|
||||||
parse_filesize,
|
|
||||||
version_tuple,
|
version_tuple,
|
||||||
|
xpath_with_ns,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -390,5 +391,16 @@ class TestUtil(unittest.TestCase):
|
||||||
self.assertEqual(version_tuple('10.23.344'), (10, 23, 344))
|
self.assertEqual(version_tuple('10.23.344'), (10, 23, 344))
|
||||||
self.assertEqual(version_tuple('10.1-6'), (10, 1, 6)) # avconv style
|
self.assertEqual(version_tuple('10.1-6'), (10, 1, 6)) # avconv style
|
||||||
|
|
||||||
|
def test_detect_exe_version(self):
|
||||||
|
self.assertEqual(detect_exe_version('''ffmpeg version 1.2.1
|
||||||
|
built on May 27 2013 08:37:26 with gcc 4.7 (Debian 4.7.3-4)
|
||||||
|
configuration: --prefix=/usr --extra-'''), '1.2.1')
|
||||||
|
self.assertEqual(detect_exe_version('''ffmpeg version N-63176-g1fb4685
|
||||||
|
built on May 15 2014 22:09:06 with gcc 4.8.2 (GCC)'''), 'N-63176-g1fb4685')
|
||||||
|
self.assertEqual(detect_exe_version('''X server found. dri2 connection failed!
|
||||||
|
Trying to open render node...
|
||||||
|
Success at /dev/dri/renderD128.
|
||||||
|
ffmpeg version 2.4.4 Copyright (c) 2000-2014 the FFmpeg ...'''), '2.4.4')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -1262,18 +1262,25 @@ def check_executable(exe, args=[]):
|
||||||
|
|
||||||
|
|
||||||
def get_exe_version(exe, args=['--version'],
|
def get_exe_version(exe, args=['--version'],
|
||||||
version_re=r'version\s+([0-9._-a-zA-Z]+)',
|
version_re=None, unrecognized='present'):
|
||||||
unrecognized='present'):
|
|
||||||
""" Returns the version of the specified executable,
|
""" Returns the version of the specified executable,
|
||||||
or False if the executable is not present """
|
or False if the executable is not present """
|
||||||
try:
|
try:
|
||||||
out, err = subprocess.Popen(
|
out, _ = subprocess.Popen(
|
||||||
[exe] + args,
|
[exe] + args,
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()
|
||||||
except OSError:
|
except OSError:
|
||||||
return False
|
return False
|
||||||
firstline = out.partition(b'\n')[0].decode('ascii', 'ignore')
|
if isinstance(out, bytes): # Python 2.x
|
||||||
m = re.search(version_re, firstline)
|
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:
|
if m:
|
||||||
return m.group(1)
|
return m.group(1)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue