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:
@@ -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.
|
- Fixed m4b chapter generation opens CMD window in Windows.
|
||||||
@@ -228,6 +228,12 @@ class ConversionThread(QThread):
|
|||||||
chapter_splits = list(re.finditer(chapter_pattern, text))
|
chapter_splits = list(re.finditer(chapter_pattern, text))
|
||||||
chapters = []
|
chapters = []
|
||||||
if chapter_splits:
|
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):
|
for idx, match in enumerate(chapter_splits):
|
||||||
start = match.end()
|
start = match.end()
|
||||||
end = (
|
end = (
|
||||||
@@ -628,9 +634,9 @@ class ConversionThread(QThread):
|
|||||||
f.write(f"[CHAPTER]\n")
|
f.write(f"[CHAPTER]\n")
|
||||||
f.write(f"TIMEBASE=1/10\n")
|
f.write(f"TIMEBASE=1/10\n")
|
||||||
# use 10th of second for start/end time
|
# use 10th of second for start/end time
|
||||||
f.write(f"START={int(chapter["start"]*10)}\n")
|
f.write(f"START={int(chapter['start']*10)}\n")
|
||||||
f.write(f"END={int(chapter["end"]*10)}\n")
|
f.write(f"END={int(chapter['end']*10)}\n")
|
||||||
f.write(f"title={chapter["chapter"]}\n\n")
|
f.write(f"title={chapter['chapter']}\n\n")
|
||||||
# call ffmpeg to merge the chapters into the output file
|
# call ffmpeg to merge the chapters into the output file
|
||||||
# ffmpeg installed on first call to add_paths()
|
# ffmpeg installed on first call to add_paths()
|
||||||
static_ffmpeg.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.clicked.connect(self.save_as_text)
|
||||||
self.save_as_button.setToolTip("Save the current text to a file")
|
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 = QPushButton("Cancel", self)
|
||||||
self.cancel_button.clicked.connect(self.reject)
|
self.cancel_button.clicked.connect(self.reject)
|
||||||
|
|
||||||
@@ -444,6 +449,13 @@ class TextboxDialog(QDialog):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
QMessageBox.critical(self, "Save Error", f"Could not save file:\n{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):
|
class abogen(QWidget):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -2126,3 +2138,4 @@ class abogen(QWidget):
|
|||||||
"Setting Saved",
|
"Setting Saved",
|
||||||
f"Maximum words per subtitle set to {value}.",
|
f"Maximum words per subtitle set to {value}.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user