mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 05:40:26 +02:00
Fixed cannot access local variable 'is_narrow' error
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
# 1.2.0
|
||||
- Fixed `cannot access local variable 'is_narrow'` error when subtitle format `SRT` was selected, mentioned by @Kinasa0096 in #88.
|
||||
|
||||
# 1.1.9
|
||||
- Fixed the issue where spaces were deleted before punctuation marks while generating subtitles.
|
||||
- Fixed markdown TOC generation breaks when "Replace single newlines" is enabled.
|
||||
|
||||
+26
-17
@@ -554,6 +554,13 @@ class ConversionThread(QThread):
|
||||
merged_subtitle_path = (
|
||||
os.path.splitext(merged_out_path)[0] + f".{file_extension}"
|
||||
)
|
||||
# Default subtitle layout flags/strings so they exist regardless
|
||||
# of whether ASS-specific handling runs. This prevents runtime
|
||||
# errors when non-ASS formats (like SRT) are selected.
|
||||
is_centered = False
|
||||
is_narrow = False
|
||||
merged_subtitle_margin = ""
|
||||
merged_subtitle_alignment_tag = ""
|
||||
if "ass" in subtitle_format:
|
||||
merged_subtitle_file = open(
|
||||
merged_subtitle_path,
|
||||
@@ -705,13 +712,20 @@ class ConversionThread(QThread):
|
||||
chapter_subtitle_path = os.path.join(
|
||||
chapters_out_dir, f"{chapter_filename}.{file_extension}"
|
||||
)
|
||||
# Ensure these variables exist even when not using ASS so
|
||||
# later code can safely reference them.
|
||||
is_centered = False
|
||||
is_narrow = False
|
||||
chapter_subtitle_margin = ""
|
||||
chapter_subtitle_alignment_tag = ""
|
||||
# Open the chapter subtitle file for writing for both SRT and ASS
|
||||
chapter_subtitle_file = open(
|
||||
chapter_subtitle_path,
|
||||
"w",
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
)
|
||||
if "ass" in subtitle_format:
|
||||
chapter_subtitle_file = open(
|
||||
chapter_subtitle_path,
|
||||
"w",
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
)
|
||||
# Minimal ASS header
|
||||
chapter_subtitle_file.write("[Script Info]\n")
|
||||
chapter_subtitle_file.write("Title: Generated by Abogen\n")
|
||||
@@ -734,18 +748,13 @@ class ConversionThread(QThread):
|
||||
is_narrow = subtitle_format in (
|
||||
"ass_narrow",
|
||||
"ass_centered_narrow",
|
||||
)
|
||||
chapter_subtitle_margin = "90" if is_narrow else ""
|
||||
chapter_subtitle_alignment_tag = (
|
||||
f"{{\\an5}}" if is_centered else ""
|
||||
)
|
||||
)
|
||||
chapter_subtitle_margin = "90" if is_narrow else ""
|
||||
chapter_subtitle_alignment_tag = (
|
||||
f"{{\\an5}}" if is_centered else ""
|
||||
)
|
||||
else:
|
||||
chapter_subtitle_file = open(
|
||||
chapter_subtitle_path,
|
||||
"w",
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
)
|
||||
chapter_subtitle_file = None
|
||||
else:
|
||||
chapter_subtitle_path = None
|
||||
chapter_subtitle_file = None
|
||||
|
||||
Reference in New Issue
Block a user