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
9 using System.Drawing;
\r
11 using System.Windows.Forms;
\r
12 using System.Text.RegularExpressions;
\r
14 namespace Handbrake.Parsing
\r
17 /// An object that represents a single Title of a DVD
\r
21 private List<Chapter> m_chapters;
\r
23 /// Collection of chapters in this Title
\r
25 public List<Chapter> Chapters
\r
29 return this.m_chapters;
\r
33 private List<AudioTrack> m_audioTracks;
\r
35 /// Collection of audio tracks associated with this Title
\r
37 public List<AudioTrack> AudioTracks
\r
41 return this.m_audioTracks;
\r
45 private List<Subtitle> m_subtitles;
\r
47 /// Collection of subtitles associated with this Title
\r
49 public List<Subtitle> Subtitles
\r
53 return this.m_subtitles;
\r
57 private int m_titleNumber;
\r
59 /// The track number of this Title
\r
61 public int TitleNumber
\r
65 return this.m_titleNumber;
\r
69 private TimeSpan m_duration;
\r
71 /// The length in time of this Title
\r
73 public TimeSpan Duration
\r
77 return this.m_duration;
\r
81 private Size m_resolution;
\r
83 /// The resolution (width/height) of this Title
\r
85 public Size Resolution
\r
89 return this.m_resolution;
\r
93 private float m_aspectRatio;
\r
95 /// The aspect ratio of this Title
\r
97 public float AspectRatio
\r
101 return this.m_aspectRatio;
\r
105 private int[] m_autoCrop;
\r
107 /// The automatically detected crop region for this Title.
\r
108 /// This is an int array with 4 items in it as so:
\r
114 public int[] AutoCropDimensions
\r
118 return this.m_autoCrop;
\r
123 /// The constructor for this object
\r
127 this.m_audioTracks = new List<AudioTrack>();
\r
128 this.m_chapters = new List<Chapter>();
\r
129 this.m_subtitles = new List<Subtitle>();
\r
133 /// Override of the ToString method to provide an easy way to use this object in the UI
\r
135 /// <returns>A string representing this track in the format: {title #} (00:00:00)</returns>
\r
136 public override string ToString()
\r
138 return string.Format("{0} ({1:00}:{2:00}:{3:00})", this.m_titleNumber, this.m_duration.Hours,
\r
139 this.m_duration.Minutes, this.m_duration.Seconds);
\r
142 public static Title Parse(StringReader output)
\r
144 Title thisTitle = new Title();
\r
146 Match m = Regex.Match(output.ReadLine(), @"^\+ title ([0-9]*):");
\r
147 // Match track number for this title
\r
149 thisTitle.m_titleNumber = int.Parse(m.Groups[1].Value.Trim().ToString());
\r
151 String testData = output.ReadLine();
\r
153 // Get duration for this title
\r
155 m = Regex.Match(output.ReadLine(), @"^ \+ duration: ([0-9]{2}:[0-9]{2}:[0-9]{2})");
\r
157 thisTitle.m_duration = TimeSpan.Parse(m.Groups[1].Value);
\r
159 // Get resolution, aspect ratio and FPS for this title
\r
160 m = Regex.Match(output.ReadLine(), @"^ \+ size: ([0-9]*)x([0-9]*), aspect: ([0-9]*\.[0-9]*), ([0-9]*\.[0-9]*) fps");
\r
163 thisTitle.m_resolution = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
\r
164 thisTitle.m_aspectRatio = float.Parse(m.Groups[3].Value, Functions.Encode.Culture);
\r
167 // Get autocrop region for this title
\r
168 m = Regex.Match(output.ReadLine(), @"^ \+ autocrop: ([0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)");
\r
170 thisTitle.m_autoCrop = new int[4] { int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value), int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value) };
\r
172 thisTitle.m_chapters.AddRange(Chapter.ParseList(output));
\r
174 thisTitle.m_audioTracks.AddRange(AudioTrack.ParseList(output));
\r
176 thisTitle.m_subtitles.AddRange(Subtitle.ParseList(output));
\r
181 public static Title[] ParseList(string output)
\r
183 List<Title> titles = new List<Title>();
\r
184 StringReader sr = new StringReader(output);
\r
186 while (sr.Peek() == '+' || sr.Peek() == ' ')
\r
188 // If the the character is a space, then chances are the line
\r
189 if (sr.Peek() == ' ') // If the character is a space, then chances are it's the combing detected line.
\r
190 sr.ReadLine(); // Skip over it
\r
192 titles.Add(Title.Parse(sr));
\r
195 return titles.ToArray();
\r