skip subtitle segment without segs key, #249

This commit is contained in:
simon 2022-05-28 17:47:21 +07:00
parent caaed252f9
commit e638f8b487
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
1 changed files with 10 additions and 9 deletions

View File

@ -189,9 +189,9 @@ class SubtitleParser:
self.all_cues = [] self.all_cues = []
for idx, event in enumerate(all_events): for idx, event in enumerate(all_events):
if "dDurationMs" not in event: if "dDurationMs" not in event or "segs" not in event:
# some events won't have a duration # some events won't have a duration or segs
print(f"failed to parse event without duration: {event}") print(f"skipping subtitle event without content: {event}")
continue continue
cue = { cue = {
@ -215,15 +215,16 @@ class SubtitleParser:
if flatten: if flatten:
# fix overlapping retiming issue # fix overlapping retiming issue
if "dDurationMs" not in flatten[-1]: last = flatten[-1]
# some events won't have a duration if "dDurationMs" not in last or "segs" not in last:
print(f"failed to parse event without duration: {event}") # some events won't have a duration or segs
print(f"skipping subtitle event without content: {event}")
continue continue
last_end = flatten[-1]["tStartMs"] + flatten[-1]["dDurationMs"] last_end = last["tStartMs"] + last["dDurationMs"]
if event["tStartMs"] < last_end: if event["tStartMs"] < last_end:
joined = flatten[-1]["segs"][0]["utf8"] + "\n" + text joined = last["segs"][0]["utf8"] + "\n" + text
flatten[-1]["segs"][0]["utf8"] = joined last["segs"][0]["utf8"] = joined
continue continue
event.update({"segs": [{"utf8": text}]}) event.update({"segs": [{"utf8": text}]})