2 using System.Collections.Generic;
\r
4 using System.Drawing;
\r
6 using System.Windows.Forms;
\r
8 namespace Handbrake.Parsing
\r
11 /// An object that represents a single Title of a DVD
\r
15 private List<Chapter> m_chapters;
\r
17 /// Collection of chapters in this Title
\r
19 public List<Chapter> Chapters
\r
23 return this.m_chapters;
\r
27 private List<AudioTrack> m_audioTracks;
\r
29 /// Collection of audio tracks associated with this Title
\r
31 public List<AudioTrack> AudioTracks
\r
35 return this.m_audioTracks;
\r
39 private List<Subtitle> m_subtitles;
\r
41 /// Collection of subtitles associated with this Title
\r
43 public List<Subtitle> Subtitles
\r
47 return this.m_subtitles;
\r
51 private int m_titleNumber;
\r
53 /// The track number of this Title
\r
55 public int TitleNumber
\r
59 return this.m_titleNumber;
\r
63 private TimeSpan m_duration;
\r
65 /// The length in time of this Title
\r
67 public TimeSpan Duration
\r
71 return this.m_duration;
\r
75 private Size m_resolution;
\r
77 /// The resolution (width/height) of this Title
\r
79 public Size Resolution
\r
83 return this.m_resolution;
\r
87 private float m_aspectRatio;
\r
89 /// The aspect ratio of this Title
\r
91 public float AspectRatio
\r
95 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
137 public static Title Parse(StreamReader output)
\r
139 Title thisTitle = new Title();
\r
142 * This will be converted to use Regex soon, I promise ;)
\r
143 * brianmario - 7/9/07
\r
146 string curLine = output.ReadLine();
\r
147 thisTitle.m_titleNumber = int.Parse(curLine.Substring(curLine.Length - 2, 1));
\r
148 curLine = output.ReadLine();
\r
149 string[] splitter = curLine.Split(',');
\r
151 splitter = splitter[2].Trim().Split(' ', '(', ')');
\r
153 splitter = splitter[1].Split('-', '>');
\r
155 curLine = output.ReadLine();
\r
156 splitter = curLine.Split(new string[] { " + duration: " }, StringSplitOptions.RemoveEmptyEntries);
\r
157 thisTitle.m_duration = TimeSpan.Parse(splitter[0]);
\r
158 curLine = output.ReadLine();
\r
159 splitter = curLine.Split(new string[] { " + size: ", "aspect: ", ", ", " fps", "x" }, StringSplitOptions.RemoveEmptyEntries);
\r
160 thisTitle.m_resolution = new Size(int.Parse(splitter[0]), int.Parse(splitter[1]));
\r
161 thisTitle.m_aspectRatio = float.Parse(splitter[2].ToString());
\r
163 curLine = output.ReadLine();
\r
164 splitter = curLine.Split(new string[] { " + autocrop: ", "/" }, StringSplitOptions.RemoveEmptyEntries);
\r
165 thisTitle.m_autoCrop = new int[4] { int.Parse(splitter[0]), int.Parse(splitter[1]), int.Parse(splitter[2]), int.Parse(splitter[3]) };
\r
169 * A Few Bugs that need fixed.
\r
173 * There is a small problem here... What happens if the DVD has no Subtitles? or Handbrake misses the Audio or Chapter track
\r
174 * data due to an error.
\r
176 * hbcli will sit in a suspended state until it is forcefully closed.
\r
179 * See AudioTrack.cs Line 80 for details
\r
182 * Doesn't seem to support DVD's where the first track is 0 instead of 1, and only includes 1 title (TS/MPG files)
\r
183 * Simply Doesn't list any titles.
\r
188 thisTitle.m_chapters.AddRange(Chapter.ParseList(output));
\r
189 thisTitle.m_audioTracks.AddRange(AudioTrack.ParseList(output));
\r
190 thisTitle.m_subtitles.AddRange(Subtitle.ParseList(output));
\r
195 public static Title[] ParseList(StreamReader output)
\r
197 List<Title> titles = new List<Title>();
\r
198 while ((char)output.Peek() == '+')
\r
200 titles.Add(Title.Parse(output));
\r
202 return titles.ToArray();
\r