[BUGFIX] Fix parsing chapters from comments (#592)
This commit is contained in:
parent
1588725bb1
commit
e1242eaa61
1 changed files with 6 additions and 7 deletions
|
|
@ -202,6 +202,7 @@ class Chapters:
|
||||||
timestamps: List[Timestamp] = []
|
timestamps: List[Timestamp] = []
|
||||||
titles: List[str] = []
|
titles: List[str] = []
|
||||||
|
|
||||||
|
# Try to accumulate chapters by parsing lines individually
|
||||||
for line in input_str.split("\n"):
|
for line in input_str.split("\n"):
|
||||||
# Timestamp captured, store it
|
# Timestamp captured, store it
|
||||||
if match := Timestamp.TIMESTAMP_REGEX.search(line):
|
if match := Timestamp.TIMESTAMP_REGEX.search(line):
|
||||||
|
|
@ -211,14 +212,12 @@ class Chapters:
|
||||||
# Remove timestamp and surrounding whitespace from it
|
# Remove timestamp and surrounding whitespace from it
|
||||||
title_str = re.sub(f"\\s*{re.escape(timestamp_str)}\\s*", " ", line).strip()
|
title_str = re.sub(f"\\s*{re.escape(timestamp_str)}\\s*", " ", line).strip()
|
||||||
titles.append(title_str)
|
titles.append(title_str)
|
||||||
elif len(timestamps) >= 3:
|
|
||||||
return Chapters(timestamps=timestamps, titles=titles)
|
|
||||||
# Timestamp was not stored, if only contained 1, reset
|
|
||||||
else:
|
|
||||||
timestamps = []
|
|
||||||
titles = []
|
|
||||||
|
|
||||||
return Chapters(timestamps=timestamps, titles=titles)
|
# If more than 3 timestamps were parsed, return it
|
||||||
|
if len(timestamps) >= 3:
|
||||||
|
return Chapters(timestamps=timestamps, titles=titles)
|
||||||
|
# Otherwise return empty chapters
|
||||||
|
return Chapters(timestamps=[], titles=[])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_entry_chapters(cls, entry: Entry) -> "Chapters":
|
def from_entry_chapters(cls, entry: Entry) -> "Chapters":
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue