Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix subtitle merge of an empty caption #238

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions pycaption/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
17 changes: 9 additions & 8 deletions pycaption/srt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down