mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-22 02:15:12 +00:00
[ffmpeg] Move version detection to utils
This commit is contained in:
parent
c30ae9594c
commit
9580711841
2 changed files with 21 additions and 18 deletions
|
@ -11,6 +11,7 @@
|
|||
compat_subprocess_get_DEVNULL,
|
||||
encodeArgument,
|
||||
encodeFilename,
|
||||
get_exe_version,
|
||||
is_outdated_version,
|
||||
PostProcessingError,
|
||||
prepend_extension,
|
||||
|
@ -19,23 +20,6 @@
|
|||
)
|
||||
|
||||
|
||||
def get_version(executable):
|
||||
""" Returns the version of the specified executable,
|
||||
or False if the executable is not present """
|
||||
try:
|
||||
out, err = subprocess.Popen(
|
||||
[executable, '-version'],
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()
|
||||
except OSError:
|
||||
return False
|
||||
firstline = out.partition(b'\n')[0].decode('ascii', 'ignore')
|
||||
m = re.search(r'version\s+([0-9._-a-zA-Z]+)', firstline)
|
||||
if not m:
|
||||
return u'present'
|
||||
else:
|
||||
return m.group(1)
|
||||
|
||||
|
||||
class FFmpegPostProcessorError(PostProcessingError):
|
||||
pass
|
||||
|
||||
|
@ -61,7 +45,7 @@ def check_version(self):
|
|||
@staticmethod
|
||||
def get_versions():
|
||||
programs = ['avprobe', 'avconv', 'ffmpeg', 'ffprobe']
|
||||
return dict((program, get_version(program)) for program in programs)
|
||||
return dict((p, get_exe_version(p, args=['-version'])) for p in programs)
|
||||
|
||||
@property
|
||||
def _executable(self):
|
||||
|
|
|
@ -1472,6 +1472,25 @@ def check_executable(exe, args=[]):
|
|||
return exe
|
||||
|
||||
|
||||
def get_exe_version(exe, args=['--version'],
|
||||
version_re=r'version\s+([0-9._-a-zA-Z]+)',
|
||||
unrecognized=u'present'):
|
||||
""" Returns the version of the specified executable,
|
||||
or False if the executable is not present """
|
||||
try:
|
||||
out, err = 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 m:
|
||||
return m.group(1)
|
||||
else:
|
||||
return unrecognized
|
||||
|
||||
|
||||
class PagedList(object):
|
||||
def __len__(self):
|
||||
# This is only useful for tests
|
||||
|
|
Loading…
Reference in a new issue