"""Auto-subtitle VTT → de-duplicated "MM:SS line" transcript (YouTube rolling captions repeat lines).

usage: python3 vtt2txt.py <file.vtt>   (or import parse())"""
import re,sys
def parse(path):
    txt=open(path,encoding='utf-8').read()
    blocks=re.split(r'\n\n+',txt)
    out=[];last=''
    for b in blocks:
        m=re.search(r'(\d+):(\d+):(\d+)\.(\d+) --> ',b)
        if not m: continue
        t=int(m[1])*3600+int(m[2])*60+int(m[3])
        lines=[re.sub(r'<[^>]+>','',l).strip() for l in b.split('\n')[1:]]
        lines=[l for l in lines if l and '-->' not in l and not l.startswith('align:')]
        for l in lines:
            if l and l!=last and (not out or l not in out[-1][1]):
                out.append((t,l));last=l
    return out
if __name__=='__main__':
    for t,l in parse(sys.argv[1]):
        print(f"{t//60:02d}:{t%60:02d} {l}")
