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
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 ((char)sr.Peek() == '+')
\r
188 titles.Add(Title.Parse(sr));
\r
190 * Fix for the line "+ combing detected, may be interlaced or telecined"
\r
191 * If the next character is not a [ or +, then there are titles left to parse, but we are not where
\r
192 * we expect to be in the output, so read one line ahead to skip over the unknown line
\r
194 * HACK: FIX THIS PROPERLY
\r
195 * The try cactch is used to fix a bug introduced with 1819. The level of verbosity needs to be 2
\r
196 * in order for the code to run correctly without the hack below. It gets upset about 2 lines of
\r
197 * log missing with -v 1. To fix this just break out the loop so that sr.Peek() isn't run.
\r
201 if ((char)sr.Peek() != '[' && (char)sr.Peek() != '+') // Hack, Fix later
\r
211 return titles.ToArray();
\r