2 This file is part of the HandBrake source code.
\r
3 Homepage: <http://handbrake.fr>.
\r
4 It may be used under the terms of the GNU General Public License. */
\r
6 namespace Handbrake.Parsing
\r
8 using System.Collections.Generic;
\r
10 using System.Text.RegularExpressions;
\r
13 /// An object that represents a subtitle associated with a Title, in a DVD
\r
15 public class Subtitle
\r
20 private string language;
\r
23 /// The Track Number
\r
25 private int trackNumber;
\r
28 /// The type of subtitle
\r
30 private string type;
\r
35 private string typecode;
\r
38 /// Gets the track number of this Subtitle
\r
40 public int TrackNumber
\r
42 get { return trackNumber; }
\r
46 /// Gets the The language (if detected) of this Subtitle
\r
48 public string Language
\r
50 get { return language; }
\r
54 /// Gets the Langauage Code
\r
56 public string LanguageCode
\r
58 get { return typecode; }
\r
62 /// Gets the Subtitle Type
\r
66 get { return type; }
\r
70 /// Parse the input strings related to subtitles
\r
72 /// <param name="output">
\r
76 /// A Subitle object
\r
78 public static Subtitle Parse(StringReader output)
\r
80 string curLine = output.ReadLine();
\r
82 Match m = Regex.Match(curLine, @"^ \+ ([0-9]*), ([A-Za-z, ]*) \((.*)\) \(([a-zA-Z]*)\)");
\r
83 if (m.Success && !curLine.Contains("HandBrake has exited."))
\r
85 var thisSubtitle = new Subtitle
\r
87 trackNumber = int.Parse(m.Groups[1].Value.Trim()),
\r
88 language = m.Groups[2].Value,
\r
89 typecode = m.Groups[3].Value,
\r
90 type = m.Groups[4].Value
\r
92 return thisSubtitle;
\r
98 /// Parse a list of Subtitle tracks from an input string.
\r
100 /// <param name="output">
\r
104 /// An array of Subtitle objects
\r
106 public static IEnumerable<Subtitle> ParseList(StringReader output)
\r
108 var subtitles = new List<Subtitle>();
\r
109 while ((char) output.Peek() != '+')
\r
111 Subtitle thisSubtitle = Parse(output);
\r
113 if (thisSubtitle != null)
\r
114 subtitles.Add(thisSubtitle);
\r
118 return subtitles.ToArray();
\r
122 /// Override of the ToString method to make this object easier to use in the UI
\r
124 /// <returns>A string formatted as: {track #} {language}</returns>
\r
125 public override string ToString()
\r
127 return string.Format("{0} {1} ({2})", trackNumber, language, type);
\r