diff --git a/CHANGELOG.md b/CHANGELOG.md index e2d5079..55b641e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. \ No newline at end of file diff --git a/abogen/conversion.py b/abogen/conversion.py index 0be2f26..863a05a 100644 --- a/abogen/conversion.py +++ b/abogen/conversion.py @@ -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() diff --git a/abogen/gui.py b/abogen/gui.py index 6bbc607..544def1 100644 --- a/abogen/gui.py +++ b/abogen/gui.py @@ -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("<>") + 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}.", ) +