public SubZir ParseStream(Stream xmlStream, Encoding encoding) { xmlStream.Position = 0; var items = new SubZir(); var xElement = XElement.Load(xmlStream); XNamespace tt = xElement.GetNamespaceOfPrefix("tt"); if (xElement != null) { var nodeList = xElement.Descendants(tt + "p").ToList(); if (nodeList != null) { for (var i = 0; i < nodeList.Count; i++) { var node = nodeList[i]; try { var reader = node.CreateReader(); reader.MoveToContent(); var beginString = node.Attribute("begin").Value.Replace("t", ""); long startTicks = long.Parse(beginString); var endString = node.Attribute("end").Value.Replace("t", ""); long endTicks = long.Parse(endString); var text = reader.ReadInnerXml().Replace("<tt:", "<").Replace("</tt:", "</").Replace(string.Format(@" xmlns:tt=""{0}""", tt), ""); items.Add(new SubtitleItem() { StartTime = (int)(startTicks / 10000), EndTime = (int)(endTicks / 10000), Lines = new List <string>() { text } }); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("Exception raised when parsing xml node {0}: {1}", node, ex)); } } } } if (items.Any()) { return(items); } else { throw new ArgumentException("Stream is not in a valid TTML format, or represents empty subtitles"); } }
public SubZir ParseStream(Stream subStream, Encoding encoding) { subStream.Position = 0; var items = new SubZir(); var reader = new StreamReader(subStream, encoding, true); string reshte = reader.ReadToEnd(); JsonArray jsonArray; if (JsonArray.TryParse(reshte, out jsonArray)) { //try { foreach (JsonValue groupValue in jsonArray) { JsonObject groupObject = groupValue.GetObject(); JsonObject itemObject = groupObject.GetObject(); //try { double startText = itemObject["startTime"].GetNumber(); double endText = itemObject["endTime"].GetNumber(); int start = ParseJSONTimecode(startText.ToString()); int end = ParseJSONTimecode(endText.ToString()); JsonObject itemObject2 = itemObject["metadata"].GetObject(); string text = itemObject2["Text"].GetString(); //<br /> items.Add(new SubtitleItem { StartTime = start, EndTime = end, Lines = new List <string>(text.Split(new string[] { "<br />", Environment.NewLine, "<br/>", "/<br>" }, StringSplitOptions.RemoveEmptyEntries)) }); } //catch { } } } //catch (Exception ex) //{ //} } if (items.Any()) { return(items); } else { throw new ArgumentException("Stream is not in a valid JSON4 format"); } }
private void Dt_Tick(object sender, object e) { try { if (SubtitleList != null && SubtitleList.Any() && showSubtitle) { var v = (from item in SubtitleList where item != null && item.StartTime + seekDouble <= mediaElement.Position.TotalMilliseconds && item.EndTime + seekDouble >= mediaElement.Position.TotalMilliseconds orderby item descending select item).FirstOrDefault(); CurrentSubtitleItem = v; if (v != null) { customMTC.SubtitleText.Blocks.Clear(); Paragraph myParagraph = new Paragraph(); int nextParagraph = 1; foreach (string item in v.Lines) { if (GetRun(item) != null) { myParagraph.Inlines.Add(GetRun(item.Replace("ي", "ی"))); try { if (v.Lines.Count < nextParagraph && v.Lines[nextParagraph] != null) { myParagraph.Inlines.Add(new LineBreak()); } } catch (Exception ex) { HelperUP.Output("nextParagraph ex: " + ex.Message); } } nextParagraph++; } customMTC.SubtitleText.Blocks.Add(myParagraph); customMTC.ShadowBorder.Visibility = customMTC.SubtitleText.Visibility = Windows.UI.Xaml.Visibility.Visible; } else { customMTC.ShadowBorder.Visibility = customMTC.SubtitleText.Visibility = Windows.UI.Xaml.Visibility.Collapsed; customMTC.SubtitleText.Blocks.Clear(); } } else { customMTC.SubtitleText.Blocks.Clear(); } } catch (Exception ex) { HelperUP.Output("mediaPlayer_PositionChanged ex: " + ex.Message); } }
public SubZir ParseStream(Stream xmlStream, Encoding encoding) { xmlStream.Position = 0; var items = new SubZir(); StreamReader st = new StreamReader(xmlStream, encoding, true); string reshte = st.ReadToEnd(); XmlDocument document = new XmlDocument(); document.LoadXml(reshte); XmlNodeList list = document.SelectSingleNode("USFSubtitles").SelectSingleNode("subtitles").SelectNodes("subtitle"); for (int j = 0; j < list.Count; j++) { try { string startText = "", endText = "", text = ""; startText = list[j].Attributes.GetNamedItem("start").InnerText; endText = list[j].Attributes.GetNamedItem("stop").InnerText; text = list[j].SelectSingleNode("text").InnerText; int start = ParseSrtTimecode(startText); int end = ParseSrtTimecode(endText); items.Add(new SubtitleItem() { StartTime = start, EndTime = end, Lines = new List <string>() { text } }); } catch { } } if (items.Any()) { return(items); } else { throw new ArgumentException("Stream is not in a valid Universal Subtitle XML format"); } }
public SubZir ParseStream(Stream stream, Encoding encoding) { stream.Position = 0; var items = new SubZir(); var reader = new StreamReader(stream, encoding, true); string reshte = reader.ReadToEnd(); SubZir subZir = new SubZir(); try { LoadSubtitle(subZir, reshte); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("SamiParser ex: " + ex.Message); } if (subZir.Any()) { return(subZir); } else { throw new ArgumentException("Stream is not in a valid Sami format"); } }
public SubZir ParseStream(Stream srtStream, Encoding encoding) { if (!srtStream.CanRead || !srtStream.CanSeek) { var message = string.Format("Stream must be seekable and readable in a subtitles parser. " + "Operation interrupted; isSeekable: {0} - isReadable: {1}", srtStream.CanSeek, srtStream.CanSeek); throw new ArgumentException(message); } srtStream.Position = 0; var reader = new StreamReader(srtStream, encoding, true); var items = new SubZir(); var srtSubParts = GetSrtSubTitleParts(reader).ToList(); if (srtSubParts.Any()) { foreach (var srtSubPart in srtSubParts) { var lines = srtSubPart.Split(new string[] { Environment.NewLine }, StringSplitOptions.None) .Select(s => s.Trim()) .Where(l => !string.IsNullOrEmpty(l)) .ToList(); var item = new SubtitleItem(); foreach (var line in lines) { if (item.StartTime == 0 && item.EndTime == 0) { int startTc; int endTc; var success = TryParseTimecodeLine(line, out startTc, out endTc); if (success) { item.StartTime = startTc; item.EndTime = endTc; } } else { item.Lines.Add(line + Environment.NewLine); } } if ((item.StartTime != 0 || item.EndTime != 0) && item.Lines.Any()) { items.Add(item); } } if (items.Any()) { return(items); } else { throw new ArgumentException("Stream is not in a valid Srt format"); } } else { throw new FormatException("Parsing as srt returned no srt part."); } }
public SubZir ParseStream(Stream stream, Encoding encoding) { stream.Position = 0; SubZir items = new SubZir(); Regex regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d:\d\d\\\d\d:\d\d:\d\d:\d\d$"); StreamReader st = new StreamReader(stream, encoding, true); string reshte = st.ReadToEnd(); List <string> lines = new List <string>(reshte.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)); var sb = new StringBuilder(); SubtitleItem p = null; int _errorCount = 0; foreach (string line in lines) { string s = line.Trim(); if (regexTimeCodes.IsMatch(s)) { var temp = s.Split('\\'); if (temp.Length > 1) { string start = temp[0]; string end = temp[1]; string[] startParts = start.Split(new[] { ':', '.' }, StringSplitOptions.RemoveEmptyEntries); string[] endParts = end.Split(new[] { ':', '.' }, StringSplitOptions.RemoveEmptyEntries); if (startParts.Length == 4 && endParts.Length == 4) { try { p = new SubtitleItem(); p.StartTime = DecodeTimeCode(startParts); p.EndTime = DecodeTimeCode(endParts); string text = sb.ToString().Trim(); Boolean positionTop = false; if (text.StartsWith("}")) { positionTop = true; text = text.Remove(0, 1); } text = text.Replace("[", @"<i>"); text = text.Replace("]", @"</i>"); text = text.Replace("</i>" + Environment.NewLine + "<i>", Environment.NewLine); if (positionTop) { text = "{\\an8}" + text; } p.Lines = new List <string>() { text }; if (text.Length > 0) { items.Add(p); } sb = new StringBuilder(); } catch (Exception exception) { _errorCount++; System.Diagnostics.Debug.WriteLine(exception.Message); } } } } else if (string.IsNullOrWhiteSpace(line) || line.StartsWith("*")) { } else if (p != null) { sb.AppendLine(line); } } if (items.Any()) { return(items); } else { throw new ArgumentException("Stream is not in a valid 'SoftNi colon sub' Subtitle format"); } }
public SubZir ParseStream(Stream stream, Encoding encoding) { stream.Position = 0; SubZir items = new SubZir(); Regex regexTimeCodes = new Regex(@"^\d\d\d\d \d\d:\d\d:\d\d:\d\d \d\d:\d\d:\d\d:\d\d"); Regex regex1DigitMilliseconds = new Regex(@"^\d\d\d\d \d\d\d:\d\d:\d\d:\d \d\d\d:\d\d:\d\d:\d"); StreamReader st = new StreamReader(stream, encoding, true); string reshte = st.ReadToEnd(); List <string> lines = new List <string>(reshte.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)); var sb = new StringBuilder(); SubtitleItem lastParagraph = null; int _errorCount = 0; foreach (string line in lines) { if (string.IsNullOrWhiteSpace(line)) { continue; } bool success = false; if (line.IndexOf(':') > 0) { string s = line; var match = regexTimeCodes.Match(s); var match1DigitMilliseconds = regex1DigitMilliseconds.Match(s); if (s.Length > 31 && match.Success) { s = s.Substring(5, match.Length - 5).TrimStart(); s = s.Replace(" ", ":"); s = s.Replace(" ", string.Empty); string[] parts = s.Split(':'); if (parts.Length == 8) { int hours = int.Parse(parts[0]); int minutes = int.Parse(parts[1]); int seconds = int.Parse(parts[2]); int milliseconds = int.Parse(parts[3]) * 10; int start = int.Parse(new TimeSpan(0, hours, minutes, seconds, milliseconds).TotalMilliseconds.ToString()); hours = int.Parse(parts[4]); minutes = int.Parse(parts[5]); seconds = int.Parse(parts[6]); milliseconds = int.Parse(parts[7]) * 10; int end = int.Parse(new TimeSpan(0, hours, minutes, seconds, milliseconds).TotalMilliseconds.ToString()); string text = line.Replace("\0", string.Empty).Substring(match.Length).TrimStart(); text = text.Replace("|", Environment.NewLine); lastParagraph = new SubtitleItem(); lastParagraph.StartTime = start; lastParagraph.EndTime = end; lastParagraph.Lines = new List <string>() { text }; items.Add(lastParagraph); success = true; } } else if (s.Length > 29 && match1DigitMilliseconds.Success) { s = s.Substring(5, match1DigitMilliseconds.Length - 5).TrimStart(); s = s.Replace(" ", ":"); s = s.Replace(" ", string.Empty); string[] parts = s.Split(':'); if (parts.Length == 8) { int hours = int.Parse(parts[0]); int minutes = int.Parse(parts[1]); int seconds = int.Parse(parts[2]); int milliseconds = int.Parse(parts[3]) * 10; int start = int.Parse(new TimeSpan(0, hours, minutes, seconds, milliseconds).TotalMilliseconds.ToString()); hours = int.Parse(parts[4]); minutes = int.Parse(parts[5]); seconds = int.Parse(parts[6]); milliseconds = int.Parse(parts[7]) * 10; int end = int.Parse(new TimeSpan(0, hours, minutes, seconds, milliseconds).TotalMilliseconds.ToString()); string text = line.Replace("\0", string.Empty).Substring(match1DigitMilliseconds.Length).TrimStart(); text = text.Replace("|", Environment.NewLine); lastParagraph = new SubtitleItem(); lastParagraph.StartTime = start; lastParagraph.EndTime = end; lastParagraph.Lines = new List <string>() { text }; items.Add(lastParagraph); success = true; } } } if (!success) { _errorCount++; } } if (items.Any()) { return(items); } else { throw new ArgumentException("Stream is not in a valid 'Sony DVDArchitect w. line#' Subtitle format"); } }
public SubZir ParseStream(Stream subStream, Encoding encoding) { if (!subStream.CanRead || !subStream.CanSeek) { var message = string.Format("Stream must be seekable and readable in a subtitles parser. " + "Operation interrupted; isSeekable: {0} - isReadable: {1}", subStream.CanSeek, subStream.CanSeek); throw new ArgumentException(message); } subStream.Position = 0; var reader = new StreamReader(subStream, encoding, true); var items = new SubZir(); var line = reader.ReadLine(); while (line != null && !IsMicroDvdLine(line)) { line = reader.ReadLine(); } if (line != null) { float frameRate; var firstItem = ParseLine(line, defaultFrameRate); if (firstItem.Lines != null && firstItem.Lines.Any()) { var success = TryExtractFrameRate(firstItem.Lines[0], out frameRate); if (!success) { System.Diagnostics.Debug.WriteLine(string.Format("Couldn't extract frame rate of sub file with first line {0}. " + "We use the default frame rate: {1}", line, defaultFrameRate)); frameRate = defaultFrameRate; items.Add(firstItem); } } else { frameRate = defaultFrameRate; } line = reader.ReadLine(); while (line != null) { if (!string.IsNullOrEmpty(line)) { var item = ParseLine(line, frameRate); items.Add(item); } line = reader.ReadLine(); } } if (items.Any()) { return(items); } else { throw new ArgumentException("Stream is not in a valid MicroDVD format"); } }
public SubZir ParseStream(Stream stream, Encoding encoding) { stream.Position = 0; Regex regexTimeCodes = new Regex(@"^\{T\ \d+:\d+:\d+:\d+$"); StreamReader st = new StreamReader(stream, encoding, true); string reshte = st.ReadToEnd(); List <string> lines = new List <string>(reshte.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)); //{T 00:00:14:01 //تقديم به تمام پارسي زبانان جهان //} //{T 00:00:20:97 //} items.Clear(); int _errorCount = 0; bool textOn = false; string text = string.Empty; double start = 0; double end = 0; foreach (string line in lines) { if (textOn) { if (line.Trim() == "}") { SubtitleItem s = new SubtitleItem(); s.StartTime = int.Parse(start.ToString()); s.EndTime = int.Parse(end.ToString()); s.Lines = new List <string>() { text }; items.Add(s); text = string.Empty; start = 0; end = 0; textOn = false; } else { if (text.Length == 0) { text = line; } else { text += Environment.NewLine + line; } } } else { if (regexTimeCodes.Match(line).Success) { try { textOn = true; string[] arr = line.Substring(3).Trim().Split(':'); if (arr.Length == 4) { int hours = int.Parse(arr[0]); int minutes = int.Parse(arr[1]); int seconds = int.Parse(arr[2]); int milliseconds = int.Parse(arr[3]); if (arr[3].Length == 2) { milliseconds *= 10; } TimeSpan t = new TimeSpan(0, hours, minutes, seconds, milliseconds); start = t.TotalMilliseconds; } } catch { textOn = false; _errorCount++; } } } } int index = 1; foreach (SubtitleItem s in items) { foreach (string line in s.Lines) { SubtitleItem next = GetParagraphOrDefault(index); if (next != null) { s.EndTime = next.StartTime; } } index++; } int counter = 0; SubZir customList = new SubZir(); foreach (var item in items) { if (counter % 2 == 0) { customList.Add(item); } counter++; } items.Clear(); items.AddRange(customList); if (items.Any()) { return(items); } else { throw new ArgumentException("Stream is not in a valid 'DVD Subtitle' format"); } }
public SubZir ParseStream(Stream ssaStream, Encoding encoding) { if (!ssaStream.CanRead || !ssaStream.CanSeek) { var message = string.Format("Stream must be seekable and readable in a subtitles parser. " + "Operation interrupted; isSeekable: {0} - isReadable: {1}", ssaStream.CanSeek, ssaStream.CanSeek); throw new ArgumentException(message); } ssaStream.Position = 0; var reader = new StreamReader(ssaStream, encoding, true); var line = reader.ReadLine(); var lineNumber = 1; while (line != null && line != EventLine) { line = reader.ReadLine(); lineNumber++; } if (line != null) { var headerLine = reader.ReadLine(); if (!string.IsNullOrEmpty(headerLine)) { var columnHeaders = headerLine.Split(Separator).Select(head => head.Trim()).ToList(); var startIndexColumn = columnHeaders.IndexOf(StartColumn); var endIndexColumn = columnHeaders.IndexOf(EndColumn); var textIndexColumn = columnHeaders.IndexOf(TextColumn); if (startIndexColumn > 0 && endIndexColumn > 0 && textIndexColumn > 0) { var items = new SubZir(); line = reader.ReadLine(); while (line != null) { if (!string.IsNullOrEmpty(line)) { var columns = line.Split(Separator); var startText = columns[startIndexColumn]; var endText = columns[endIndexColumn]; var textLine = string.Join(",", columns.Skip(textIndexColumn)); var start = ParseAssTimecode(startText); var end = ParseAssTimecode(endText); if (start > 0 && end > 0 && !string.IsNullOrEmpty(textLine)) { var item = new SubtitleItem() { StartTime = start, EndTime = end, Lines = new List <string>() { textLine.Replace("\\N", Environment.NewLine).Replace("\\n", Environment.NewLine) } }; items.Add(item); } } line = reader.ReadLine(); } if (items.Any()) { return(items); } else { throw new ArgumentException("Stream is not in a valid Ssa format"); } } else { var message = string.Format("Couldn't find all the necessary columns " + "headers ({0}, {1}, {2}) in header line {3}", StartColumn, EndColumn, TextColumn, headerLine); throw new ArgumentException(message); } } else { var message = string.Format("The header line after the line '{0}' was null -> " + "no need to continue parsing", line); throw new ArgumentException(message); } } else { var message = string.Format("We reached line '{0}' with line number #{1} without finding to " + "Event section ({2})", line, lineNumber, EventLine); throw new ArgumentException(message); } }
public SubZir ParseStream(Stream stream, Encoding encoding) { stream.Position = 0; SubZir items = new SubZir(); Regex regexTimeCodes = new Regex(@"^\[\d\d:\d\d:\d\d\]$"); StreamReader st = new StreamReader(stream, encoding, true); string reshte = st.ReadToEnd(); List <string> lines = new List <string>(reshte.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)); var sb = new StringBuilder(); SubtitleItem paragraph = new SubtitleItem(); ExpectingLine expecting = ExpectingLine.TimeStart; int _errorCount = 0; foreach (string line in lines) { if (line.StartsWith("[") && regexTimeCodes.IsMatch(line)) { string[] parts = line.Split(new[] { ':', ']', '[', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 3) { try { int startHours = int.Parse(parts[0]); int startMinutes = int.Parse(parts[1]); int startSeconds = int.Parse(parts[2]); var tc = int.Parse(new TimeSpan(0, startHours, startMinutes, startSeconds, 0).TotalMilliseconds.ToString()); if (expecting == ExpectingLine.TimeStart) { paragraph = new SubtitleItem(); paragraph.StartTime = tc; expecting = ExpectingLine.Text; } else if (expecting == ExpectingLine.TimeEnd) { paragraph.EndTime = tc; expecting = ExpectingLine.TimeStart; items.Add(paragraph); paragraph = new SubtitleItem(); } } catch { _errorCount++; expecting = ExpectingLine.TimeStart; } } } else { if (expecting == ExpectingLine.Text) { if (line.Length > 0) { string text = line.Replace("|", Environment.NewLine); paragraph.Lines = new List <string>() { text }; expecting = ExpectingLine.TimeEnd; } } } } if (items.Any()) { return(items); } else { throw new ArgumentException("Stream is not in a valid 'SubViewer 1.0' Subtitle format"); } }
public SubZir ParseStream(Stream stream, Encoding encoding) { stream.Position = 0; SubZir items = new SubZir(); Regex regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d.\d+,\d\d:\d\d:\d\d.\d+$"); StreamReader st = new StreamReader(stream, encoding, true); string reshte = st.ReadToEnd(); List <string> lines = new List <string>(reshte.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)); var sb = new StringBuilder(); SubtitleItem paragraph = new SubtitleItem(); ExpectingLine expecting = ExpectingLine.TimeCodes; foreach (string line in lines) { if (regexTimeCodes.IsMatch(line)) { string[] parts = line.Split(new[] { ':', ',', '.' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 8) { try { int startHours = int.Parse(parts[0]); int startMinutes = int.Parse(parts[1]); int startSeconds = int.Parse(parts[2]); int startMilliseconds = int.Parse(parts[3]); int endHours = int.Parse(parts[4]); int endMinutes = int.Parse(parts[5]); int endSeconds = int.Parse(parts[6]); int endMilliseconds = int.Parse(parts[7]); paragraph.StartTime = int.Parse(new TimeSpan(0, startHours, startMinutes, startSeconds, startMilliseconds).TotalMilliseconds.ToString()); paragraph.EndTime = int.Parse(new TimeSpan(0, endHours, endMinutes, endSeconds, endMilliseconds).TotalMilliseconds.ToString()); expecting = ExpectingLine.Text; } catch { expecting = ExpectingLine.TimeCodes; } } } else { if (expecting == ExpectingLine.Text) { if (line.Length > 0) { string text = line.Replace("[br]", Environment.NewLine); text = text.Replace("{\\i1}", "<i>"); text = text.Replace("{\\i0}", "</i>"); text = text.Replace("{\\i}", "</i>"); text = text.Replace("{\\b1}", "<b>'"); text = text.Replace("{\\b0}", "</b>"); text = text.Replace("{\\b}", "</b>"); text = text.Replace("{\\u1}", "<u>"); text = text.Replace("{\\u0}", "</u>"); text = text.Replace("{\\u}", "</u>"); //<font color="">... آنچه گذشت</font>[br]{\i1}Ramtin{\b1}'Jokar{\b0}{\i0}[br]{\i1}SalAM{\i0} text = text.Replace("[br]", Environment.NewLine); paragraph.Lines = new List <string>() { text }; items.Add(paragraph); paragraph = new SubtitleItem(); expecting = ExpectingLine.TimeCodes; } } } } if (items.Any()) { return(items); } else { throw new ArgumentException("Stream is not in a valid 'SubViewer 2.0' Subtitle format"); } }
public SubZir ParseStream(Stream stream, Encoding encoding) { stream.Position = 0; SubZir items = new SubZir(); Regex regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d\.\d\d\d[ \t]+\d\d:\d\d:\d\d\.\d\d\d[ \t]+\d\d:\d\d:\d\d\.\d\d\d[ \t]+"); StreamReader st = new StreamReader(stream, encoding, true); string reshte = st.ReadToEnd(); List <string> lines = new List <string>(reshte.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)); SubtitleItem lastParagraph = null; int _errorCount = 0; foreach (string line in lines) { if (string.IsNullOrWhiteSpace(line)) { continue; } string s = line; bool success = false; if (s.Length > 26 && s.IndexOf(':') == 2) { var match = regexTimeCodes.Match(s); if (match.Success) { s = s.Substring(0, match.Length); s = s.Replace("\t", ":"); s = s.Replace(".", ":"); s = s.Replace(" ", string.Empty); s = s.Trim().TrimEnd(':').TrimEnd(); string[] parts = s.Split(':'); if (parts.Length == 12) { int hours = int.Parse(parts[0]); int minutes = int.Parse(parts[1]); int seconds = int.Parse(parts[2]); int milliseconds = int.Parse(parts[3]); int start = int.Parse(new TimeSpan(0, hours, minutes, seconds, milliseconds).TotalMilliseconds.ToString()); hours = int.Parse(parts[4]); minutes = int.Parse(parts[5]); seconds = int.Parse(parts[6]); milliseconds = int.Parse(parts[7]); int end = int.Parse(new TimeSpan(0, hours, minutes, seconds, milliseconds).TotalMilliseconds.ToString()); string text = line.Substring(match.Length).TrimStart(); text = text.Replace("|", Environment.NewLine); lastParagraph = new SubtitleItem(); lastParagraph.StartTime = start; lastParagraph.EndTime = end; lastParagraph.Lines = new List <string>() { text }; items.Add(lastParagraph); success = true; } } } if (!success) { _errorCount++; } } if (items.Any()) { System.Diagnostics.Debug.WriteLine("items count: " + items.Count); return(items); } else { throw new ArgumentException("Stream is not in a valid 'Sony DVDArchitect Explicit duration' Subtitle format"); } }