dont throw exception for invalid files
This commit is contained in:
parent
75e0ec06f9
commit
f02d42712d
1 changed files with 58 additions and 55 deletions
113
ox/file.py
113
ox/file.py
|
@ -219,63 +219,66 @@ def ffprobe(filename):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
info = {}
|
info = {}
|
||||||
for key in ('duration', 'size', 'bit_rate'):
|
if not 'format' in ffinfo:
|
||||||
info[{
|
info['error'] = 'badfile'
|
||||||
'bit_rate': 'bitrate'
|
else:
|
||||||
}.get(key, key)] = fix_value(key, ffinfo['format'][key])
|
for key in ('duration', 'size', 'bit_rate'):
|
||||||
info['audio'] = []
|
info[{
|
||||||
info['video'] = []
|
'bit_rate': 'bitrate'
|
||||||
info['metadata'] = ffinfo['format'].get('tags', {})
|
}.get(key, key)] = fix_value(key, ffinfo['format'][key])
|
||||||
for s in ffinfo['streams']:
|
info['audio'] = []
|
||||||
tags = s.pop('tags', {})
|
info['video'] = []
|
||||||
language = None
|
info['metadata'] = ffinfo['format'].get('tags', {})
|
||||||
for t in tags:
|
for s in ffinfo['streams']:
|
||||||
if t == 'language':
|
tags = s.pop('tags', {})
|
||||||
language = tags[t]
|
language = None
|
||||||
else:
|
for t in tags:
|
||||||
info['metadata'][t] = tags[t]
|
if t == 'language':
|
||||||
if s.get('codec_type') in ('audio', 'video'):
|
language = tags[t]
|
||||||
stream = {}
|
else:
|
||||||
if language and language != 'und':
|
info['metadata'][t] = tags[t]
|
||||||
stream['language'] = language
|
if s.get('codec_type') in ('audio', 'video'):
|
||||||
keys = [
|
stream = {}
|
||||||
'codec_name',
|
if language and language != 'und':
|
||||||
'width',
|
stream['language'] = language
|
||||||
'height',
|
keys = [
|
||||||
'bit_rate',
|
'codec_name',
|
||||||
'index',
|
'width',
|
||||||
'display_aspect_ratio',
|
'height',
|
||||||
'sample_rate',
|
'bit_rate',
|
||||||
'channels',
|
'index',
|
||||||
]
|
'display_aspect_ratio',
|
||||||
if s['codec_type'] == 'video':
|
'sample_rate',
|
||||||
keys += [
|
'channels',
|
||||||
'sample_aspect_ratio',
|
|
||||||
'r_frame_rate',
|
|
||||||
'pix_fmt',
|
|
||||||
]
|
]
|
||||||
|
if s['codec_type'] == 'video':
|
||||||
|
keys += [
|
||||||
|
'sample_aspect_ratio',
|
||||||
|
'r_frame_rate',
|
||||||
|
'pix_fmt',
|
||||||
|
]
|
||||||
|
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if key in s:
|
if key in s:
|
||||||
stream[{
|
stream[{
|
||||||
'codec_name': 'codec',
|
'codec_name': 'codec',
|
||||||
'bit_rate': 'bitrate',
|
'bit_rate': 'bitrate',
|
||||||
'index': 'id',
|
'index': 'id',
|
||||||
'r_frame_rate': 'framerate',
|
'r_frame_rate': 'framerate',
|
||||||
'sample_rate': 'samplerate',
|
'sample_rate': 'samplerate',
|
||||||
'pix_fmt': 'pixel_format',
|
'pix_fmt': 'pixel_format',
|
||||||
'sample_aspect_ratio': 'pixel_aspect_ratio',
|
'sample_aspect_ratio': 'pixel_aspect_ratio',
|
||||||
}.get(key, key)] = fix_value(key, s[key])
|
}.get(key, key)] = fix_value(key, s[key])
|
||||||
info[s['codec_type']].append(stream)
|
info[s['codec_type']].append(stream)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
#print s
|
#print s
|
||||||
for v in info['video']:
|
for v in info['video']:
|
||||||
k = 'display_aspect_ratio'
|
k = 'display_aspect_ratio'
|
||||||
if not k in v and 'width' in v \
|
if not k in v and 'width' in v \
|
||||||
or (k in v and v[k] == '0:1'):
|
or (k in v and v[k] == '0:1'):
|
||||||
v[k] = '%d:%d' % (v['width'], v['height'])
|
v[k] = '%d:%d' % (v['width'], v['height'])
|
||||||
v['pixel_aspect_ratio'] = '1:1'
|
v['pixel_aspect_ratio'] = '1:1'
|
||||||
info['oshash'] = oshash(filename)
|
info['oshash'] = oshash(filename)
|
||||||
info['path'] = filename
|
info['path'] = filename
|
||||||
return info
|
return info
|
||||||
|
|
Loading…
Reference in a new issue