Fixed subtitle splitting before commas

This commit is contained in:
Deniz Şafak
2025-09-17 20:14:26 +03:00
parent a074b8b0ad
commit 9e9561988d
2 changed files with 24 additions and 21 deletions
+1
View File
@@ -3,6 +3,7 @@
- Added new option `Configure silence between chapters` that lets you configure the silence between chapters, mentioned by @lfperez1982 in #79
- Better indicators while displaying and managing the input and processing files.
- Improved the markdown logic to better handle various markdown structures and cases.
- Fixed subtitle splitting before commas by combining punctuation with preceding words.
- Fixed save options not working correctly in queue mode, mentioned by @jborza in #78
- Fixed `No Qt platform plugin could be initialized` error, mentioned by @sunrainxyz in #59
- Fixed ordered list numbers not being included in EPUB content conversion. The numbers are now properly included in the converted content, mentioned by @jefro108 in #47
+23 -21
View File
@@ -1189,13 +1189,32 @@ class ConversionThread(QThread):
if not tokens_with_timestamps:
return
# Always combine punctuation with preceding words for consistent handling across modes
processed_tokens = []
i = 0
while i < len(tokens_with_timestamps):
token = tokens_with_timestamps[i].copy()
# Look ahead for punctuation
while i + 1 < len(tokens_with_timestamps) and re.match(
r"^[^\w\s]+$", tokens_with_timestamps[i + 1]["text"]
):
token["text"] += tokens_with_timestamps[i + 1]["text"]
token["end"] = tokens_with_timestamps[i + 1]["end"]
token["whitespace"] = tokens_with_timestamps[i + 1]["whitespace"]
i += 1
processed_tokens.append(token)
i += 1
# Use processed_tokens instead of tokens_with_timestamps for the rest of the method
if self.subtitle_mode == "Sentence + Highlighting":
# Sentence-based processing with karaoke highlighting
separator = r"[.!?]"
current_sentence = []
word_count = 0
for token in tokens_with_timestamps:
for token in processed_tokens: # Updated to use processed_tokens
current_sentence.append(token)
word_count += 1
@@ -1249,7 +1268,7 @@ class ConversionThread(QThread):
current_sentence = []
word_count = 0
for token in tokens_with_timestamps:
for token in processed_tokens: # Updated to use processed_tokens
current_sentence.append(token)
word_count += 1
@@ -1299,25 +1318,7 @@ class ConversionThread(QThread):
except (ValueError, IndexError):
word_count = 1
# Combine punctuation with preceding words
processed_tokens = []
i = 0
while i < len(tokens_with_timestamps):
token = tokens_with_timestamps[i].copy()
# Look ahead for punctuation
while i + 1 < len(tokens_with_timestamps) and re.match(
r"^[^\w\s]+$", tokens_with_timestamps[i + 1]["text"]
):
token["text"] += tokens_with_timestamps[i + 1]["text"]
token["end"] = tokens_with_timestamps[i + 1]["end"]
token["whitespace"] = tokens_with_timestamps[i + 1]["whitespace"]
i += 1
processed_tokens.append(token)
i += 1
# Group words into subtitle entries
# Group words into subtitle entries (processed_tokens already has punctuation combined)
for i in range(0, len(processed_tokens), word_count):
group = processed_tokens[i : i + word_count]
if group:
@@ -1334,6 +1335,7 @@ class ConversionThread(QThread):
if end is None or end <= start or end <= 0:
subtitle_entries[-1] = (start, fallback_end_time, text)
def cancel(self):
self.cancel_requested = True
self.should_cancel = True