A lot of bug fixes and edge cases

This commit is contained in:
Hannes committed 2026-03-22 03:20:45 +01:00
1 parent 58e66996cc
commit 004556c4a7
5 files changed
+237 -106

No files matched your search

+23 -20
View File
@@ -35,32 +35,35 @@ from .intro_outro importme, duration) for each chapter."""
def get_intro_outro(file: Path, length: float = 90.0) -> List[Tuple[float, float]]:
try:
chapters = get_chapters(Path(file))
except:
raise AttributeError(f"{file} has no chapter Marks")
multiplier = 2
min_len = length / multiplier
max_len = length * multiplier
filtered = [
(start, dur) for start, dur in chapters
if min_len <= dur <= max_len
]
while len(filtered) > 2 and multiplier <= 1.1:
multiplier -= 0.1
multiplier = 2
min_len = length / multiplier
max_len = length * multiplier
filtered = [
(start, dur) for start, dur in chapters
if min_len <= dur <= max_len
]
if len(filtered) == 2:
return filtered
elif len(filtered) == 1:
### Found only a Intro or Outro
raise ValueError(f"Could only find one intro or outro:\n{filtered}")
elif len(filtered) == 0:
raise ValueError(f"Found no outro or intro:\n{filtered}")
else:
raise ValueError(f"Found too many intros/outros:\n{filtered}")
while len(filtered) > 2 and multiplier <= 1.1:
multiplier -= 0.1
min_len = length / multiplier
max_len = length * multiplier
filtered = [
(start, dur) for start, dur in chapters
if min_len <= dur <= max_len
]
if len(filtered) == 2:
return filtered
elif len(filtered) == 1:
### Found only a Intro or Outro
raise ValueError(f"Could only find one intro or outro:\n{filtered}")
elif len(filtered) == 0:
raise ValueError(f"Found no outro or intro:\n{filtered}")
else:
raise ValueError(f"Found too many intros/outros:\n{filtered}")
except:
raise AttributeError(f"{file} has no chapter Marks")
### TODO: Find more alternative ways to find intro and outro, possible: https://github.com/aniskip/aniskip-cli
### https://github.com/jonbarrow/open-anime-timestamps?utm_source=chatgpt.com
if __name__ == '__main__':
file = "/home/honney/projects/mkv/output_dir/08.mkv"