From 18b4e58606f0871e0f3ce22a838c21493fe610d5 Mon Sep 17 00:00:00 2001 From: Paco8 <5084042+Paco8@users.noreply.github.com> Date: Mon, 15 Nov 2021 17:05:55 +0100 Subject: [PATCH] Get timestamps without hour in vtt files --- src/ttml2ssa.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ttml2ssa.py b/src/ttml2ssa.py index 0f3a8d4..6942979 100644 --- a/src/ttml2ssa.py +++ b/src/ttml2ssa.py @@ -25,7 +25,7 @@ class Ttml2Ssa(object): - VERSION = '0.3.5' + VERSION = '0.3.6' TIME_BASES = [ 'media', @@ -389,11 +389,16 @@ def unescape_text(text): while i < len(lines): line = lines[i].strip() i += 1 - m = re.match(r'(?P\d{2}:\d{2}:\d{2}[\.,]\d{3})\s-->\s(?P\d{2}:\d{2}:\d{2}[\.,]\d{3})(?:.*(line:(?P[0-9.]+?))%)?', line) + #m = re.match(r'(?P\d{2}:\d{2}:\d{2}[\.,]\d{3})\s-->\s(?P\d{2}:\d{2}:\d{2}[\.,]\d{3})(?:.*(line:(?P[0-9.]+?))%)?', line) + m = re.match(r'(?P(\d{2}:)?\d{2}:\d{2}[\.,]\d{3})\s-->\s(?P(\d{2}:)?\d{2}:\d{2}[\.,]\d{3})(?:.*(line:(?P[0-9.]+?))%)?', line) if m: + time1 = m.group('t1').replace(',', '.') + time2 = m.group('t2').replace(',', '.') + if len(time1) == 9: time1 = "00:" + time1 + if len(time2) == 9: time2 = "00:" + time2 entry = {} - entry['ms_begin'] = self._tc.timeexpr_to_ms(m.group('t1').replace(',', '.')) - entry['ms_end'] = self._tc.timeexpr_to_ms(m.group('t2').replace(',', '.')) + entry['ms_begin'] = self._tc.timeexpr_to_ms(time1) + entry['ms_end'] = self._tc.timeexpr_to_ms(time2) entry['position'] = 'top' if m.group('pos') and float(m.group('pos')) < 50 else 'bottom' text = "" while i < len(lines):