Skip to content

Commit

Permalink
Get timestamps without hour in vtt files
Browse files Browse the repository at this point in the history
  • Loading branch information
Paco8 committed Nov 15, 2021
1 parent 2026b0a commit 18b4e58
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/ttml2ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

class Ttml2Ssa(object):

VERSION = '0.3.5'
VERSION = '0.3.6'

TIME_BASES = [
'media',
Expand Down Expand Up @@ -389,11 +389,16 @@ def unescape_text(text):
while i < len(lines):
line = lines[i].strip()
i += 1
m = re.match(r'(?P<t1>\d{2}:\d{2}:\d{2}[\.,]\d{3})\s-->\s(?P<t2>\d{2}:\d{2}:\d{2}[\.,]\d{3})(?:.*(line:(?P<pos>[0-9.]+?))%)?', line)
#m = re.match(r'(?P<t1>\d{2}:\d{2}:\d{2}[\.,]\d{3})\s-->\s(?P<t2>\d{2}:\d{2}:\d{2}[\.,]\d{3})(?:.*(line:(?P<pos>[0-9.]+?))%)?', line)
m = re.match(r'(?P<t1>(\d{2}:)?\d{2}:\d{2}[\.,]\d{3})\s-->\s(?P<t2>(\d{2}:)?\d{2}:\d{2}[\.,]\d{3})(?:.*(line:(?P<pos>[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):
Expand Down

0 comments on commit 18b4e58

Please # to comment.