From 5d39b6d823095d1801b708c169d9c02b6bc83a57 Mon Sep 17 00:00:00 2001 From: FloridaStream Date: Thu, 1 Jul 2021 20:48:52 -0300 Subject: [PATCH 1/2] Fix subtitle merge of empty caption This fix the error: AttributeError: 'NoneType' object has no attribute 'start' Explaining the error: It is caused because the caption has a blank value, a blank caption with no text, this causes the default code that joins the subtitles to go into error, as it cannot join a received None value, with an existing String value, and ends up breaking the subtitle conversion. Problem example (DFXP/SMPTE xml): ```

Subtitle End

``` --- pycaption/srt.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pycaption/srt.py b/pycaption/srt.py index 89ee0ff8..54b25596 100644 --- a/pycaption/srt.py +++ b/pycaption/srt.py @@ -105,14 +105,15 @@ def _recreate_lang(self, captions): for caption in captions[1:]: # Merge if the timestamp is the same as last caption - if (caption.start, caption.end) == (merged_captions[-1].start, merged_captions[-1].end): - merged_captions[-1] = Caption( - start=caption.start, - end=caption.end, - nodes=merged_captions[-1].nodes + caption.nodes) - else: - # Different timestamp, end of merging, append new caption - merged_captions.append(caption) + if caption != None: + if (caption.start, caption.end) == (merged_captions[-1].start, merged_captions[-1].end): + merged_captions[-1] = Caption( + start=caption.start, + end=caption.end, + nodes=merged_captions[-1].nodes + caption.nodes) + else: + # Different timestamp, end of merging, append new caption + merged_captions.append(caption) captions = merged_captions srt = '' From 53c2dd20c3584bb1172cee960dc181255651014a Mon Sep 17 00:00:00 2001 From: FloridaStream Date: Fri, 2 Jul 2021 00:35:54 -0300 Subject: [PATCH 2/2] Fix merge_concurrent_captions Fix merge of an empty caption --- pycaption/base.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pycaption/base.py b/pycaption/base.py index 2c3df511..134f61fb 100644 --- a/pycaption/base.py +++ b/pycaption/base.py @@ -380,17 +380,18 @@ def merge_concurrent_captions(caption_set): concurrent_captions = CaptionList() merged_captions = CaptionList() for caption in captions: - if last_caption: - last_timespan = last_caption.start, last_caption.end - current_timespan = caption.start, caption.end - if current_timespan == last_timespan: - concurrent_captions.append(caption) - last_caption = caption - continue - else: - merged_captions.append(merge(concurrent_captions)) - concurrent_captions = [caption] - last_caption = caption + if caption != None: + if last_caption: + last_timespan = last_caption.start, last_caption.end + current_timespan = caption.start, caption.end + if current_timespan == last_timespan: + concurrent_captions.append(caption) + last_caption = caption + continue + else: + merged_captions.append(merge(concurrent_captions)) + concurrent_captions = [caption] + last_caption = caption if concurrent_captions: merged_captions.append(merge(concurrent_captions))