2 using System.Collections.Generic;
\r
4 using System.Drawing;
\r
6 using System.Windows.Forms;
\r
7 using System.Text.RegularExpressions;
\r
9 namespace Handbrake.Parsing
\r
12 /// An object that represents a single Title of a DVD
\r
16 private List<Chapter> m_chapters;
\r
18 /// Collection of chapters in this Title
\r
20 public List<Chapter> Chapters
\r
24 return this.m_chapters;
\r
28 private List<AudioTrack> m_audioTracks;
\r
30 /// Collection of audio tracks associated with this Title
\r
32 public List<AudioTrack> AudioTracks
\r
36 return this.m_audioTracks;
\r
40 private List<Subtitle> m_subtitles;
\r
42 /// Collection of subtitles associated with this Title
\r
44 public List<Subtitle> Subtitles
\r
48 return this.m_subtitles;
\r
52 private int m_titleNumber;
\r
54 /// The track number of this Title
\r
56 public int TitleNumber
\r
60 return this.m_titleNumber;
\r
64 private TimeSpan m_duration;
\r
66 /// The length in time of this Title
\r
68 public TimeSpan Duration
\r
72 return this.m_duration;
\r
76 private Size m_resolution;
\r
78 /// The resolution (width/height) of this Title
\r
80 public Size Resolution
\r
84 return this.m_resolution;
\r
88 private float m_aspectRatio;
\r
90 /// The aspect ratio of this Title
\r
92 public float AspectRatio
\r
96 return this.m_aspectRatio;
\r
100 private int[] m_autoCrop;
\r
102 /// The automatically detected crop region for this Title.
\r
103 /// This is an int array with 4 items in it as so:
\r
109 public int[] AutoCropDimensions
\r
113 return this.m_autoCrop;
\r
118 /// The constructor for this object
\r
122 this.m_audioTracks = new List<AudioTrack>();
\r
123 this.m_chapters = new List<Chapter>();
\r
124 this.m_subtitles = new List<Subtitle>();
\r
128 /// Override of the ToString method to provide an easy way to use this object in the UI
\r
130 /// <returns>A string representing this track in the format: {title #} (00:00:00)</returns>
\r
131 public override string ToString()
\r
133 return string.Format("{0} ({1:00}:{2:00}:{3:00})", this.m_titleNumber, this.m_duration.Hours,
\r
134 this.m_duration.Minutes, this.m_duration.Seconds);
\r
140 * There is some pretty extensive exception handling in here. A number of people have been seeing random problems.
\r
141 * It just helps pinpointing which line of code is causing the issue.
\r
142 * Can be cut down at a later date.
\r
145 public static Title Parse(StringReader output)
\r
147 Title thisTitle = new Title();
\r
150 Match m = Regex.Match(output.ReadLine(), @"^\+ title ([0-9]*):");
\r
153 // Match track number for this title
\r
156 //MessageBox.Show(m.Groups[1].Value);
\r
157 thisTitle.m_titleNumber = int.Parse(m.Groups[1].Value.Trim().ToString());
\r
158 //.Trim().ToString() Not sure why this is needed but some systems seem to get a rogue
\r
161 catch (Exception exc)
\r
163 if (Properties.Settings.Default.GuiDebug == "Checked")
\r
165 MessageBox.Show("Title.cs - Track Number " + exc.ToString());
\r
171 // Get duration for this title
\r
174 m = Regex.Match(output.ReadLine(), @"^ \+ duration: ([0-9]{2}:[0-9]{2}:[0-9]{2})");
\r
177 thisTitle.m_duration = TimeSpan.Parse(m.Groups[1].Value);
\r
180 catch (Exception exc)
\r
182 if (Properties.Settings.Default.GuiDebug == "Checked")
\r
184 MessageBox.Show("Title.cs - Duration " + exc.ToString());
\r
190 // Get resolution, aspect ratio and FPS for this title
\r
191 m = Regex.Match(output.ReadLine(), @"^ \+ size: ([0-9]*)x([0-9]*), aspect: ([0-9]*\.[0-9]*), ([0-9]*\.[0-9]*) fps");
\r
194 thisTitle.m_resolution = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
\r
195 thisTitle.m_aspectRatio = float.Parse(m.Groups[3].Value, Functions.CLI.Culture);
\r
198 catch (Exception exc)
\r
200 if (Properties.Settings.Default.GuiDebug == "Checked")
\r
202 MessageBox.Show("Title.cs - Resolution and Aspect " + exc.ToString());
\r
208 // Get autocrop region for this title
\r
209 m = Regex.Match(output.ReadLine(), @"^ \+ autocrop: ([0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)");
\r
212 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
215 catch (Exception exc)
\r
217 if (Properties.Settings.Default.GuiDebug == "Checked")
\r
219 MessageBox.Show("Title.cs - Auto Crop " + exc.ToString());
\r
226 thisTitle.m_chapters.AddRange(Chapter.ParseList(output));
\r
228 catch (Exception exc)
\r
230 if (Properties.Settings.Default.GuiDebug == "Checked")
\r
232 MessageBox.Show("Title.cs - Chapters EXC " + exc.ToString());
\r
238 thisTitle.m_audioTracks.AddRange(AudioTrack.ParseList(output));
\r
240 catch (Exception exc)
\r
242 if (Properties.Settings.Default.GuiDebug == "Checked")
\r
244 MessageBox.Show("Title.cs - Audio EXC " + exc.ToString());
\r
250 thisTitle.m_subtitles.AddRange(Subtitle.ParseList(output));
\r
252 catch (Exception exc)
\r
254 if (Properties.Settings.Default.GuiDebug == "Checked")
\r
256 MessageBox.Show("Title.cs - Subtitles EXC " + exc.ToString());
\r
260 catch (Exception exc)
\r
262 if (Properties.Settings.Default.GuiDebug == "Checked")
\r
264 MessageBox.Show("Title.cs - Parse " + exc.ToString());
\r
272 public static Title[] ParseList(string output)
\r
274 List<Title> titles = new List<Title>();
\r
277 StringReader sr = new StringReader(output);
\r
278 while ((char)sr.Peek() == '+')
\r
280 titles.Add(Title.Parse(sr));
\r
283 catch (Exception exc)
\r
285 if (Properties.Settings.Default.GuiDebug == "Checked")
\r
287 MessageBox.Show("Title.cs - ParseList " + exc.ToString());
\r
290 return titles.ToArray();
\r