diff options
author | brianmario <[email protected]> | 2007-07-19 03:46:40 +0000 |
---|---|---|
committer | brianmario <[email protected]> | 2007-07-19 03:46:40 +0000 |
commit | 5a85699f791f49ea7643ec2335d919d152410652 (patch) | |
tree | c86fd1ac50e4e70b1bebc02389111457aed3fd84 /win/C#/Parsing/Title.cs | |
parent | 34ec0f7cfb452f851cd2e59278b19ba724c50fa6 (diff) |
WinGui:
misc UI control placement changes
updates to some FormBorderStyle's
converted Parsing code to use regex instead of substrings and string splitting
added a couple of additional code comments
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@715 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/Parsing/Title.cs')
-rw-r--r-- | win/C#/Parsing/Title.cs | 126 |
1 files changed, 71 insertions, 55 deletions
diff --git a/win/C#/Parsing/Title.cs b/win/C#/Parsing/Title.cs index 6f3574f67..933be6d2d 100644 --- a/win/C#/Parsing/Title.cs +++ b/win/C#/Parsing/Title.cs @@ -4,6 +4,7 @@ using System.Text; using System.Drawing;
using System.IO;
using System.Windows.Forms;
+using System.Text.RegularExpressions;
namespace Handbrake.Parsing
{
@@ -96,7 +97,6 @@ namespace Handbrake.Parsing }
}
-
private int[] m_autoCrop;
/// <summary>
/// The automatically detected crop region for this Title.
@@ -130,74 +130,90 @@ namespace Handbrake.Parsing /// <returns>A string representing this track in the format: {title #} (00:00:00)</returns>
public override string ToString()
{
- return string.Format("{0} ({1:00}:{2:00}:{3:00})", this.m_titleNumber, this.m_duration.Hours,
+ return string.Format("{0} ({1:00}:{2:00}:{3:00})", this.m_titleNumber, this.m_duration.Hours,
this.m_duration.Minutes, this.m_duration.Seconds);
}
- public static Title Parse(StreamReader output)
+ public static Title Parse(StringReader output)
{
Title thisTitle = new Title();
+ // Match track number for this title
+ Match m = Regex.Match(output.ReadLine(), @"^\+ title ([0-9]*):");
+ if (m.Success)
+ {
+ thisTitle.m_titleNumber = int.Parse(m.Groups[1].Value);
+ }
+
+ output.ReadLine();
/*
- * This will be converted to use Regex soon, I promise ;)
- * brianmario - 7/9/07
+ // Match vts, ttn, cell range and block count
+ m = Regex.Match(output.ReadLine(), @"^ \+ vts ([0-9]*), ttn ([0-9]*), cells ([0-9]*)->([0-9]*) \(([0-9]*) blocks\)");
+ if (m.Success)
+ {
+ // We don't need any of those values right now, so we'll just ignore them
+ // and read a line from the buffer to get it out of the way.
+ }
+ */
+
+ // Get duration for this title
+ m = Regex.Match(output.ReadLine(), @"^ \+ duration: ([0-9]{2}:[0-9]{2}:[0-9]{2})");
+ if (m.Success)
+ {
+ thisTitle.m_duration = TimeSpan.Parse(m.Groups[1].Value);
+ }
+
+ // Get resolution, aspect ratio and FPS for this title
+ m = Regex.Match(output.ReadLine(), @"^ \+ size: ([0-9]*)x([0-9]*), aspect: ([0-9]*\.[0-9]*), ([0-9]*\.[0-9]*) fps");
+ if (m.Success)
+ {
+ thisTitle.m_resolution = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
+ thisTitle.m_aspectRatio = float.Parse(m.Groups[3].Value);
+ // we don't need FPS right now
+ }
+
+ // Get autocrop region for this title
+ m = Regex.Match(output.ReadLine(), @"^ \+ autocrop: ([0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)");
+ if (m.Success)
+ {
+ 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) };
+ }
+
+ /*
+ *
+ * A Few Bugs that need fixed.
+ *
+ *
+ * Problem 1
+ * There is a small problem here... What happens if the DVD has no Subtitles? or Handbrake misses the Audio or Chapter track
+ * data due to an error.
+ *
+ * hbcli will sit in a suspended state until it is forcefully closed.
+ *
+ * Problem 2
+ * See AudioTrack.cs Line 80 for details
+ *
+ * Problem 3
+ * Doesn't seem to support DVD's where the first track is 0 instead of 1, and only includes 1 title (TS/MPG files)
+ * Simply Doesn't list any titles.
+ *
+ *
*/
-
- string curLine = output.ReadLine();
- thisTitle.m_titleNumber = int.Parse(curLine.Substring(curLine.Length - 2, 1));
- curLine = output.ReadLine();
- string[] splitter = curLine.Split(',');
-
- splitter = splitter[2].Trim().Split(' ', '(', ')');
-
- splitter = splitter[1].Split('-', '>');
-
- curLine = output.ReadLine();
- splitter = curLine.Split(new string[] { " + duration: " }, StringSplitOptions.RemoveEmptyEntries);
- thisTitle.m_duration = TimeSpan.Parse(splitter[0]);
- curLine = output.ReadLine();
- splitter = curLine.Split(new string[] { " + size: ", "aspect: ", ", ", " fps", "x" }, StringSplitOptions.RemoveEmptyEntries);
- thisTitle.m_resolution = new Size(int.Parse(splitter[0]), int.Parse(splitter[1]));
- thisTitle.m_aspectRatio = float.Parse(splitter[2].ToString());
-
- curLine = output.ReadLine();
- splitter = curLine.Split(new string[] { " + autocrop: ", "/" }, StringSplitOptions.RemoveEmptyEntries);
- thisTitle.m_autoCrop = new int[4] { int.Parse(splitter[0]), int.Parse(splitter[1]), int.Parse(splitter[2]), int.Parse(splitter[3]) };
-
- /*
- *
- * A Few Bugs that need fixed.
- *
- *
- * Problem 1
- * There is a small problem here... What happens if the DVD has no Subtitles? or Handbrake misses the Audio or Chapter track
- * data due to an error.
- *
- * hbcli will sit in a suspended state until it is forcefully closed.
- *
- * Problem 2
- * See AudioTrack.cs Line 80 for details
- *
- * Problem 3
- * Doesn't seem to support DVD's where the first track is 0 instead of 1, and only includes 1 title (TS/MPG files)
- * Simply Doesn't list any titles.
- *
- *
- */
-
- thisTitle.m_chapters.AddRange(Chapter.ParseList(output));
- thisTitle.m_audioTracks.AddRange(AudioTrack.ParseList(output));
- thisTitle.m_subtitles.AddRange(Subtitle.ParseList(output));
-
+
+ thisTitle.m_chapters.AddRange(Chapter.ParseList(output));
+ thisTitle.m_audioTracks.AddRange(AudioTrack.ParseList(output));
+ thisTitle.m_subtitles.AddRange(Subtitle.ParseList(output));
+
return thisTitle;
}
- public static Title[] ParseList(StreamReader output)
+ public static Title[] ParseList(string output)
{
List<Title> titles = new List<Title>();
- while ((char)output.Peek() == '+')
+ StringReader sr = new StringReader(output);
+ while ((char)sr.Peek() == '+')
{
- titles.Add(Title.Parse(output));
+ titles.Add(Title.Parse(sr));
}
return titles.ToArray();
}
|