3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
7 using System.Collections.Generic;
\r
9 using System.Text.RegularExpressions;
\r
11 namespace Handbrake.Parsing
\r
14 /// An object that represents a subtitle associated with a Title, in a DVD
\r
16 public class Subtitle
\r
18 private string m_language;
\r
19 private int m_trackNumber;
\r
22 /// The track number of this Subtitle
\r
24 public int TrackNumber
\r
26 get { return m_trackNumber; }
\r
30 /// The language (if detected) of this Subtitle
\r
32 public string Language
\r
34 get { return m_language; }
\r
38 /// Override of the ToString method to make this object easier to use in the UI
\r
40 /// <returns>A string formatted as: {track #} {language}</returns>
\r
41 public override string ToString()
\r
43 return string.Format("{0} {1}", m_trackNumber, m_language);
\r
46 public static Subtitle Parse(StringReader output)
\r
48 string curLine = output.ReadLine();
\r
50 Match m = Regex.Match(curLine, @"^ \+ ([0-9]*), ([A-Za-z, ]*) \((.*)\)");
\r
51 if (m.Success && !curLine.Contains("HandBrake has exited."))
\r
53 var thisSubtitle = new Subtitle();
\r
54 thisSubtitle.m_trackNumber = int.Parse(m.Groups[1].Value.Trim());
\r
55 thisSubtitle.m_language = m.Groups[2].Value;
\r
56 return thisSubtitle;
\r
62 public static Subtitle[] ParseList(StringReader output)
\r
64 var subtitles = new List<Subtitle>();
\r
65 while ((char) output.Peek() != '+')
\r
67 Subtitle thisSubtitle = Parse(output);
\r
69 if (thisSubtitle != null)
\r
70 subtitles.Add(thisSubtitle);
\r
74 return subtitles.ToArray();
\r