yuppity / ttml2srt

Convert TTML subtitles used by Netflix, HBO, CMore and others to SRT format
The Unlicense
75 stars 32 forks source link

timestamps without milliseconds #8

Open jcable opened 1 year ago

jcable commented 1 year ago

Hi, I found an EBU-TT-D file where some timestamps are without milliseconds. I made this small change to accommodate this:

def fraction_timestamp_to_ms(self, timestamp):
    """Convert hh:mm:ss.fraction to milliseconds
    """
    if '.' in timestamp:
      hh, mm, ss, fraction = re.split(r'[:.]', timestamp)
    else:
      hh, mm, ss = re.split(r'[:]', timestamp)
      fraction = '0'
    hh, mm, ss = [int(i) for i in (hh, mm, ss)]
    # Resolution beyond ms is useless for our purposes
    ms = int(fraction[:3])

    return self._scaler(self._hhmmss_to_ms(hh, mm, ss) + ms)