mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Add chapter marker button, fix f-string, fix contnet before chapter not including
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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}.",
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user