public static Caption ParseSrt(string[] Buffer) { Caption cap=new Caption(); Section sec=new Section(); for (int i=0;i<Buffer.Length;i++) { if (Buffer[i]=="") continue; if (Buffer[i].IndexOf(Pub.SrtSymbol)>-1) { sec=ExtractSrtSection(Buffer[i]); cap.Add(sec); } else { try { int.Parse(Buffer[i]); } catch { if (sec.Items.Count==0) sec.StyleFormat=ExtractStyle(ref Buffer[i]); sec.Items.Add(Buffer[i]); } } } return cap; }
private static Section ExtractSrtSection(string line) { Section sec=null; line=line.Replace(",","."); int i=line.IndexOf(Pub.SrtSymbol); if (i>-1) { sec=new Section(); sec.BeginTime=ParseTime(line.Substring(0,i)); sec.EndTime=ParseTime(line.Substring(i+Pub.SrtSymbol.Length)); } return sec; }
private string TimeMerge() { Caption ct=new Caption(); ct.AutoWrap=false; int index1,index2; int lockType;//0 no, 1 cap1, 2 cap2 lockType=index1=index2=0; DateTime capTime1=new DateTime(),capTime2=new DateTime(); while (index1<cap1.Count||index2<cap2.Count) { Section st=new Section(); if (lockType!=1&&index1<cap1.Count) capTime1=cap1[index1].GetBeginTime(); if (lockType!=2&&index2<cap2.Count) capTime2=cap2[index2].GetBeginTime(); lockType=0; if (capTime1>capTime2&&capTime1>capTime2.Add(TimeIgnore)&&index2<cap2.Count||index1==cap1.Count) lockType=1; if (capTime2>capTime1&&capTime2>capTime1.Add(TimeIgnore)&&index1<cap1.Count||index2==cap2.Count) lockType=2; if (lockType!=1) { st=cap1[index1++].Copy(); if (this.isRepeatHead||lockType==2) ct.Add(st); } if (lockType!=2) { addText(ref st,cap2[index2]); ct.Add(st); index2++; } } return ct.ToString(); }
public Section Copy() { Section st=new Section(); st.BeginTime=this.BeginTime; st.EndTime=this.EndTime; st.StyleFormat=this.StyleFormat; st.TimeBaseLine=this.TimeBaseLine; if (Pub.AutoWrap) st.Items.Add(this.Text(true,false)); else { for (int i=0;i<this.Items.Count;i++) st.Items.Add(this.Items[i].ToString()); } return st; }
public void Add(Section Section) { list.Add(Section); adjustLastIndex=buildLastIndex=list.Count-1; }
private static Section ExtractSsaSection(string line) { Section sec=null; if (line.IndexOf(Pub.SsaSymbol)>-1) { string [] split=line.Split(Pub.SsaLimit.ToCharArray(),10); sec=new Section(); sec.BeginTime=System.DateTime.Parse(split[1]); sec.EndTime=System.DateTime.Parse(split[2]); sec.StyleFormat=ExtractStyle(ref split[9]); split[9]=split[9].Replace(@"\N",@"\n"); int i; while ((i=split[9].IndexOf(@"\n"))>-1) { sec.Items.Add(split[9].Substring(0,i)); split[9]=split[9].Substring(i+2); } sec.Items.Add(split[9]); } return sec; }
private string BlockMerge() { Caption ct=new Caption(); ct.AutoWrap=false; int max=cap1.Count>cap2.Count?cap1.Count:cap2.Count; for (int i=0;i<max;i++) { Section st=new Section(); if (i<cap1.Count) { st=cap1[i].Copy(); if (this.isRepeatHead||i>=cap2.Count) ct.Add(st); } if (i<cap2.Count) { addText(ref st,cap2[i]); ct.Add(st); } } return ct.ToString(); }
private void addText(ref Section st,Section sec) { if (this.isRepeatHead||st.Items.Count==0) st=sec.Copy(); else { if (isSecondTime) { st.BeginTime=sec.BeginTime; st.EndTime=sec.EndTime; st.TimeBaseLine=sec.TimeBaseLine; } if (isSecondFront) { if (Pub.AutoWrap) st.Items.Insert(0,sec.Text(true,false)); else st.Items.InsertRange(0,sec.Items); } else { if (Pub.AutoWrap) st.Items.Add(sec.Text(true,false)); else st.Items.AddRange(sec.Items); } } }