Add chapter marker button, fix f-string, fix contnet before chapter not including

This commit is contained in:
Deniz Şafak
2025-05-04 13:53:03 +03:00
parent 146fcb3c1f
commit 15f1eb7f1e
3 changed files with 25 additions and 3 deletions
+3
View File
@@ -1 +1,4 @@
- Added `Insert chapter marker` button in text editor to insert chapter markers at the current cursor position.
- Fixed `f-string: unmatched '['` error in Voice preview, mentioned in #14
- Fixed the content before first chapter not being included in the output (added handling for initial content).
- Fixed m4b chapter generation opens CMD window in Windows.
+9 -3
View File
@@ -228,6 +228,12 @@ class ConversionThread(QThread):
chapter_splits = list(re.finditer(chapter_pattern, text))
chapters = []
if chapter_splits:
# prepend Introduction for content before first marker
first_start = chapter_splits[0].start()
if first_start > 0:
intro_text = text[:first_start].strip()
if intro_text:
chapters.append(("Introduction", intro_text))
for idx, match in enumerate(chapter_splits):
start = match.end()
end = (
@@ -628,9 +634,9 @@ class ConversionThread(QThread):
f.write(f"[CHAPTER]\n")
f.write(f"TIMEBASE=1/10\n")
# use 10th of second for start/end time
f.write(f"START={int(chapter["start"]*10)}\n")
f.write(f"END={int(chapter["end"]*10)}\n")
f.write(f"title={chapter["chapter"]}\n\n")
f.write(f"START={int(chapter['start']*10)}\n")
f.write(f"END={int(chapter['end']*10)}\n")
f.write(f"title={chapter['chapter']}\n\n")
# call ffmpeg to merge the chapters into the output file
# ffmpeg installed on first call to add_paths()
static_ffmpeg.add_paths()
+13
View File
@@ -358,6 +358,11 @@ class TextboxDialog(QDialog):
self.save_as_button.clicked.connect(self.save_as_text)
self.save_as_button.setToolTip("Save the current text to a file")
self.insert_chapter_btn = QPushButton("Insert Chapter Marker", self)
self.insert_chapter_btn.setToolTip("Insert a chapter marker at the cursor")
self.insert_chapter_btn.clicked.connect(self.insert_chapter_marker)
button_layout.addWidget(self.insert_chapter_btn)
self.cancel_button = QPushButton("Cancel", self)
self.cancel_button.clicked.connect(self.reject)
@@ -444,6 +449,13 @@ class TextboxDialog(QDialog):
except Exception as e:
QMessageBox.critical(self, "Save Error", f"Could not save file:\n{e}")
def insert_chapter_marker(self):
# Insert a fixed chapter marker without prompting
cursor = self.text_edit.textCursor()
cursor.insertText("<<CHAPTER_MARKER:Chapter Title>>")
self.text_edit.setTextCursor(cursor)
self.update_char_count()
class abogen(QWidget):
def __init__(self):
@@ -2126,3 +2138,4 @@ class abogen(QWidget):
"Setting Saved",
f"Maximum words per subtitle set to {value}.",
)