avoid distutils, no longer in python 3.12
This commit is contained in:
parent
301babd1dd
commit
171059cf45
1 changed files with 16 additions and 3 deletions
19
ox/file.py
19
ox/file.py
|
@ -2,7 +2,6 @@
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
# GPL 2008
|
# GPL 2008
|
||||||
from __future__ import division, print_function
|
from __future__ import division, print_function
|
||||||
from distutils.spawn import find_executable
|
|
||||||
from glob import glob
|
from glob import glob
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
|
@ -39,6 +38,21 @@ EXTENSIONS = {
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def is_exe(fpath):
|
||||||
|
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
||||||
|
|
||||||
|
def which(program):
|
||||||
|
fpath, fname = os.path.split(program)
|
||||||
|
if fpath:
|
||||||
|
if is_exe(program):
|
||||||
|
return program
|
||||||
|
else:
|
||||||
|
for path in os.environ.get("PATH", "").split(os.pathsep):
|
||||||
|
exe_file = os.path.join(path, program)
|
||||||
|
if is_exe(exe_file):
|
||||||
|
return exe_file
|
||||||
|
return None
|
||||||
|
|
||||||
def cmd(program):
|
def cmd(program):
|
||||||
local = os.path.expanduser('~/.ox/bin/%s' % program)
|
local = os.path.expanduser('~/.ox/bin/%s' % program)
|
||||||
if os.path.exists(local):
|
if os.path.exists(local):
|
||||||
|
@ -160,12 +174,11 @@ def avinfo(filename, cached=True):
|
||||||
if cached:
|
if cached:
|
||||||
return cache(filename, 'info')
|
return cache(filename, 'info')
|
||||||
if os.path.getsize(filename):
|
if os.path.getsize(filename):
|
||||||
if find_executable('ffprobe'):
|
if which('ffprobe'):
|
||||||
return ffprobe(filename)
|
return ffprobe(filename)
|
||||||
raise EnvironmentError('could to find ffprobe. please install ffmpeg')
|
raise EnvironmentError('could to find ffprobe. please install ffmpeg')
|
||||||
return {'path': filename, 'size': 0}
|
return {'path': filename, 'size': 0}
|
||||||
|
|
||||||
|
|
||||||
def ffprobe(filename):
|
def ffprobe(filename):
|
||||||
p = subprocess.Popen([
|
p = subprocess.Popen([
|
||||||
cmd('ffprobe'),
|
cmd('ffprobe'),
|
||||||
|
|
Loading…
Reference in a new issue