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
20 private string m_type;
\r
21 private string m_typecode;
\r
24 /// The track number of this Subtitle
\r
26 public int TrackNumber
\r
28 get { return m_trackNumber; }
\r
32 /// The language (if detected) of this Subtitle
\r
34 public string Language
\r
36 get { return m_language; }
\r
42 public string LanguageCode
\r
44 get { return m_typecode; }
\r
53 get { return m_type; }
\r
58 /// Override of the ToString method to make this object easier to use in the UI
\r
60 /// <returns>A string formatted as: {track #} {language}</returns>
\r
61 public override string ToString()
\r
63 return string.Format("{0} {1} ({2})", m_trackNumber, m_language, m_type);
\r
66 public static Subtitle Parse(StringReader output)
\r
68 string curLine = output.ReadLine();
\r
70 Match m = Regex.Match(curLine, @"^ \+ ([0-9]*), ([A-Za-z, ]*) \((.*)\) \(([a-zA-Z]*)\)");
\r
71 if (m.Success && !curLine.Contains("HandBrake has exited."))
\r
73 var thisSubtitle = new Subtitle
\r
75 m_trackNumber = int.Parse(m.Groups[1].Value.Trim()),
\r
76 m_language = m.Groups[2].Value,
\r
77 m_typecode = m.Groups[3].Value,
\r
78 m_type = m.Groups[4].Value
\r
80 return thisSubtitle;
\r
85 public static Subtitle[] ParseList(StringReader output)
\r
87 var subtitles = new List<Subtitle>();
\r
88 while ((char) output.Peek() != '+')
\r
90 Subtitle thisSubtitle = Parse(output);
\r
92 if (thisSubtitle != null)
\r
93 subtitles.Add(thisSubtitle);
\r
97 return subtitles.ToArray();
\r