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)) 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 = ''