mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Ignore metadata and leding/trailing spaces when counting text length
This commit is contained in:
+7
-3
@@ -204,11 +204,15 @@ def save_config(config):
|
|||||||
|
|
||||||
def calculate_text_length(text):
|
def calculate_text_length(text):
|
||||||
# Ignore chapter markers
|
# Ignore chapter markers
|
||||||
text_no_markers = re.sub(r"<<CHAPTER_MARKER:.*?>>", "", text)
|
text = re.sub(r"<<CHAPTER_MARKER:.*?>>", "", text)
|
||||||
|
# Ignore metadata patterns
|
||||||
|
text = re.sub(r"<<METADATA_[^:]+:[^>]*>>", "", text)
|
||||||
# Ignore newlines
|
# Ignore newlines
|
||||||
cleaned_text = text_no_markers.replace("\n", "")
|
text = text.replace("\n", "")
|
||||||
|
# Ignore leading/trailing spaces
|
||||||
|
text = text.strip()
|
||||||
# Calculate character count
|
# Calculate character count
|
||||||
char_count = len(cleaned_text)
|
char_count = len(text)
|
||||||
return char_count
|
return char_count
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user