diff options
Diffstat (limited to 'win/C#/Parsing')
-rw-r--r-- | win/C#/Parsing/AudioTrack.cs | 30 | ||||
-rw-r--r-- | win/C#/Parsing/Chapter.cs | 25 | ||||
-rw-r--r-- | win/C#/Parsing/DVD.cs | 13 | ||||
-rw-r--r-- | win/C#/Parsing/Parser.cs | 9 | ||||
-rw-r--r-- | win/C#/Parsing/Subtitle.cs | 15 | ||||
-rw-r--r-- | win/C#/Parsing/Title.cs | 126 |
6 files changed, 122 insertions, 96 deletions
diff --git a/win/C#/Parsing/AudioTrack.cs b/win/C#/Parsing/AudioTrack.cs index d23d34748..98114a5ca 100644 --- a/win/C#/Parsing/AudioTrack.cs +++ b/win/C#/Parsing/AudioTrack.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic;
using System.Text;
using System.IO;
+using System.Text.RegularExpressions;
namespace Handbrake.Parsing
{
@@ -91,25 +92,18 @@ namespace Handbrake.Parsing return string.Format("{0} {1} ({2}) ({3})", this.m_trackNumber, this.m_language, this.m_format, this.m_subFormat);
}
- public static AudioTrack Parse(StreamReader output)
+ public static AudioTrack Parse(StringReader output)
{
- string curLine = output.ReadLine();
- if (!curLine.Contains(" + subtitle tracks:"))
+ Match m = Regex.Match(output.ReadLine(), @"^ \+ ([0-9]*), ([A-Za-z0-9]*) \((.*)\) \((.*)\), ([0-9]*)Hz, ([0-9]*)bps");
+ if (m.Success)
{
AudioTrack thisTrack = new AudioTrack();
- string[] splitter = curLine.Split(new string[] { " + ", ", ", " (", ") (", " ch", "), ", "Hz, ", "bps" }, StringSplitOptions.RemoveEmptyEntries);
- thisTrack.m_trackNumber = int.Parse(splitter[0]);
- thisTrack.m_language = splitter[1];
- thisTrack.m_format = splitter[2];
- /*
- * Problem 2
- * Field 'Handbrake.frmMain.hbProc' is never assigned to, and will always have it's default value null.
- * This happens with "AllAudios.iso" which is a test file. http://www.sr88.co.uk/AllAudios.iso (~95MB)
- */
-
- thisTrack.m_subFormat = splitter[3];
- thisTrack.m_frequency = int.Parse(splitter[4]);
- thisTrack.m_bitrate = int.Parse(splitter[5]);
+ thisTrack.m_trackNumber = int.Parse(m.Groups[1].Value);
+ thisTrack.m_language = m.Groups[2].Value;
+ thisTrack.m_format = m.Groups[3].Value;
+ thisTrack.m_subFormat = m.Groups[4].Value;
+ thisTrack.m_frequency = int.Parse(m.Groups[5].Value);
+ thisTrack.m_bitrate = int.Parse(m.Groups[6].Value);
return thisTrack;
}
else
@@ -118,10 +112,10 @@ namespace Handbrake.Parsing }
}
- public static AudioTrack[] ParseList(StreamReader output)
+ public static AudioTrack[] ParseList(StringReader output)
{
List<AudioTrack> tracks = new List<AudioTrack>();
- while (true) // oh glorious hack, serve me well
+ while (true)
{
AudioTrack thisTrack = AudioTrack.Parse(output);
if (thisTrack != null)
diff --git a/win/C#/Parsing/Chapter.cs b/win/C#/Parsing/Chapter.cs index c824fcd68..665841e97 100644 --- a/win/C#/Parsing/Chapter.cs +++ b/win/C#/Parsing/Chapter.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic;
using System.Text;
using System.IO;
+using System.Text.RegularExpressions;
namespace Handbrake.Parsing
{
@@ -43,15 +44,14 @@ namespace Handbrake.Parsing return this.m_chapterNumber.ToString();
}
- public static Chapter Parse(StreamReader output)
+ public static Chapter Parse(StringReader output)
{
- string curLine = output.ReadLine();
- if (!curLine.Contains(" + audio tracks:"))
+ Match m = Regex.Match(output.ReadLine(), @"^ \+ ([0-9]*): cells ([0-9]*)->([0-9]*), ([0-9]*) blocks, duration ([0-9]{2}:[0-9]{2}:[0-9]{2})");
+ if (m.Success)
{
Chapter thisChapter = new Chapter();
- string[] splitter = curLine.Split(new string[] { " + ", ": cells ", ", ", " blocks, duration ", "->" }, StringSplitOptions.RemoveEmptyEntries);
- thisChapter.m_chapterNumber = int.Parse(splitter[0]);
- thisChapter.m_duration = TimeSpan.Parse(splitter[4]);
+ thisChapter.m_chapterNumber = int.Parse(m.Groups[1].Value);
+ thisChapter.m_duration = TimeSpan.Parse(m.Groups[5].Value);
return thisChapter;
}
else
@@ -60,14 +60,19 @@ namespace Handbrake.Parsing }
}
- public static Chapter[] ParseList(StreamReader output)
+ public static Chapter[] ParseList(StringReader output)
{
List<Chapter> chapters = new List<Chapter>();
- string curLine = output.ReadLine();
- while (!curLine.Contains(" + audio tracks:"))
+
+ // this is to read the " + chapters:" line from the buffer
+ // so we can start reading the chapters themselvs
+ output.ReadLine();
+
+ while (true)
{
+ // Start of the chapter list for this Title
Chapter thisChapter = Chapter.Parse(output);
-
+
if (thisChapter != null)
{
chapters.Add(thisChapter);
diff --git a/win/C#/Parsing/DVD.cs b/win/C#/Parsing/DVD.cs index 1c2e0d0e7..025961240 100644 --- a/win/C#/Parsing/DVD.cs +++ b/win/C#/Parsing/DVD.cs @@ -2,8 +2,7 @@ using System; using System.Collections.Generic;
using System.Text;
using System.IO;
-using System.Windows.Forms;
-
+using System.Text.RegularExpressions;
namespace Handbrake.Parsing
{
@@ -37,11 +36,13 @@ namespace Handbrake.Parsing DVD thisDVD = new DVD();
while (!output.EndOfStream)
{
- string curLine = output.ReadLine();
-
- if (curLine.Contains("Scanning title"))
+ if ((char)output.Peek() == '+')
+ {
+ thisDVD.m_titles.AddRange(Title.ParseList(output.ReadToEnd()));
+ }
+ else
{
- thisDVD.m_titles.AddRange(Title.ParseList(output));
+ output.ReadLine();
}
}
return thisDVD;
diff --git a/win/C#/Parsing/Parser.cs b/win/C#/Parsing/Parser.cs index ef6476f78..afd5471d0 100644 --- a/win/C#/Parsing/Parser.cs +++ b/win/C#/Parsing/Parser.cs @@ -13,6 +13,12 @@ namespace Handbrake.Parsing /// <param name="Data">The data parsed from the stream</param>
public delegate void DataReadEventHandler(object Sender, string Data);
+ /// <summary>
+ /// A delegate to handle events regarding progress during DVD scanning
+ /// </summary>
+ /// <param name="Sender">The object who's raising the event</param>
+ /// <param name="CurrentTitle">The title number currently being processed</param>
+ /// <param name="TitleCount">The total number of titiles to be processed</param>
public delegate void ScanProgressEventHandler(object Sender, int CurrentTitle, int TitleCount);
/// <summary>
@@ -42,6 +48,9 @@ namespace Handbrake.Parsing /// </summary>
public static event DataReadEventHandler OnReadToEnd;
+ /// <summary>
+ /// Raised upon the catching of a "Scanning title # of #..." in the stream
+ /// </summary>
public static event ScanProgressEventHandler OnScanProgress;
/// <summary>
diff --git a/win/C#/Parsing/Subtitle.cs b/win/C#/Parsing/Subtitle.cs index 66cc07843..a30fd7882 100644 --- a/win/C#/Parsing/Subtitle.cs +++ b/win/C#/Parsing/Subtitle.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic;
using System.Text;
using System.IO;
+using System.Text.RegularExpressions;
namespace Handbrake.Parsing
{
@@ -43,15 +44,15 @@ namespace Handbrake.Parsing return string.Format("{0} {1}", this.m_trackNumber, this.m_language);
}
- public static Subtitle Parse(StreamReader output)
+ public static Subtitle Parse(StringReader output)
{
string curLine = output.ReadLine();
- if (!curLine.Contains("HandBrake has exited."))
+ Match m = Regex.Match(curLine, @"^ \+ ([0-9]*), ([A-Za-z]*) \((.*)\)");
+ if (m.Success && !curLine.Contains("HandBrake has exited."))
{
Subtitle thisSubtitle = new Subtitle();
- string[] splitter = curLine.Split(new string[] { " + ", ", " }, StringSplitOptions.RemoveEmptyEntries);
- thisSubtitle.m_trackNumber = int.Parse(splitter[0]);
- thisSubtitle.m_language = splitter[1];
+ thisSubtitle.m_trackNumber = int.Parse(m.Groups[1].Value);
+ thisSubtitle.m_language = m.Groups[2].Value;
return thisSubtitle;
}
else
@@ -60,10 +61,10 @@ namespace Handbrake.Parsing }
}
- public static Subtitle[] ParseList(StreamReader output)
+ public static Subtitle[] ParseList(StringReader output)
{
List<Subtitle> subtitles = new List<Subtitle>();
- while ((char)output.Peek() != '+') // oh glorious hack, serve me well
+ while ((char)output.Peek() != '+')
{
Subtitle thisSubtitle = Subtitle.Parse(output);
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();
}
|