Compare commits
No commits in common. "3574be2975bca8fbc1a42634e79e4ee9a088054a" and "03c119155081f7b9f65e1f55d3a58708c9dc6704" have entirely different histories.
3574be2975
...
03c1191550
2 changed files with 48 additions and 17 deletions
45
ox/file.py
45
ox/file.py
|
|
@ -159,9 +159,50 @@ 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)
|
||||||
raise EnvironmentError('could to find ffprobe. please install ffmpeg')
|
ffmpeg2theora = cmd('ffmpeg2theora')
|
||||||
return {'path': filename, 'size': 0}
|
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}
|
||||||
|
|
||||||
def ffprobe(filename):
|
def ffprobe(filename):
|
||||||
p = subprocess.Popen([
|
p = subprocess.Popen([
|
||||||
|
|
|
||||||
20
ox/srt.py
20
ox/srt.py
|
|
@ -63,6 +63,10 @@ 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()
|
||||||
|
|
@ -73,21 +77,7 @@ 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 []
|
return srt
|
||||||
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