From 75cfe74877aa41a547b60123f6941b4458239dc1 Mon Sep 17 00:00:00 2001 From: j Date: Sat, 21 Dec 2019 20:18:19 +0200 Subject: [PATCH 1/2] srt fixes --- ox/srt.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ox/srt.py b/ox/srt.py index 5191a55..c29ae8b 100644 --- a/ox/srt.py +++ b/ox/srt.py @@ -63,10 +63,6 @@ def load(filename, offset=0): Returns list with dicts that have in, out, value and id ''' srt = [] - - def parse_time(t): - return offset + ox.time2ms(t.replace(',', '.')) / 1000 - with open(filename, 'rb') as f: encoding = _detect_encoding(f) data = f.read() @@ -77,7 +73,21 @@ def load(filename, offset=0): data = data.decode('latin-1') except: 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') if not data.endswith('\n\n'): From 3574be2975bca8fbc1a42634e79e4ee9a088054a Mon Sep 17 00:00:00 2001 From: j Date: Sat, 21 Dec 2019 20:29:44 +0200 Subject: [PATCH 2/2] don't fall back to ffmpeg2theora --- ox/file.py | 45 ++------------------------------------------- 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/ox/file.py b/ox/file.py index 177ca1f..ec9da4b 100644 --- a/ox/file.py +++ b/ox/file.py @@ -159,51 +159,10 @@ def avinfo(filename, cached=True): if os.path.getsize(filename): if find_executable('ffprobe'): return ffprobe(filename) - ffmpeg2theora = cmd('ffmpeg2theora') - 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 - + raise EnvironmentError('could to find ffprobe. please install ffmpeg') return {'path': filename, 'size': 0} + def ffprobe(filename): p = subprocess.Popen([ cmd('ffprobe'),