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
8 using System.Collections.Generic;
\r
10 using System.Text.RegularExpressions;
\r
12 namespace Handbrake.Parsing
\r
15 /// An object that represents a subtitle associated with a Title, in a DVD
\r
17 public class Subtitle
\r
19 private int m_trackNumber;
\r
21 /// The track number of this Subtitle
\r
23 public int TrackNumber
\r
27 return this.m_trackNumber;
\r
31 private string m_language;
\r
33 /// The language (if detected) of this Subtitle
\r
35 public string Language
\r
39 return this.m_language;
\r
44 /// Override of the ToString method to make this object easier to use in the UI
\r
46 /// <returns>A string formatted as: {track #} {language}</returns>
\r
47 public override string ToString()
\r
49 return string.Format("{0} {1}", this.m_trackNumber, this.m_language);
\r
52 public static Subtitle Parse(StringReader output)
\r
54 string curLine = output.ReadLine();
\r
56 Match m = Regex.Match(curLine, @"^ \+ ([0-9]*), ([A-Za-z, ]*) \((.*)\)");
\r
57 if (m.Success && !curLine.Contains("HandBrake has exited."))
\r
59 Subtitle thisSubtitle = new Subtitle();
\r
60 thisSubtitle.m_trackNumber = int.Parse(m.Groups[1].Value.Trim().ToString());
\r
61 thisSubtitle.m_language = m.Groups[2].Value;
\r
62 return thisSubtitle;
\r
68 public static Subtitle[] ParseList(StringReader output)
\r
70 List<Subtitle> subtitles = new List<Subtitle>();
\r
71 while ((char)output.Peek() != '+')
\r
73 Subtitle thisSubtitle = Subtitle.Parse(output);
\r
75 if (thisSubtitle != null)
\r
76 subtitles.Add(thisSubtitle);
\r
80 return subtitles.ToArray();
\r