From 0d281af269251cf8abd29312c490378cf80fe5eb Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Wed, 1 Nov 2023 20:32:32 +0100 Subject: [PATCH] vapoursynth: Fix lwindex parsing for files with multiple video streams --- automation/vapoursynth/aegisub_vs.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/automation/vapoursynth/aegisub_vs.py b/automation/vapoursynth/aegisub_vs.py index 8e3ed93e8..c05e37d26 100644 --- a/automation/vapoursynth/aegisub_vs.py +++ b/automation/vapoursynth/aegisub_vs.py @@ -127,12 +127,14 @@ streaminfo_re = re.compile(r"Codec=(?P[0-9]+),TimeBase=(?P[0-9\ class LWIndexFrame: pts: int key: int + index: int def __init__(self, raw: list[str]): match1 = lwindex_re1.match(raw[0]) match2 = lwindex_re2.match(raw[1]) if not match1 or not match2: raise ValueError("Invalid lwindex format") + self.index = int(match1.group("Index")) self.pts = int(match1.group("PTS")) self.key = int(match2.group("Key")) @@ -150,11 +152,13 @@ def info_from_lwindex(indexfile: str) -> Dict[str, List[int]]: with open(indexfile, encoding="latin1") as f: index = f.read().splitlines() - indexstart, indexend = index.index("") + 1, index.index("") + # The picture list starts after the last tag + indexstart, indexend = (len(index) - index[::-1].index("")), index.index("") frames = [LWIndexFrame(index[i:i+2]) for i in range(indexstart, indexend, 2)] + frames = [f for f in frames if f.index == 0] # select the first stream frames.sort(key=int) - streaminfo = streaminfo_re.match(index[indexstart - 2]) + streaminfo = streaminfo_re.match(index[index.index("") + 1]) # info of first stream if not streaminfo: raise ValueError("Invalid lwindex format")