Compare commits
2 commits
03c1191550
...
3574be2975
| Author | SHA1 | Date | |
|---|---|---|---|
| 3574be2975 | |||
| 75cfe74877 |
2 changed files with 17 additions and 48 deletions
45
ox/file.py
45
ox/file.py
|
|
@ -159,51 +159,10 @@ def avinfo(filename, cached=True):
|
||||||
if os.path.getsize(filename):
|
if os.path.getsize(filename):
|
||||||
if find_executable('ffprobe'):
|
if find_executable('ffprobe'):
|
||||||
return ffprobe(filename)
|
return ffprobe(filename)
|
||||||
ffmpeg2theora = cmd('ffmpeg2theora')
|
raise EnvironmentError('could to find ffprobe. please install ffmpeg')
|
||||||
p = subprocess.Popen([ffmpeg2theora], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
||||||
stdout, error = p.communicate()
|
|
||||||
stdout = stdout.decode('utf-8')
|
|
||||||
version = stdout.split('\n')[0].split(' - ')[0].split(' ')[-1]
|
|
||||||
if version < '0.27':
|
|
||||||
raise EnvironmentError('version of ffmpeg2theora needs to be 0.27 or later, found %s' % version)
|
|
||||||
p = subprocess.Popen([ffmpeg2theora, '--info', filename],
|
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
||||||
stdout, error = p.communicate()
|
|
||||||
stdout = stdout.decode('utf-8')
|
|
||||||
try:
|
|
||||||
info = json.loads(stdout)
|
|
||||||
except:
|
|
||||||
# remove metadata, can be broken
|
|
||||||
reg = re.compile('"metadata": {.*?},', re.DOTALL)
|
|
||||||
stdout = re.sub(reg, '', stdout)
|
|
||||||
info = json.loads(stdout)
|
|
||||||
if 'video' in info:
|
|
||||||
for v in info['video']:
|
|
||||||
if 'display_aspect_ratio' not in v and 'width' in v:
|
|
||||||
v['display_aspect_ratio'] = '%d:%d' % (v['width'], v['height'])
|
|
||||||
v['pixel_aspect_ratio'] = '1:1'
|
|
||||||
if len(info.get('audio', [])) > 1:
|
|
||||||
if 'metadata' in info['audio'][0]:
|
|
||||||
for stream in info['audio']:
|
|
||||||
language = stream.get('metadata', {}).get('language')
|
|
||||||
if language and language != 'und':
|
|
||||||
stream['language'] = language[0]
|
|
||||||
else:
|
|
||||||
ffmpeg = cmd('ffmpeg')
|
|
||||||
p = subprocess.Popen([ffmpeg, '-i', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
||||||
stdout, stderr = p.communicate()
|
|
||||||
stderr = stderr.decode('utf-8')
|
|
||||||
languages = [re.compile('\((.+?)\):').findall(l) for l in stderr.split('\n') if 'Stream' in l and 'Audio' in l]
|
|
||||||
if len(languages) == len(info['audio']):
|
|
||||||
for i, stream in enumerate(info['audio']):
|
|
||||||
language = languages[i]
|
|
||||||
if language and language[0] != 'und':
|
|
||||||
stream['language'] = language[0]
|
|
||||||
fix_coverart(info)
|
|
||||||
return info
|
|
||||||
|
|
||||||
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'),
|
||||||
|
|
|
||||||
20
ox/srt.py
20
ox/srt.py
|
|
@ -63,10 +63,6 @@ def load(filename, offset=0):
|
||||||
Returns list with dicts that have in, out, value and id
|
Returns list with dicts that have in, out, value and id
|
||||||
'''
|
'''
|
||||||
srt = []
|
srt = []
|
||||||
|
|
||||||
def parse_time(t):
|
|
||||||
return offset + ox.time2ms(t.replace(',', '.')) / 1000
|
|
||||||
|
|
||||||
with open(filename, 'rb') as f:
|
with open(filename, 'rb') as f:
|
||||||
encoding = _detect_encoding(f)
|
encoding = _detect_encoding(f)
|
||||||
data = f.read()
|
data = f.read()
|
||||||
|
|
@ -77,7 +73,21 @@ def load(filename, offset=0):
|
||||||
data = data.decode('latin-1')
|
data = data.decode('latin-1')
|
||||||
except:
|
except:
|
||||||
print("failed to detect encoding, giving up")
|
print("failed to detect encoding, giving up")
|
||||||
return srt
|
return []
|
||||||
|
return loads(data, offset)
|
||||||
|
|
||||||
|
def loads(data, offset=0):
|
||||||
|
'''Parses an srt file
|
||||||
|
|
||||||
|
filename: path to an srt file
|
||||||
|
offset (float, seconds): shift all in/out points by offset
|
||||||
|
|
||||||
|
Returns list with dicts that have in, out, value and id
|
||||||
|
'''
|
||||||
|
srt = []
|
||||||
|
|
||||||
|
def parse_time(t):
|
||||||
|
return offset + ox.time2ms(t.replace(',', '.')) / 1000
|
||||||
|
|
||||||
data = data.replace('\r\n', '\n')
|
data = data.replace('\r\n', '\n')
|
||||||
if not data.endswith('\n\n'):
|
if not data.endswith('\n\n'):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue