# Mechanical call extraction from caption episodes (rules fixed before scoring; see README_youtube.md) import re,sys,datetime as dt,pandas as pd sys.path.insert(0,'scripts'); from subs2txt import load from extract_calls import ACT,SL,TG,CT,CS,first from episodes import PLAN,STK SIDEC=re.compile(r'कॉल|सीई'); SIDEP=re.compile(r'पुट|पीई') def calls(vid,start,gap=120): L=[(t,x) for t,x in load(f'data/subs/{vid}.hi-orig.json3') if 'गोल्ड' not in x and 'क्रूड' not in x and 'बिटकॉइन' not in x] st=dt.datetime.fromisoformat(start) hits=[(t,x) for t,x in L if ACT.search(x) or PLAN.search(x) or any(r.search(x) for r in SL+TG)] eps=[];cur=None for t,x in hits: if cur and t-cur[-1][0]<=gap: cur.append((t,x)) else: cur=[(t,x)]; eps.append(cur) out=[] for e in eps: acts=[(t,x) for t,x in e if ACT.search(x) and not re.search(r'नहीं|मत ',x)] txt=' '.join(x for _,x in e); sl,slt=first(SL,txt); tg,tgt=first(TG,txt) if acts: te=acts[0][0]; tier='ACT' elif PLAN.search(txt) and (sl or tg): te=e[-1][0]; tier='PLAN' else: continue w=' '.join(x for t,x in L if e[0][0]-60<=t<=te+30); nc=len(SIDEC.findall(w)); npp=len(SIDEP.findall(w)) side='CE' if nc>npp else ('PE' if npp>nc else None) stk=STK.search(w); post=[(tt,xx) for tt,xx in L if te