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
147 Match m = Regex.Match(output.ReadLine(), @"^\+ title ([0-9]*):");
\r
148 // Match track number for this title
\r
150 thisTitle.m_titleNumber = int.Parse(m.Groups[1].Value.Trim().ToString());
\r
154 // Get duration for this title
\r
156 m = Regex.Match(output.ReadLine(), @"^ \+ duration: ([0-9]{2}:[0-9]{2}:[0-9]{2})");
\r
158 thisTitle.m_duration = TimeSpan.Parse(m.Groups[1].Value);
\r
160 // Get resolution, aspect ratio and FPS for this title
\r
161 m = Regex.Match(output.ReadLine(), @"^ \+ size: ([0-9]*)x([0-9]*), aspect: ([0-9]*\.[0-9]*), ([0-9]*\.[0-9]*) fps");
\r
164 thisTitle.m_resolution = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
\r
165 thisTitle.m_aspectRatio = float.Parse(m.Groups[3].Value, Functions.CLI.Culture);
\r
168 // Get autocrop region for this title
\r
169 m = Regex.Match(output.ReadLine(), @"^ \+ autocrop: ([0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)");
\r
171 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
173 thisTitle.m_chapters.AddRange(Chapter.ParseList(output));
\r
175 thisTitle.m_audioTracks.AddRange(AudioTrack.ParseList(output));
\r
177 thisTitle.m_subtitles.AddRange(Subtitle.ParseList(output));
\r
179 catch (Exception exc)
\r
181 MessageBox.Show("Title.cs - Parse " + exc.ToString());
\r
187 public static Title[] ParseList(string output)
\r
189 List<Title> titles = new List<Title>();
\r
192 StringReader sr = new StringReader(output);
\r
193 while ((char)sr.Peek() == '+')
\r
195 titles.Add(Title.Parse(sr));
\r
198 catch (Exception exc)
\r
200 MessageBox.Show("Title.cs - ParseList " + exc.ToString());
\r
202 return titles.ToArray();
\r