public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { //00:03:15:22 00:03:23:10 This is line one. //This is line two. subtitle.Paragraphs.Clear(); _errorCount = 0; foreach (string line in lines) { if (regexTimeCodes.IsMatch(line)) { string temp = line.Substring(0, regexTimeCodes.Match(line).Length); string start = temp.Substring(0, 11); string end = temp.Substring(12, 11); string[] startParts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); string[] endParts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (startParts.Length == 4 && endParts.Length == 4) { string text = line.Remove(0, regexTimeCodes.Match(line).Length - 1).Trim(); text = text.Replace("//", Environment.NewLine); var p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), text); subtitle.Paragraphs.Add(p); } } else { _errorCount += 10; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; subtitle.Paragraphs.Clear(); foreach (string line in lines) { if (regexTimeCodes.IsMatch(line)) { int splitter = line.IndexOf(':') + 3; string text = line.Remove(0, splitter); var p = new Paragraph(DecodeTimeCode(line.Substring(0, splitter)), new TimeCode(0, 0, 0, 0), text); subtitle.Paragraphs.Add(p); text = text.Trim().Trim('–', '.', ';', ':').Trim(); if (text.Length > 0 && char.IsDigit(text[0])) _errorCount++; } else { _errorCount += 2; } } foreach (Paragraph p2 in subtitle.Paragraphs) { p2.Text = Utilities.AutoBreakLine(p2.Text); } subtitle.RecalculateDisplayTimes(Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds, null); subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { //00:01:54:19,00:01:56:17,We should be thankful|they accepted our offer. _errorCount = 0; subtitle.Paragraphs.Clear(); var regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d:\d\d,\d\d:\d\d:\d\d:\d\d,.+", RegexOptions.Compiled); if (fileName != null && fileName.EndsWith(".stl", StringComparison.OrdinalIgnoreCase)) // allow empty text if extension is ".stl"... regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d:\d\d,\d\d:\d\d:\d\d:\d\d,", RegexOptions.Compiled); foreach (string line in lines) { if (line.IndexOf(':') == 2 && regexTimeCodes.IsMatch(line)) { string start = line.Substring(0, 11); string end = line.Substring(12, 11); try { Paragraph p = new Paragraph(DecodeTimeCode(start), DecodeTimeCode(end), DecodeText(line.Substring(24))); subtitle.Paragraphs.Add(p); } catch { _errorCount++; } } else if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("//") && !line.StartsWith('$')) { _errorCount++; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { const int startPosition = 0xa99; const int textPosition = 72; _errorCount = 0; subtitle.Paragraphs.Clear(); subtitle.Header = null; var buffer = FileUtil.ReadAllBytesShared(fileName); int index = startPosition; if (buffer[index] != 1) { return; } while (index + textPosition < buffer.Length) { int textLength = buffer[index + 16]; if (textLength > 0 && index + textPosition + textLength < buffer.Length) { string text = GetText(index + textPosition, textLength, buffer); if (!string.IsNullOrWhiteSpace(text)) { int startFrames = GetFrames(index + 4, buffer); int endFrames = GetFrames(index + 8, buffer); subtitle.Paragraphs.Add(new Paragraph(text, FramesToMilliseconds(startFrames), FramesToMilliseconds(endFrames))); } } index += textPosition + textLength; } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { //00:01:54:19,00:01:56:17,We should be thankful|they accepted our offer. _errorCount = 0; subtitle.Paragraphs.Clear(); foreach (string line in lines) { if (line.IndexOf(':') == 2 && regexTimeCodes.IsMatch(line)) { string start = line.Substring(0, 11); string end = line.Substring(13, 11); try { Paragraph p = new Paragraph(DecodeTimeCode(start), DecodeTimeCode(end), DecodeText(line.Substring(25).Trim())); subtitle.Paragraphs.Add(p); } catch { _errorCount++; } } else if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("//") && !line.StartsWith('$')) { _errorCount++; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; FrameRate = Configuration.Settings.General.CurrentFrameRate; var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); var xml = new XmlDocument(); xml.XmlResolver = null; try { xml.LoadXml(sb.ToString().Trim()); foreach (XmlNode node in xml.SelectNodes("fcpxml/project/sequence/spine/gap")) { try { foreach (XmlNode title in node.SelectNodes("title")) { var textNodes = title.SelectNodes("text"); if (textNodes != null && textNodes.Count > 0) { Paragraph p = new Paragraph(); p.StartTime = DecodeTime(title.Attributes["offset"]); p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + DecodeTime(title.Attributes["duration"]).TotalMilliseconds; var text = new StringBuilder(); foreach (XmlNode textNode in textNodes) { text.AppendLine(textNode.InnerText); } p.Text = text.ToString().Trim(); subtitle.Paragraphs.Add(p); } } } catch { _errorCount++; } } subtitle.Renumber(); } catch { _errorCount = 1; return; } }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); string xmlString = sb.ToString(); if (!xmlString.Contains("<BDN")) return; var xml = new XmlDocument(); xml.XmlResolver = null; try { xml.LoadXml(xmlString); } catch { _errorCount = 1; return; } foreach (XmlNode node in xml.DocumentElement.SelectNodes("Events/Event")) { try { string start = node.Attributes["InTC"].InnerText; string end = node.Attributes["OutTC"].InnerText; var textBuilder = new StringBuilder(); foreach (XmlNode graphic in node.SelectNodes("Graphic")) textBuilder.AppendLine(graphic.InnerText); var p = new Paragraph(textBuilder.ToString().Trim(), GetMillisecondsFromTimeCode(start), GetMillisecondsFromTimeCode(end)); if (node.Attributes["Forced"] != null && node.Attributes["Forced"].Value.Equals("true", StringComparison.OrdinalIgnoreCase)) p.Forced = true; subtitle.Paragraphs.Add(p); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); _errorCount++; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); string xmlString = sb.ToString(); if (!xmlString.Contains("<titles") || !xmlString.Contains("<text1>")) return; var xml = new XmlDocument(); xml.XmlResolver = null; try { xml.LoadXml(xmlString); } catch { _errorCount = 1; return; } foreach (XmlNode node in xml.DocumentElement.SelectNodes("title")) { try { XmlNode timeNode = node.SelectSingleNode("time"); string start = timeNode.Attributes["start"].InnerText; string end = timeNode.Attributes["end"].InnerText; string text = string.Empty; for (int i = 1; i < 10; i++) { XmlNode textNode = node.SelectSingleNode("text" + i); if (textNode != null) text = (text + Environment.NewLine + textNode.InnerText).Trim(); } subtitle.Paragraphs.Add(new Paragraph(text, ParseTimeCode(start), ParseTimeCode(end))); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); _errorCount++; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { //1 00:03:15:22 00:03:23:10 //This is line one. //This is line two. Paragraph p = null; subtitle.Paragraphs.Clear(); _errorCount = 0; foreach (string line in lines) { if (regexTimeCodes.IsMatch(line)) { string[] temp = line.Split(' '); if (temp.Length == 3) { string start = temp[1]; string end = temp[2]; string[] startParts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); string[] endParts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (startParts.Length == 4 && endParts.Length == 4) { p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty); subtitle.Paragraphs.Add(p); } } } else if (string.IsNullOrWhiteSpace(line)) { // skip these lines } else if (p != null) { if (string.IsNullOrEmpty(p.Text)) p.Text = line; else p.Text = p.Text + Environment.NewLine + line; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { //22 00:04:19:12 00:04:21:09 00:00:01:21 _errorCount = 0; Paragraph lastParagraph = null; int count = 0; foreach (string line in lines) { bool isTimeCode = false; if (line.Length > 0) { bool success = false; if (line.Length > 31 && line.IndexOf(':') > 1) { var match = regex.Match(line); if (match.Success) { isTimeCode = true; if (lastParagraph != null) subtitle.Paragraphs.Add(lastParagraph); var arr = line.Split('\t'); TimeCode start = DecodeTimeCode(arr[1]); TimeCode end = DecodeTimeCode(arr[2]); lastParagraph = new Paragraph(start, end, string.Empty); success = true; } } if (!isTimeCode && !string.IsNullOrWhiteSpace(line) && lastParagraph != null && Utilities.GetNumberOfLines(lastParagraph.Text) < 5) { lastParagraph.Text = (lastParagraph.Text + Environment.NewLine + line).Trim(); success = true; } if (!success && count > 9) _errorCount++; } count++; } if (lastParagraph != null) subtitle.Paragraphs.Add(lastParagraph); subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; StringBuilder sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); string allText = sb.ToString(); if (!allText.Contains("<Subtitle") || !allText.Contains("TimeStart=")) return; XmlDocument xml = new XmlDocument(); xml.XmlResolver = null; try { xml.LoadXml(allText); } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.Message); _errorCount = 1; return; } foreach (XmlNode node in xml.DocumentElement.SelectNodes("Phrase")) { try { string start = node.Attributes["TimeStart"].InnerText; string end = node.Attributes["TimeEnd"].InnerText; string text = node.SelectSingleNode("Text").InnerText; text = text.Replace("\\n", Environment.NewLine); subtitle.Paragraphs.Add(new Paragraph(DecodeTimeCode(start), DecodeTimeCode(end), text)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); _errorCount++; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { //01072508010729007 _errorCount = 0; Paragraph p = null; subtitle.Paragraphs.Clear(); subtitle.Header = null; foreach (string line in lines) { if (string.IsNullOrWhiteSpace(line)) { continue; } var indexOf7001 = line.IndexOf("7\x01\x01\0", StringComparison.Ordinal); var indexOfTen = line.IndexOf(" 10 ", StringComparison.Ordinal); if (indexOf7001 >= 0 && indexOfTen > 0) { try { string text = line.Substring(0, indexOfTen).Trim(); string time = line.Substring(indexOf7001 - 16, 16); p = new Paragraph(DecodeTimeCode(time.Substring(0, 8)), DecodeTimeCode(time.Substring(8)), text); subtitle.Paragraphs.Add(p); } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.Message); _errorCount++; } } else if (p != null) { _errorCount++; } } if (p != null && !string.IsNullOrEmpty(p.Text)) subtitle.Paragraphs.Add(p); subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); string allText = sb.ToString(); if (!allText.Contains("<page") || !allText.Contains("<cuepoint")) return; var xml = new XmlDocument(); xml.XmlResolver = null; try { xml.LoadXml(allText); } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.Message); _errorCount = 1; return; } foreach (XmlNode node in xml.DocumentElement.SelectNodes("video/cuepoint")) { try { string text = node.SelectSingleNode("name").InnerText; string start = node.SelectSingleNode("startTime").InnerText; string end = node.SelectSingleNode("endTime").InnerText; subtitle.Paragraphs.Add(new Paragraph(DecodeTimeCode(start), DecodeTimeCode(end), text)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); _errorCount++; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); string xmlString = sb.ToString(); if (!xmlString.Contains("<USFSubtitles") || !xmlString.Contains("<subtitles>")) return; var xml = new XmlDocument(); xml.XmlResolver = null; try { xml.LoadXml(xmlString); } catch { _errorCount = 1; return; } foreach (XmlNode node in xml.DocumentElement.SelectNodes("subtitles/subtitle")) { try { string start = node.Attributes["start"].InnerText; string stop = node.Attributes["stop"].InnerText; string text = node.SelectSingleNode("text").InnerText; subtitle.Paragraphs.Add(new Paragraph(DecodeTimeCode(start), DecodeTimeCode(stop), text)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); _errorCount++; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); string allText = sb.ToString(); if (!allText.Contains("<layers") && !allText.Contains("<marker>")) return; var xml = new XmlDocument(); xml.XmlResolver = null; try { xml.LoadXml(allText); } catch (Exception exception) { System.Diagnostics.Debug.WriteLine(exception.Message); _errorCount = 1; return; } foreach (XmlNode node in xml.DocumentElement.SelectNodes("layers/layer/marker")) { try { double start = Convert.ToDouble(node.SelectSingleNode("time").Attributes["value"].InnerText, CultureInfo.InvariantCulture); double end = start + Convert.ToDouble(node.SelectSingleNode("duration").Attributes["value"].InnerText, CultureInfo.InvariantCulture); string text = node.SelectSingleNode("comment").Attributes["value"].InnerText.Replace("||", Environment.NewLine); subtitle.Paragraphs.Add(new Paragraph(text, start * TimeCode.BaseUnit, end * TimeCode.BaseUnit)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); _errorCount++; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { //0001 00:00:19:13 00:00:22:10 a_0001.tif Paragraph p = null; subtitle.Paragraphs.Clear(); _errorCount = 0; var regexTimeCodes = new Regex(@"^\d\d\d\d[\t]+\d\d:\d\d:\d\d:\d\d\t\d\d:\d\d:\d\d:\d\d\t.+\.(tif|tiff|png|bmp|TIF|TIFF|PNG|BMP)", RegexOptions.Compiled); int index = 0; char[] splitChar = { ':' }; foreach (string line in lines) { if (regexTimeCodes.IsMatch(line)) { string temp = line.Substring(0, regexTimeCodes.Match(line).Length); string start = temp.Substring(5, 11); string end = temp.Substring(12 + 5, 11); string[] startParts = start.Split(splitChar, StringSplitOptions.RemoveEmptyEntries); string[] endParts = end.Split(splitChar, StringSplitOptions.RemoveEmptyEntries); if (startParts.Length == 4 && endParts.Length == 4) { int lastIndexOfTab = line.LastIndexOf('\t'); string text = line.Remove(0, lastIndexOfTab + 1).Trim(); if (!text.Contains(Environment.NewLine)) text = text.Replace("\t", Environment.NewLine); p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), text); subtitle.Paragraphs.Add(p); } } else if (string.IsNullOrWhiteSpace(line) || line.StartsWith("Display_Area") || line.StartsWith('#') || line.StartsWith("Color") || index < 10) { // skip these lines } else if (p != null) { _errorCount++; } index++; } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; StringBuilder sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); string xmlString = sb.ToString(); if (!xmlString.Contains("<Paragraph>") || !xmlString.Contains("<Text>")) return; XmlDocument xml = new XmlDocument(); xml.XmlResolver = null; try { xml.LoadXml(xmlString); } catch { _errorCount = 1; return; } foreach (XmlNode node in xml.DocumentElement.SelectNodes("Paragraph")) { try { string start = node.SelectSingleNode("StartMilliseconds").InnerText; string end = node.SelectSingleNode("EndMilliseconds").InnerText; string text = node.SelectSingleNode("Text").InnerText; subtitle.Paragraphs.Add(new Paragraph(text, Convert.ToDouble(start, System.Globalization.CultureInfo.InvariantCulture), Convert.ToDouble(end, System.Globalization.CultureInfo.InvariantCulture))); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); _errorCount++; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); string xmlString = sb.ToString(); if (!xmlString.Contains("<reel")) return; var xml = new XmlDocument { XmlResolver = null }; try { xml.LoadXml(xmlString); } catch { _errorCount = 1; return; } foreach (XmlNode node in xml.DocumentElement.SelectNodes("reel/title")) { try { string start = node.Attributes["start"].InnerText; string end = node.Attributes["end"].InnerText; string text = node.InnerText; text = text.Replace("|", Environment.NewLine); subtitle.Paragraphs.Add(new Paragraph(text, ParseTimeCode(start), ParseTimeCode(end))); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); _errorCount++; } } subtitle.Renumber(); }
public void Initialize(Subtitle subtitle) { if (subtitle.Paragraphs.Count > 0) subtitle.Renumber(subtitle.Paragraphs[0].Number); Text = Configuration.Settings.Language.MergeTextWithSameTimeCodes.Title; labelMaxDifferenceMS.Text = Configuration.Settings.Language.MergeTextWithSameTimeCodes.MaxDifferenceMilliseconds; checkBoxAutoBreakOn.Text = Configuration.Settings.Language.MergeTextWithSameTimeCodes.ReBreakLines; listViewFixes.Columns[0].Text = Configuration.Settings.Language.General.Apply; listViewFixes.Columns[1].Text = Configuration.Settings.Language.General.LineNumber; listViewFixes.Columns[2].Text = Configuration.Settings.Language.MergeTextWithSameTimeCodes.MergedText; buttonOK.Text = Configuration.Settings.Language.General.Ok; buttonCancel.Text = Configuration.Settings.Language.General.Cancel; SubtitleListview1.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings); Utilities.InitializeSubtitleFont(SubtitleListview1); SubtitleListview1.AutoSizeAllColumns(this); NumberOfMerges = 0; _subtitle = subtitle; MergeTextWithSameTimeCodes_ResizeEnd(null, null); _language = LanguageAutoDetect.AutoDetectGoogleLanguage(subtitle); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; subtitle.Paragraphs.Clear(); var text = new StringBuilder(); for (int i = 0; i < lines.Count; i++) { string line = lines[i].Trim(); if (line.StartsWith('#')) { var timeParts = line.Split(new[] { '#', ',' }, StringSplitOptions.RemoveEmptyEntries); if (timeParts.Length == 2) { try { TimeCode start = DecodeTimeCode(timeParts[0]); TimeCode end = DecodeTimeCode(timeParts[1]); subtitle.Paragraphs.Add(new Paragraph(start, end, text.ToString().Trim())); } catch { _errorCount++; } } } else if (line.Length > 0) { text.AppendLine(line.Trim()); if (text.Length > 5000) return; } else { text = new StringBuilder(); } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; var sb = new StringBuilder(); foreach (string s in lines) sb.Append(s); int startIndex = sb.ToString().IndexOf("[{\"hitType", StringComparison.Ordinal); if (startIndex < 0) return; string text = sb.ToString().Substring(startIndex); foreach (string line in text.Replace("},{", Environment.NewLine).SplitToLines()) { string s = line.Trim() + "}"; string start = Json.ReadTag(s, "startTime"); string end = Json.ReadTag(s, "endTime"); string content = Json.ReadTag(s, "Text"); if (start != null && end != null && content != null) { double startSeconds; double endSeconds; if (double.TryParse(start, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out startSeconds) && double.TryParse(end, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out endSeconds)) { subtitle.Paragraphs.Add(new Paragraph(Json.DecodeJsonText(content), startSeconds * TimeCode.BaseUnit, endSeconds * TimeCode.BaseUnit)); } else { _errorCount++; } } else { _errorCount++; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { //00:03:15:22 -> 00:03:23:10 This is line one. //This is line two. Paragraph p = null; subtitle.Paragraphs.Clear(); _errorCount = 0; foreach (string line in lines) { if (RegexTimeCodes.IsMatch(line)) { string temp = line.Substring(0, RegexTimeCodes.Match(line).Length); int indexOfSeparator = temp.IndexOf("->", StringComparison.Ordinal); string start = temp.Substring(0, indexOfSeparator).Trim(); string end = temp.Substring(indexOfSeparator + 2).Trim(); string[] startParts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); string[] endParts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (startParts.Length == 4 && endParts.Length == 4) { p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty); subtitle.Paragraphs.Add(p); } } else if (string.IsNullOrWhiteSpace(line)) { // skip these lines } else if (p != null) { if (string.IsNullOrEmpty(p.Text)) p.Text = line; else p.Text = p.Text + Environment.NewLine + line; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { Paragraph p = null; subtitle.Paragraphs.Clear(); _errorCount = 0; char[] splitChar = { ':' }; foreach (string line in lines) { if (regexTimeCodes.IsMatch(line)) { string[] temp = line.Split('–'); string start = temp[0].Trim(); string end = temp[1].Trim(); string[] startParts = start.Split(splitChar, StringSplitOptions.RemoveEmptyEntries); string[] endParts = end.Split(splitChar, StringSplitOptions.RemoveEmptyEntries); if (startParts.Length == 2 && endParts.Length == 2) { p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), string.Empty); subtitle.Paragraphs.Add(p); } } else if (string.IsNullOrWhiteSpace(line)) { // skip these lines } else if (p != null) { if (string.IsNullOrEmpty(p.Text)) p.Text = line; else p.Text = p.Text.TrimEnd() + Environment.NewLine + line; if (p.Text.Length > 500) return; } } subtitle.Renumber(); }
public void Initialize(Subtitle subtitle) { if (subtitle.Paragraphs.Count > 0) subtitle.Renumber(subtitle.Paragraphs[0].Number); Text = Configuration.Settings.Language.SplitLongLines.Title; labelSingleLineMaxLength.Text = Configuration.Settings.Language.SplitLongLines.SingleLineMaximumLength; labelLineMaxLength.Text = Configuration.Settings.Language.SplitLongLines.LineMaximumLength; labelLineContinuationBeginEnd.Text = Configuration.Settings.Language.SplitLongLines.LineContinuationBeginEndStrings; listViewFixes.Columns[0].Text = Configuration.Settings.Language.General.Apply; listViewFixes.Columns[1].Text = Configuration.Settings.Language.General.LineNumber; listViewFixes.Columns[2].Text = Configuration.Settings.Language.General.Text; buttonOK.Text = Configuration.Settings.Language.General.Ok; buttonCancel.Text = Configuration.Settings.Language.General.Cancel; SubtitleListview1.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings); Utilities.InitializeSubtitleFont(SubtitleListview1); SubtitleListview1.AutoSizeAllColumns(this); NumberOfSplits = 0; numericUpDownSingleLineMaxCharacters.Value = Configuration.Settings.General.SubtitleLineMaximumLength; _subtitle = subtitle; }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { //00:03:15.22 00:03:23.10 This is line one.//This is line two. _errorCount = 0; Paragraph p = null; subtitle.Paragraphs.Clear(); foreach (string line in lines) { if (regexTimeCodes.IsMatch(line)) { string temp = line.Substring(0, regexTimeCodes.Match(line).Length); string start = temp.Substring(0, 11); string end = temp.Substring(12, 11); string[] startParts = start.Split(new[] { ':', '.' }, StringSplitOptions.RemoveEmptyEntries); string[] endParts = end.Split(new[] { ':', '.' }, StringSplitOptions.RemoveEmptyEntries); if (startParts.Length == 4 && endParts.Length == 4 && line.Length >= 23) { string text = line.Remove(0, 23).Trim(); if (!text.Contains(Environment.NewLine)) text = text.Replace("//", Environment.NewLine); p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), text); subtitle.Paragraphs.Add(p); } } else if (string.IsNullOrWhiteSpace(line)) { } else if (p != null) { if (p.Text.Length < 200) p.Text = (p.Text + Environment.NewLine + line).Trim(); } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; var sb = new StringBuilder(); foreach (string s in lines) sb.Append(s); if (!sb.ToString().TrimStart().StartsWith("[{\"startMillis")) return; foreach (string line in sb.ToString().Replace("},{", Environment.NewLine).SplitToLines()) { string s = line.Trim() + "}"; string start = Json.ReadTag(s, "startMillis"); string end = Json.ReadTag(s, "endMillis"); string text = Json.ReadTag(s, "text"); if (start != null && end != null && text != null) { double startSeconds; double endSeconds; if (double.TryParse(start, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out startSeconds) && double.TryParse(end, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out endSeconds)) { subtitle.Paragraphs.Add(new Paragraph(Json.DecodeJsonText(text), startSeconds, endSeconds)); } else { _errorCount++; } } else { _errorCount++; } } subtitle.Renumber(); }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; Paragraph p = null; subtitle.Paragraphs.Clear(); foreach (string line in lines) { if (regexTimeCodes.IsMatch(line)) { p = new Paragraph(DecodeTimeCode(line), new TimeCode(0, 0, 0, 0), string.Empty); subtitle.Paragraphs.Add(p); } else if (string.IsNullOrWhiteSpace(line)) { // skip these lines } else if (p != null) { if (string.IsNullOrEmpty(p.Text)) p.Text = line; else p.Text = p.Text + Environment.NewLine + line; if (p.Text.Length > 800) { _errorCount++; return; } } } foreach (Paragraph p2 in subtitle.Paragraphs) { p2.Text = Utilities.AutoBreakLine(p2.Text); } subtitle.RecalculateDisplayTimes(Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds, null); subtitle.Renumber(); }
public void Initialize(Subtitle subtitle) { if (subtitle.Paragraphs.Count > 0) subtitle.Renumber(); Text = Configuration.Settings.Language.MergedShortLines.Title; labelMaxCharacters.Text = Configuration.Settings.Language.MergedShortLines.MaximumCharacters; labelMaxMillisecondsBetweenLines.Text = Configuration.Settings.Language.MergedShortLines.MaximumMillisecondsBetween; checkBoxOnlyContinuationLines.Text = Configuration.Settings.Language.MergedShortLines.OnlyMergeContinuationLines; listViewFixes.Columns[0].Text = Configuration.Settings.Language.General.Apply; listViewFixes.Columns[1].Text = Configuration.Settings.Language.General.LineNumber; listViewFixes.Columns[2].Text = Configuration.Settings.Language.MergedShortLines.MergedText; buttonOK.Text = Configuration.Settings.Language.General.Ok; buttonCancel.Text = Configuration.Settings.Language.General.Cancel; SubtitleListview1.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings); Utilities.InitializeSubtitleFont(SubtitleListview1); SubtitleListview1.AutoSizeAllColumns(this); NumberOfMerges = 0; numericUpDownMaxCharacters.Value = Configuration.Settings.General.SubtitleLineMaximumLength; _subtitle = subtitle; }
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) { _errorCount = 0; foreach (string line in lines) { if (RegexTimeCodes.Match(line).Success) { string[] parts = line.Split(new[] { ' ' }, StringSplitOptions.None); var p = new Paragraph(); if (parts.Length > 2 && GetTimeCode(p.StartTime, parts[0].Trim()) && GetTimeCode(p.EndTime, parts[1].Trim())) { p.Text = line.Remove(0, 25).Trim(); subtitle.Paragraphs.Add(p); } } else { _errorCount += 10; } } subtitle.Renumber(); }
public void Initialize(Subtitle subtitle) { if (subtitle.Paragraphs.Count > 0) subtitle.Renumber(subtitle.Paragraphs[0].Number); Text = Configuration.Settings.Language.MergeDoubleLines.Title; labelMaxMillisecondsBetweenLines.Text = Configuration.Settings.Language.MergeDoubleLines.MaxMillisecondsBetweenLines; checkBoxIncludeIncrementing.Text = Configuration.Settings.Language.MergeDoubleLines.IncludeIncrementing; numericUpDownMaxMillisecondsBetweenLines.Left = labelMaxMillisecondsBetweenLines.Left + labelMaxMillisecondsBetweenLines.Width + 3; checkBoxIncludeIncrementing.Left = numericUpDownMaxMillisecondsBetweenLines.Left + numericUpDownMaxMillisecondsBetweenLines.Width + 10; listViewFixes.Columns[0].Text = Configuration.Settings.Language.General.Apply; listViewFixes.Columns[1].Text = Configuration.Settings.Language.General.LineNumber; listViewFixes.Columns[2].Text = Configuration.Settings.Language.MergedShortLines.MergedText; buttonOK.Text = Configuration.Settings.Language.General.Ok; buttonCancel.Text = Configuration.Settings.Language.General.Cancel; SubtitleListview1.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings); Utilities.InitializeSubtitleFont(SubtitleListview1); SubtitleListview1.AutoSizeAllColumns(this); NumberOfMerges = 0; _subtitle = subtitle; MergeDoubleLines_ResizeEnd(null, null); }
private Subtitle ImportTimeCodesInFramesOnSameSeperateLine(string[] lines) { Paragraph p = null; var subtitle = new Subtitle(); var sb = new StringBuilder(); for (int idx = 0; idx < lines.Length; idx++) { string line = lines[idx]; string lineWithPerhapsOnlyNumbers = GetLineWithPerhapsOnlyNumbers(line); bool allNumbers = lineWithPerhapsOnlyNumbers.Length > 0; foreach (char c in lineWithPerhapsOnlyNumbers) { if (!char.IsDigit(c)) { allNumbers = false; } } if (allNumbers && lineWithPerhapsOnlyNumbers.Length > 2) { string[] arr = line.Replace('-', ' ').Replace('>', ' ').Replace('{', ' ').Replace('}', ' ').Replace('[', ' ').Replace(']', ' ').Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length == 2) { string[] start = arr[0].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); string[] end = arr[0].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); if (start.Length == 1 && end.Length == 1) { if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } p = new Paragraph(); sb.Clear(); try { if (UseFrames) { p.StartFrame = int.Parse(start[0]); p.EndFrame = int.Parse(end[0]); p.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate); } else { p.StartTime.TotalMilliseconds = double.Parse(start[0]); p.EndTime.TotalMilliseconds = double.Parse(end[0]); } } catch { p = null; } } } else if (arr.Length == 3) { string[] start = arr[0].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); string[] end = arr[0].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); string[] duration = arr[0].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); if (end.Length == 1 && duration.Length == 1) { start = end; end = duration; } if (start.Length == 1 && end.Length == 1) { if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } p = new Paragraph(); sb.Clear(); try { if (UseFrames) { p.StartFrame = int.Parse(start[0]); p.EndFrame = int.Parse(end[0]); p.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate); } else { p.StartTime.TotalMilliseconds = double.Parse(start[0]); p.EndTime.TotalMilliseconds = double.Parse(end[0]); } } catch { p = null; } } } } if (p != null && !allNumbers && line.Length > 1) { line = line.Trim(); if (line.StartsWith("}{}", StringComparison.Ordinal) || line.StartsWith("][]", StringComparison.Ordinal)) { line = line.Remove(0, 3); } sb.AppendLine(line.Trim()); } } if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } subtitle.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate); subtitle.Renumber(); return(subtitle); }
private static Subtitle ImportTimeCodesOnAloneLines(string[] lines) { Paragraph p = null; var subtitle = new Subtitle(); var sb = new StringBuilder(); char[] splitChars = { ' ', '\t', '-', '>', '<', '{', '}', '[', ']' }; for (int idx = 0; idx < lines.Length; idx++) { string line = lines[idx]; string lineWithPerhapsOnlyNumbers = GetLineWithPerhapsOnlyNumbers(line); bool allNumbers = lineWithPerhapsOnlyNumbers.Length > 0; foreach (char c in lineWithPerhapsOnlyNumbers) { if (!char.IsDigit(c)) { allNumbers = false; break; } } if (allNumbers && lineWithPerhapsOnlyNumbers.Length > 5) { string[] arr = line.Split(splitChars, StringSplitOptions.RemoveEmptyEntries); if (arr.Length == 1) { string[] tc = arr[0].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); if (p == null || Math.Abs(p.EndTime.TotalMilliseconds) > 0.001) { if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); sb.Clear(); } p = new Paragraph { StartTime = DecodeTime(tc) }; } else { p.EndTime = DecodeTime(tc); } } } if (p != null && !allNumbers && line.Length > 1) { line = line.Trim(); if (line.StartsWith("}{}", StringComparison.Ordinal) || line.StartsWith("][]", StringComparison.Ordinal)) { line = line.Remove(0, 3); } sb.AppendLine(line.Trim()); } } if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } subtitle.Renumber(); return(subtitle); }
private static Subtitle ImportTimeCodesAndTextOnSameLine(string[] lines) { var regexTimeCodes1 = new Regex(@"\d+[:.,;]{1}\d\d[:.,;]{1}\d\d[:.,;]{1}\d+", RegexOptions.Compiled); var regexTimeCodes2 = new Regex(@"\d+[:.,;]{1}\d\d[:.,;]{1}\d+", RegexOptions.Compiled); Paragraph p = null; var subtitle = new Subtitle(); var sb = new StringBuilder(); bool isFirstLineNumber = false; int count = -1; for (int idx = 0; idx < lines.Length; idx++) { string line = lines[idx]; var matches = regexTimeCodes1.Matches(line); if (matches.Count == 0) { matches = regexTimeCodes2.Matches(line); } if (matches.Count == 2) { var start = matches[0].Value.Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); int i; if (int.TryParse(start[0], out i)) { if (count == -1 && i < 2) { count = i; } if (count != i) { isFirstLineNumber = false; break; } count++; } } if (count > 2) { isFirstLineNumber = true; } } for (int idx = 0; idx < lines.Length; idx++) { string line = lines[idx]; if (isFirstLineNumber) { while (line.Length > 0 && char.IsDigit(line[0])) { line = line.Remove(0, 1); } } var matches = regexTimeCodes1.Matches(line); if (matches.Count == 0) { matches = regexTimeCodes2.Matches(line); } if (matches.Count == 2) { string[] start = matches[0].ToString().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); string[] end = matches[1].ToString().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); if ((start.Length == 3 || start.Length == 4) && (end.Length == 3 || end.Length == 4)) { if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } p = new Paragraph(); sb.Clear(); p.StartTime = DecodeTime(start); p.EndTime = DecodeTime(end); } if (matches[0].Index < 9) { line = line.Remove(0, matches[0].Index); } line = line.Replace(matches[0].ToString(), string.Empty); line = line.Replace(matches[1].ToString(), string.Empty); line = line.Trim(); if (line.StartsWith("}{}", StringComparison.Ordinal) || line.StartsWith("][]", StringComparison.Ordinal)) { line = line.Remove(0, 3); } line = line.Trim(); } if (p != null && line.Length > 1) { sb.AppendLine(line.Trim()); } } if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } // remove all equal headers if (subtitle.Paragraphs.Count > 5) { string prefix = subtitle.Paragraphs[0].Text; foreach (Paragraph paragraph in subtitle.Paragraphs) { string text = paragraph.Text.Trim(); var newPrefix = new StringBuilder(); int i = 0; while (i < prefix.Length && i < text.Length && text[i] == prefix[i]) { newPrefix.Append(text[i]); i++; } prefix = newPrefix.ToString(); } if (prefix.Length > 3 && prefix[1] == ':' && prefix[2] == '\\') { prefix = string.Empty; } if (prefix.Length > 0) { foreach (Paragraph paragraph in subtitle.Paragraphs) { string text = paragraph.Text.Trim(); if (text.StartsWith(prefix, StringComparison.Ordinal)) { paragraph.Text = text.Remove(0, prefix.Length); } } } } subtitle.Renumber(); return(subtitle); }
private static Subtitle ImportTimeCodesOnSameSeperateLine(string[] lines) { Paragraph p = null; var subtitle = new Subtitle(); var sb = new StringBuilder(); char[] splitChars = { ' ', '\t' }; for (int idx = 0; idx < lines.Length; idx++) { string line = lines[idx]; string lineWithPerhapsOnlyNumbers = GetLineWithPerhapsOnlyNumbers(line); bool allNumbers = lineWithPerhapsOnlyNumbers.Length > 0; foreach (char c in lineWithPerhapsOnlyNumbers) { if (!char.IsDigit(c)) { allNumbers = false; break; } } if (allNumbers && lineWithPerhapsOnlyNumbers.Length > 5) { string[] arr = line.Replace('-', ' ').Replace('>', ' ').Replace('{', ' ').Replace('}', ' ').Replace('[', ' ').Replace(']', ' ').Trim().Split(splitChars, StringSplitOptions.RemoveEmptyEntries); if (arr.Length == 2) { string[] start = arr[0].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); string[] end = arr[1].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); if ((start.Length == 3 || start.Length == 4) && (end.Length == 3 || end.Length == 4)) { if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } p = new Paragraph(); sb.Clear(); p.StartTime = DecodeTime(start); p.EndTime = DecodeTime(end); } } else if (arr.Length > 3) { string[] start; string[] end; if (arr[0].Length > 9) { start = arr[0].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); end = arr[1].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); } else { start = arr[1].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); end = arr[2].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); } if ((start.Length == 3 || start.Length == 4) && (end.Length == 3 || end.Length == 4)) { if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } p = new Paragraph(); sb = new StringBuilder(); p.StartTime = DecodeTime(start); p.EndTime = DecodeTime(end); } } } if (p != null && !allNumbers && line.Length > 1) { line = line.Trim(); if (line.StartsWith("}{}", StringComparison.Ordinal) || line.StartsWith("][]", StringComparison.Ordinal)) { line = line.Remove(0, 3); } sb.AppendLine(line.Trim()); } } if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } double averateDuration = 0; foreach (Paragraph a in subtitle.Paragraphs) { double d = a.Duration.TotalSeconds; if (d > 10) { d = 8; } averateDuration += d; } averateDuration = averateDuration / subtitle.Paragraphs.Count; if (averateDuration < 0.2 || (averateDuration < 0.5 && subtitle.Paragraphs.Count > 100 && subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].StartTime.TotalSeconds < 140 && subtitle.Paragraphs[subtitle.Paragraphs.Count - 2].StartTime.TotalSeconds < 140)) { subtitle = ImportTimeCodesOnSameSeperateLineNoMilliseconds(lines); int i = 0; foreach (Paragraph a in subtitle.Paragraphs) { i++; var next = subtitle.GetParagraphOrDefault(i); if (next != null && a.EndTime.TotalMilliseconds >= next.StartTime.TotalMilliseconds) { a.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines; } } return(subtitle); } subtitle.Renumber(); return(subtitle); }
private static Subtitle ImportTimeCodesOnSameSeperateLineNoMilliseconds(string[] lines) { Paragraph p = null; var subtitle = new Subtitle(); var sb = new StringBuilder(); for (int idx = 0; idx < lines.Length; idx++) { string line = lines[idx]; string lineWithPerhapsOnlyNumbers = line.Replace(" ", string.Empty).Replace(".", string.Empty).Replace(",", string.Empty).Replace("\t", string.Empty).Replace(":", string.Empty).Replace(";", string.Empty).Replace("{", string.Empty).Replace("}", string.Empty).Replace("[", string.Empty).Replace("]", string.Empty).Replace("-", string.Empty).Replace(">", string.Empty).Replace("<", string.Empty); bool allNumbers = lineWithPerhapsOnlyNumbers.Length > 0; foreach (char c in lineWithPerhapsOnlyNumbers) { if (!char.IsDigit(c)) { allNumbers = false; } } if (allNumbers && lineWithPerhapsOnlyNumbers.Length > 5) { string[] arr = line.Replace("-", " ").Replace(">", " ").Replace("{", " ").Replace("}", " ").Replace("[", " ").Replace("]", " ").Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length == 2) { string[] start = arr[0].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); string[] end = arr[1].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); if ((start.Length == 3 || start.Length == 4) && (end.Length == 3 || end.Length == 4)) { if (start.Length == 3) { start = (arr[0].Trim() + ".000").Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); } if (end.Length == 3) { end = (arr[1].Trim() + ".000").Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); } if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } p = new Paragraph(); sb = new StringBuilder(); p.StartTime = DecodeTime(start); p.EndTime = DecodeTime(end); } } else if (arr.Length == 3) { string[] start = arr[0].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); string[] end = arr[1].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); string[] duration = arr[2].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); if (start.Length == 3) { start = (arr[0].Trim() + ".000").Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); } if (end.Length == 3) { end = (arr[1].Trim() + ".000").Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); } if (duration.Length == 3) { duration = (arr[2].Trim() + ".000").Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); } if (start.Length < 3) { start = end; end = duration; } if ((start.Length == 3 || start.Length == 4) && (end.Length == 3 || end.Length == 4)) { if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } p = new Paragraph(); sb = new StringBuilder(); p.StartTime = DecodeTime(start); p.EndTime = DecodeTime(end); } } } if (p != null && !allNumbers && line.Length > 1) { line = line.Trim(); if (line.StartsWith("}{}") || line.StartsWith("][]")) { line = line.Remove(0, 3); } sb.AppendLine(line.Trim()); } } if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } subtitle.Renumber(); return(subtitle); }
private static Subtitle ImportTimeCodesAndTextOnSameLineOnlySpaceAsSeparator(List <string> lines) { var regexTimeCodes1 = new Regex(@"\d+ {1}\d\d {1}\d\d {1}\d+", RegexOptions.Compiled); var regexTimeCodes2 = new Regex(@"\d+ {1}\d\d {1}\d+", RegexOptions.Compiled); Paragraph p = null; var subtitle = new Subtitle(); var sb = new StringBuilder(); char[] splitChar = { ' ' }; for (int idx = 0; idx < lines.Count; idx++) { string line = lines[idx]; var matches = regexTimeCodes1.Matches(line); if (matches.Count == 0) { matches = regexTimeCodes2.Matches(line); } if (matches.Count == 2) { string[] start = matches[0].ToString().Split(splitChar, StringSplitOptions.RemoveEmptyEntries); string[] end = matches[1].ToString().Split(splitChar, StringSplitOptions.RemoveEmptyEntries); if ((start.Length == 3 || start.Length == 4) && (end.Length == 3 || end.Length == 4)) { if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } p = new Paragraph(); sb.Clear(); p.StartTime = DecodeTime(start); p.EndTime = DecodeTime(end); } if (matches[0].Index < 9) { line = line.Remove(0, matches[0].Index); } line = line.Replace(matches[0].ToString(), string.Empty); line = line.Replace(matches[1].ToString(), string.Empty); line = line.Trim(); if (line.StartsWith("}{}", StringComparison.Ordinal) || line.StartsWith("][]", StringComparison.Ordinal)) { line = line.Remove(0, 3); } line = line.Trim(); } if (p != null && line.Length > 1) { sb.AppendLine(line.Trim()); } } if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } subtitle.Renumber(); return(subtitle); }
private Subtitle ImportTimeCodesInFramesAndTextOnSameLine(string[] lines) { var regexTimeCodes1 = new Regex(@"\d+", RegexOptions.Compiled); Paragraph p = null; var subtitle = new Subtitle(); var sb = new StringBuilder(); for (int idx = 0; idx < lines.Length; idx++) { string line = lines[idx]; var matches = regexTimeCodes1.Matches(line); if (matches.Count >= 2) { string start = matches[0].ToString(); string end = matches[1].ToString(); if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } p = new Paragraph(); sb.Clear(); try { if (UseFrames) { p.StartFrame = int.Parse(start); p.EndFrame = int.Parse(end); p.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate); } else { p.StartTime.TotalMilliseconds = double.Parse(start); p.EndTime.TotalMilliseconds = double.Parse(end); } } catch { p = null; } if (matches[0].Index < 9) { line = line.Remove(0, matches[0].Index); } line = line.Replace(matches[0].ToString(), string.Empty); line = line.Replace(matches[1].ToString(), string.Empty); line = line.Trim(); if (line.StartsWith("}{}", StringComparison.Ordinal) || line.StartsWith("][]", StringComparison.Ordinal)) { line = line.Remove(0, 3); } line = line.Trim(); } if (p != null && line.Length > 1) { sb.AppendLine(line.Trim()); if (sb.Length > 200) { return(new Subtitle()); } } } if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } subtitle.Renumber(); return(subtitle); }
private static Subtitle ImportTimeCodesOnSameSeperateLine(string[] lines) { Paragraph p = null; var subtitle = new Subtitle(); var sb = new StringBuilder(); for (int idx = 0; idx < lines.Length; idx++) { string line = lines[idx]; string lineWithPerhapsOnlyNumbers = line.Replace(" ", string.Empty).Replace(".", string.Empty).Replace(",", string.Empty).Replace("\t", string.Empty).Replace(":", string.Empty).Replace(";", string.Empty).Replace("{", string.Empty).Replace("}", string.Empty).Replace("[", string.Empty).Replace("]", string.Empty).Replace("-", string.Empty).Replace(">", string.Empty).Replace("<", string.Empty); bool allNumbers = lineWithPerhapsOnlyNumbers.Length > 0; foreach (char c in lineWithPerhapsOnlyNumbers) { if (!char.IsDigit(c)) { allNumbers = false; } } if (allNumbers && lineWithPerhapsOnlyNumbers.Length > 5) { string[] arr = line.Replace("-", " ").Replace(">", " ").Replace("{", " ").Replace("}", " ").Replace("[", " ").Replace("]", " ").Trim().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length == 2) { string[] start = arr[0].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); string[] end = arr[1].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); if ((start.Length == 3 || start.Length == 4) && (end.Length == 3 || end.Length == 4)) { if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } p = new Paragraph(); sb = new StringBuilder(); p.StartTime = DecodeTime(start); p.EndTime = DecodeTime(end); } } else if (arr.Length == 3) { string[] start = arr[0].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); string[] end = arr[1].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); string[] duration = arr[2].Trim().Split(new[] { '.', ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries); if (start.Length < 3) { start = end; end = duration; } if ((start.Length == 3 || start.Length == 4) && (end.Length == 3 || end.Length == 4)) { if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } p = new Paragraph(); sb = new StringBuilder(); p.StartTime = DecodeTime(start); p.EndTime = DecodeTime(end); } } } if (p != null && !allNumbers && line.Length > 1) { line = line.Trim(); if (line.StartsWith("}{}") || line.StartsWith("][]")) { line = line.Remove(0, 3); } sb.AppendLine(line.Trim()); } } if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } double averateDuration = 0; foreach (Paragraph a in subtitle.Paragraphs) { double d = a.Duration.TotalSeconds; if (d > 10) { d = 8; } averateDuration += d; } averateDuration = averateDuration / subtitle.Paragraphs.Count; if (averateDuration < 0.2 || (averateDuration < 0.5 && subtitle.Paragraphs.Count > 100 && subtitle.Paragraphs[subtitle.Paragraphs.Count - 1].StartTime.TotalSeconds < 140 && subtitle.Paragraphs[subtitle.Paragraphs.Count - 2].StartTime.TotalSeconds < 140)) { subtitle = ImportTimeCodesOnSameSeperateLineNoMilliseconds(lines); int i = 0; foreach (Paragraph a in subtitle.Paragraphs) { i++; var next = subtitle.GetParagraphOrDefault(i); if (next != null && a.EndTime.TotalMilliseconds >= next.StartTime.TotalMilliseconds) { a.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines; } } return(subtitle); } subtitle.Renumber(); return(subtitle); }
private static Subtitle ImportTimeCodesOnSameSeperateLineNoMilliseconds(string[] lines) { Paragraph p = null; var subtitle = new Subtitle(); var sb = new StringBuilder(); char[] splitChar = { ' ' }; for (int idx = 0; idx < lines.Length; idx++) { string line = lines[idx]; string lineWithPerhapsOnlyNumbers = GetLineWithPerhapsOnlyNumbers(line); bool allNumbers = lineWithPerhapsOnlyNumbers.Length > 0; foreach (char c in lineWithPerhapsOnlyNumbers) { if (!char.IsDigit(c)) { allNumbers = false; } } if (allNumbers && lineWithPerhapsOnlyNumbers.Length > 5) { string[] arr = line.Replace('-', ' ').Replace('>', ' ').Replace('{', ' ').Replace('}', ' ').Replace('[', ' ').Replace(']', ' ').Trim().Split(splitChar, StringSplitOptions.RemoveEmptyEntries); if (arr.Length == 2) { string[] start = arr[0].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); string[] end = arr[1].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); if ((start.Length == 3 || start.Length == 4) && (end.Length == 3 || end.Length == 4)) { if (start.Length == 3) { start = (arr[0].Trim() + ".000").Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); } if (end.Length == 3) { end = (arr[1].Trim() + ".000").Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); } if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } p = new Paragraph(); sb.Clear(); p.StartTime = DecodeTime(start); p.EndTime = DecodeTime(end); } } else if (arr.Length == 3) { string[] start = arr[0].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); string[] end = arr[1].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); string[] duration = arr[2].Trim().Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); if (start.Length == 3) { start = (arr[0].Trim() + ".000").Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); } if (end.Length == 3) { end = (arr[1].Trim() + ".000").Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); } if (duration.Length == 3) { duration = (arr[2].Trim() + ".000").Split(ExpectedSplitChars, StringSplitOptions.RemoveEmptyEntries); } if (start.Length < 3) { start = end; end = duration; } if ((start.Length == 3 || start.Length == 4) && (end.Length == 3 || end.Length == 4)) { if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } p = new Paragraph(); sb.Clear(); p.StartTime = DecodeTime(start); p.EndTime = DecodeTime(end); } } } if (p != null && !allNumbers && line.Length > 1) { line = line.Trim(); if (line.StartsWith("}{}", StringComparison.Ordinal) || line.StartsWith("][]", StringComparison.Ordinal)) { line = line.Remove(0, 3); } sb.AppendLine(line.Trim()); } } if (p != null) { p.Text = sb.ToString().Trim(); subtitle.Paragraphs.Add(p); } subtitle.Renumber(); return(subtitle); }