♻️ (TFC/__init__.py): initialize chapters with a default first chapter and adjust chapter indexing

This commit is contained in:
Sp4rk.y 2024-07-31 12:42:37 -06:00
parent e1977c60b1
commit 67bec7f817

View File

@ -259,11 +259,14 @@ class TFC(Service):
# Sort the cuepoints # Sort the cuepoints
sorted_cuepoints = sorted(cuepoints, key=lambda x: datetime.strptime(x, "%H:%M:%S.%f")) sorted_cuepoints = sorted(cuepoints, key=lambda x: datetime.strptime(x, "%H:%M:%S.%f"))
chapters = [] chapters = [
for i, cuepoint in enumerate(sorted_cuepoints): Chapter(name="Chapter 1", timestamp="00:00:00.000")
]
for i, cuepoint in enumerate(sorted_cuepoints, start=2):
try: try:
timestamp = datetime.strptime(cuepoint, "%H:%M:%S.%f").time() timestamp = datetime.strptime(cuepoint, "%H:%M:%S.%f").time()
chapters.append(Chapter(name=f"Chapter {i + 1}", timestamp=timestamp.strftime("%H:%M:%S.%f")[:-3])) chapters.append(Chapter(name=f"Chapter {i}", timestamp=timestamp.strftime("%H:%M:%S.%f")[:-3]))
except ValueError: except ValueError:
self.log.warning(f"Invalid cuepoint format: {cuepoint}") self.log.warning(f"Invalid cuepoint format: {cuepoint}")