public Subtitle RemoveChinese(Subtitle subtitle) { var newSrts = new Dictionary<int, SubtitleLine>(); var srts = subtitle.Bodies; for (int i = 1; i <= subtitle.Bodies.Count; i++) { var subtitleLine = srts[i]; var lines = subtitleLine.Text.Split(new string[] { "\r","\n","\\N" }, StringSplitOptions.RemoveEmptyEntries); IList<string> newLines = new List<string>(); foreach (var line in lines) { var l = StringHelper.RemoveRemark2(line); if (!StringHelper.IsChinese(l)) { newLines.Add(l); } } if (newLines.Count > 0) { subtitleLine.EnglishText = string.Join("\r\n", newLines.ToArray()); } else { subtitleLine.EnglishText = " "; } newSrts.Add(subtitleLine.Number,subtitleLine); } subtitle.Bodies = newSrts; return subtitle; }
public Subtitle Parse(string str) { var result = new Dictionary<int, SubtitleLine>(); var blocks = str.Split(new[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries); int index = 0; foreach (var block in blocks) { var array = block.Split(new string[] {"\r","\n"}, StringSplitOptions.RemoveEmptyEntries); if(array.Length<3) continue; var srt = new SubtitleLine(); var num = array[0]; srt.Number = ++index; var tarray = array[1].Split(new string[] { " --> " }, StringSplitOptions.RemoveEmptyEntries); srt.StartTime = Convert.ToDateTime("2000-01-01 " + tarray[0].Replace(',', '.').Replace(" ","")); srt.EndTime = Convert.ToDateTime("2000-01-01 " + tarray[1].Replace(',', '.').Replace(" ", "")); srt.Text = ""; for (var i = 2; i < array.Length;i++ ) srt.Text += array[i]+"\r\n"; if (srt.Text != "") { srt.Text= srt.Text.Remove(srt.Text.Length - 2, 2); } result.Add(index,srt); } Subtitle st = new Subtitle(){Bodies=result}; //ReCalcSequence(st); return st; }
public Subtitle RemoveFormat(Subtitle subtitle) { foreach (KeyValuePair<int, SubtitleLine> subtitleLine in subtitle.Bodies) { subtitle.Bodies[subtitleLine.Key].EnglishText = formatRegex.Replace(subtitleLine.Value.EnglishText, ""); } return subtitle; }
public string Subtitle2String(Subtitle st) { StringBuilder sb=new StringBuilder(); foreach (var subtitleLine in st.Bodies.Values) { sb.Append(subtitleLine.EnglishTextWithMeans+"\r\n"); } return sb.ToString(); }
public string Subtitle2String(Subtitle st) { StringBuilder sb=new StringBuilder(); sb.Append(st.Header); foreach (var subtitleLine in st.Bodies) { sb.Append(Line2String(subtitleLine.Value)); sb.Append("\r\n"); } return sb.ToString(); }
public Subtitle Parse(string str) { Subtitle sb=new Subtitle(); sb.Bodies=new Dictionary<int, SubtitleLine>(); int rowIndex = 1; foreach (var line in str.Split(new []{'\r','\n'},StringSplitOptions.RemoveEmptyEntries)) { sb.Bodies.Add(rowIndex,new SubtitleLine() {EnglishText = line,Number = rowIndex}); rowIndex++; } return sb; }
public Subtitle Parse(string str) { Subtitle subtitle=new Subtitle(); var eIndex = str.IndexOf("[Events]"); var head = str.Substring(0, eIndex); str = str.Substring(eIndex); var diagIndex = str.IndexOf("Dialogue"); head += str.Substring(0, diagIndex); subtitle.Header = head; str = str.Substring(diagIndex); var lines = str.Split(new char[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries); int index = 0; foreach (var line in lines) { var number = ++index; var sub = ParseLine(line); sub.Number = number; subtitle.Bodies.Add(number,sub); } return subtitle; }
private void ReadAndShowSubtitle() { var txt = FileOperationHelper.ReadFile(txbSubtitleFilePath.Text); stOperator = SubtitleHelper.GetOperatorByFileName(txbSubtitleFilePath.Text); var srts = stOperator.Parse(txt); srts = stOperator.RemoveChinese(srts); srts = stOperator.RemoveFormat(srts); ShowSubtitleText(srts.Bodies.Values); subtitle = srts; }
private Subtitle BuildSubtitleFromGrid() { Subtitle nsubtitle=new Subtitle(); nsubtitle.Header = subtitle.Header; nsubtitle.Footer = nsubtitle.Footer; nsubtitle.Bodies = new Dictionary<int, SubtitleLine>(); foreach (DataGridViewRow row in dgvSubtitleSentence.Rows) { SubtitleLine line=new SubtitleLine(); var number = Convert.ToInt32( row.Cells[0].Value.ToString()); var orgLine = subtitle.Bodies[number];//.SingleOrDefault(i => i.Number == number); line.Number = number; line.StartTime = orgLine.StartTime; line.EndTime = orgLine.EndTime; line.Text = row.Cells[2].Value.ToString(); nsubtitle.Bodies.Add(number,line); } return nsubtitle; }
//private void ReCalcSequence(Subtitle subtitle) //{ // var newList = subtitle.Bodies.OrderBy(l => l.StartTime).ToList(); // for (var i = 1; i < newList.Count; i++) // { // newList[i].Number = i; // } // subtitle.Bodies = newList; //} public string Subtitle2String(Subtitle st ) { StringBuilder sb=new StringBuilder(); var srts = st.Bodies; foreach (var kv in srts) { var subtitleLine = kv.Value; sb.Append(subtitleLine.Number); sb.Append("\r\n"); sb.Append(subtitleLine.StartTime.ToString("HH:mm:ss,fff") + " --> " + subtitleLine.EndTime.ToString("HH:mm:ss,fff")); sb.Append("\r\n"); sb.Append(subtitleLine.Text); sb.Append("\r\n\r\n"); } var result = sb.ToString(); return result.Remove(result.Length - 4); }
public Subtitle RemoveFormat(Subtitle subtitle) { return subtitle; }
public Subtitle RemoveChinese(Subtitle subtitle) { return subtitle; }