def split_at(self, splits: list[int], audio: int | list[int] | None = None) -> tuple[SplitTitle, ...]:
# Check if chapters are still valid, user is allowed to manipulated them
last_chpt = -1
for a in self.chapters:
if a < 0:
raise CustomValueError(f'Negative chapter point {a}', self.split_at)
if a <= last_chpt:
raise CustomValueError(f'Chapter must be monotonly increasing {a} before {last_chpt}', self.split_at)
if a > len(self.video):
raise CustomValueError('Chapter must not be higher than video length', self.split_at)
last_chpt = a
output_cnt = SplitHelper._sanitize_splits(self, splits)
video = SplitHelper.split_video(self, splits)
chapters = SplitHelper.split_chapters(self, splits)
audios: list[list[vs.AudioNode | None]]
if audio is not None and (audio := to_arr(audio)):
audio_per_output_cnt = len(audio)
auds = [SplitHelper.split_audio(self, splits, a) for a in audio]
audios = [
[auds[j][i] for j in range(audio_per_output_cnt)] for i in range(output_cnt)
]
else:
audios = [[]] * output_cnt
fromy = 1
from_to_s = list[tuple[int, int]]()
for j in splits:
from_to_s.append((fromy, j - 1))
fromy = j
from_to_s.append((fromy, len(self.chapters) - 1))
return tuple(
SplitTitle(v, a, c, self, f) for v, a, c, f in zip(video, audios, chapters, from_to_s)
)