summaryrefslogtreecommitdiffstats
path: root/win/C#/Parsing
diff options
context:
space:
mode:
authorsr55 <[email protected]>2009-01-08 20:11:26 +0000
committersr55 <[email protected]>2009-01-08 20:11:26 +0000
commit979826e24b3f187c3b488da47b720234c93f293d (patch)
tree1341bb819559c40cd68ff39237fc354aa6f27dea /win/C#/Parsing
parenta385d189c2830994e460b8739546825d7f4418d2 (diff)
WinGui:
- Code cleanup. Remoes old using tags, removes unused code, cleans up some functions to make them shorter/more readable etc. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2069 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/Parsing')
-rw-r--r--win/C#/Parsing/AudioTrack.cs70
-rw-r--r--win/C#/Parsing/Chapter.cs29
-rw-r--r--win/C#/Parsing/DVD.cs26
-rw-r--r--win/C#/Parsing/Parser.cs3
-rw-r--r--win/C#/Parsing/Subtitle.cs28
-rw-r--r--win/C#/Parsing/Title.cs108
6 files changed, 105 insertions, 159 deletions
diff --git a/win/C#/Parsing/AudioTrack.cs b/win/C#/Parsing/AudioTrack.cs
index 493fb4dff..d2d6f3fac 100644
--- a/win/C#/Parsing/AudioTrack.cs
+++ b/win/C#/Parsing/AudioTrack.cs
@@ -16,76 +16,59 @@ namespace Handbrake.Parsing
/// </summary>
public class AudioTrack
{
+ private int m_bitrate;
+ private string m_format;
+ private int m_frequency;
+ private string m_language;
+ private string m_subFormat;
private int m_trackNumber;
+
/// <summary>
/// The track number of this Audio Track
/// </summary>
public int TrackNumber
{
- get
- {
- return this.m_trackNumber;
- }
+ get { return m_trackNumber; }
}
- private string m_language;
/// <summary>
/// The language (if detected) of this Audio Track
/// </summary>
public string Language
{
- get
- {
- return this.m_language;
- }
+ get { return m_language; }
}
- private string m_format;
/// <summary>
/// The primary format of this Audio Track
/// </summary>
public string Format
{
- get
- {
- return this.m_format;
- }
+ get { return m_format; }
}
- private string m_subFormat;
/// <summary>
/// Additional format info for this Audio Track
/// </summary>
public string SubFormat
{
- get
- {
- return this.m_subFormat;
- }
+ get { return m_subFormat; }
}
- private int m_frequency;
/// <summary>
/// The frequency (in MHz) of this Audio Track
/// </summary>
public int Frequency
{
- get
- {
- return this.m_frequency;
- }
+ get { return m_frequency; }
}
- private int m_bitrate;
/// <summary>
/// The bitrate (in kbps) of this Audio Track
/// </summary>
public int Bitrate
{
- get
- {
- return this.m_bitrate;
- }
+ get { return m_bitrate; }
}
/// <summary>
@@ -94,32 +77,33 @@ namespace Handbrake.Parsing
/// <returns>A string formatted as: {track #} {language} ({format}) ({sub-format})</returns>
public override string ToString()
{
- if (this.m_subFormat == null)
- return string.Format("{0} {1} ({2})", this.m_trackNumber, this.m_language, this.m_format);
+ if (m_subFormat == null)
+ return string.Format("{0} {1} ({2})", m_trackNumber, m_language, m_format);
else
- return string.Format("{0} {1} ({2}) ({3})", this.m_trackNumber, this.m_language, this.m_format, this.m_subFormat);
+ return string.Format("{0} {1} ({2}) ({3})", m_trackNumber, m_language, m_format, m_subFormat);
}
public static AudioTrack Parse(StringReader output)
{
- String audio_track= output.ReadLine();
- Match m = Regex.Match(audio_track, @"^ \+ ([0-9]*), ([A-Za-z0-9]*) \((.*)\) \((.*)\), ([0-9]*)Hz, ([0-9]*)bps");
+ String audio_track = output.ReadLine();
+ Match m = Regex.Match(audio_track,
+ @"^ \+ ([0-9]*), ([A-Za-z0-9]*) \((.*)\) \((.*)\), ([0-9]*)Hz, ([0-9]*)bps");
Match y = Regex.Match(audio_track, @"^ \+ ([0-9]*), ([A-Za-z0-9]*) \((.*)\)");
if (m.Success)
{
- AudioTrack thisTrack = new AudioTrack();
- thisTrack.m_trackNumber = int.Parse(m.Groups[1].Value.Trim().ToString());
+ var thisTrack = new AudioTrack();
+ thisTrack.m_trackNumber = int.Parse(m.Groups[1].Value.Trim());
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.Trim().ToString());
- thisTrack.m_bitrate = int.Parse(m.Groups[6].Value.Trim().ToString());
+ thisTrack.m_frequency = int.Parse(m.Groups[5].Value.Trim());
+ thisTrack.m_bitrate = int.Parse(m.Groups[6].Value.Trim());
return thisTrack;
}
else if (y.Success)
{
- AudioTrack thisTrack = new AudioTrack();
- thisTrack.m_trackNumber = int.Parse(y.Groups[1].Value.Trim().ToString());
+ var thisTrack = new AudioTrack();
+ thisTrack.m_trackNumber = int.Parse(y.Groups[1].Value.Trim());
thisTrack.m_language = y.Groups[2].Value;
thisTrack.m_format = y.Groups[3].Value;
return thisTrack;
@@ -130,10 +114,10 @@ namespace Handbrake.Parsing
public static AudioTrack[] ParseList(StringReader output)
{
- List<AudioTrack> tracks = new List<AudioTrack>();
+ var tracks = new List<AudioTrack>();
while (true)
{
- AudioTrack thisTrack = AudioTrack.Parse(output);
+ AudioTrack thisTrack = Parse(output);
if (thisTrack != null)
tracks.Add(thisTrack);
else
@@ -142,4 +126,4 @@ namespace Handbrake.Parsing
return tracks.ToArray();
}
}
-}
+} \ No newline at end of file
diff --git a/win/C#/Parsing/Chapter.cs b/win/C#/Parsing/Chapter.cs
index 526967510..301fa5719 100644
--- a/win/C#/Parsing/Chapter.cs
+++ b/win/C#/Parsing/Chapter.cs
@@ -17,27 +17,23 @@ namespace Handbrake.Parsing
public class Chapter
{
private int m_chapterNumber;
+
+ private TimeSpan m_duration;
+
/// <summary>
/// The number of this Chapter, in regards to it's parent Title
/// </summary>
public int ChapterNumber
{
- get
- {
- return this.m_chapterNumber;
- }
+ get { return m_chapterNumber; }
}
- private TimeSpan m_duration;
/// <summary>
/// The length in time this Chapter spans
/// </summary>
public TimeSpan Duration
{
- get
- {
- return this.m_duration;
- }
+ get { return m_duration; }
}
/// <summary>
@@ -46,16 +42,17 @@ namespace Handbrake.Parsing
/// <returns>A string formatted as: {chapter #}</returns>
public override string ToString()
{
- return this.m_chapterNumber.ToString();
+ return m_chapterNumber.ToString();
}
public static Chapter Parse(StringReader output)
{
- 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})");
+ 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();
- thisChapter.m_chapterNumber = int.Parse(m.Groups[1].Value.Trim().ToString());
+ var thisChapter = new Chapter();
+ thisChapter.m_chapterNumber = int.Parse(m.Groups[1].Value.Trim());
thisChapter.m_duration = TimeSpan.Parse(m.Groups[5].Value);
return thisChapter;
}
@@ -65,7 +62,7 @@ namespace Handbrake.Parsing
public static Chapter[] ParseList(StringReader output)
{
- List<Chapter> chapters = new List<Chapter>();
+ var chapters = new List<Chapter>();
// this is to read the " + chapters:" line from the buffer
// so we can start reading the chapters themselvs
@@ -74,7 +71,7 @@ namespace Handbrake.Parsing
while (true)
{
// Start of the chapter list for this Title
- Chapter thisChapter = Chapter.Parse(output);
+ Chapter thisChapter = Parse(output);
if (thisChapter != null)
chapters.Add(thisChapter);
@@ -84,4 +81,4 @@ namespace Handbrake.Parsing
return chapters.ToArray();
}
}
-}
+} \ No newline at end of file
diff --git a/win/C#/Parsing/DVD.cs b/win/C#/Parsing/DVD.cs
index d0802e4c9..31fe2de12 100644
--- a/win/C#/Parsing/DVD.cs
+++ b/win/C#/Parsing/DVD.cs
@@ -4,47 +4,41 @@
Homepage: <http://handbrake.fr>.
It may be used under the terms of the GNU General Public License. */
-using System;
using System.Collections.Generic;
-using System.Windows.Forms;
using System.IO;
namespace Handbrake.Parsing
{
-
/// <summary>
/// An object representing a scanned DVD
/// </summary>
public class DVD
{
+ private readonly List<Title> m_titles;
- private List<Title> m_titles;
/// <summary>
- /// Collection of Titles associated with this DVD
+ /// Default constructor for this object
/// </summary>
- public List<Title> Titles
+ public DVD()
{
- get
- {
- return this.m_titles;
- }
+ m_titles = new List<Title>();
}
/// <summary>
- /// Default constructor for this object
+ /// Collection of Titles associated with this DVD
/// </summary>
- public DVD()
+ public List<Title> Titles
{
- this.m_titles = new List<Title>();
+ get { return m_titles; }
}
public static DVD Parse(StreamReader output)
{
- DVD thisDVD = new DVD();
+ var thisDVD = new DVD();
while (!output.EndOfStream)
{
- if ((char)output.Peek() == '+')
+ if ((char) output.Peek() == '+')
thisDVD.m_titles.AddRange(Title.ParseList(output.ReadToEnd()));
else
output.ReadLine();
@@ -53,4 +47,4 @@ namespace Handbrake.Parsing
return thisDVD;
}
}
-}
+} \ No newline at end of file
diff --git a/win/C#/Parsing/Parser.cs b/win/C#/Parsing/Parser.cs
index bbafc9295..24dcef40f 100644
--- a/win/C#/Parsing/Parser.cs
+++ b/win/C#/Parsing/Parser.cs
@@ -4,11 +4,8 @@
Homepage: <http://handbrake.fr>.
It may be used under the terms of the GNU General Public License. */
-using System;
-using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
-using System.Windows.Forms;
namespace Handbrake.Parsing
{
diff --git a/win/C#/Parsing/Subtitle.cs b/win/C#/Parsing/Subtitle.cs
index c5a722b6f..71e00121e 100644
--- a/win/C#/Parsing/Subtitle.cs
+++ b/win/C#/Parsing/Subtitle.cs
@@ -4,7 +4,6 @@
Homepage: <http://handbrake.fr>.
It may be used under the terms of the GNU General Public License. */
-using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
@@ -16,28 +15,23 @@ namespace Handbrake.Parsing
/// </summary>
public class Subtitle
{
+ private string m_language;
private int m_trackNumber;
+
/// <summary>
/// The track number of this Subtitle
/// </summary>
public int TrackNumber
{
- get
- {
- return this.m_trackNumber;
- }
+ get { return m_trackNumber; }
}
- private string m_language;
/// <summary>
/// The language (if detected) of this Subtitle
/// </summary>
public string Language
{
- get
- {
- return this.m_language;
- }
+ get { return m_language; }
}
/// <summary>
@@ -46,7 +40,7 @@ namespace Handbrake.Parsing
/// <returns>A string formatted as: {track #} {language}</returns>
public override string ToString()
{
- return string.Format("{0} {1}", this.m_trackNumber, this.m_language);
+ return string.Format("{0} {1}", m_trackNumber, m_language);
}
public static Subtitle Parse(StringReader output)
@@ -56,8 +50,8 @@ namespace Handbrake.Parsing
Match m = Regex.Match(curLine, @"^ \+ ([0-9]*), ([A-Za-z, ]*) \((.*)\)");
if (m.Success && !curLine.Contains("HandBrake has exited."))
{
- Subtitle thisSubtitle = new Subtitle();
- thisSubtitle.m_trackNumber = int.Parse(m.Groups[1].Value.Trim().ToString());
+ var thisSubtitle = new Subtitle();
+ thisSubtitle.m_trackNumber = int.Parse(m.Groups[1].Value.Trim());
thisSubtitle.m_language = m.Groups[2].Value;
return thisSubtitle;
}
@@ -67,10 +61,10 @@ namespace Handbrake.Parsing
public static Subtitle[] ParseList(StringReader output)
{
- List<Subtitle> subtitles = new List<Subtitle>();
- while ((char)output.Peek() != '+')
+ var subtitles = new List<Subtitle>();
+ while ((char) output.Peek() != '+')
{
- Subtitle thisSubtitle = Subtitle.Parse(output);
+ Subtitle thisSubtitle = Parse(output);
if (thisSubtitle != null)
subtitles.Add(thisSubtitle);
@@ -80,4 +74,4 @@ namespace Handbrake.Parsing
return subtitles.ToArray();
}
}
-}
+} \ No newline at end of file
diff --git a/win/C#/Parsing/Title.cs b/win/C#/Parsing/Title.cs
index 6f0f6ffc3..74ccab752 100644
--- a/win/C#/Parsing/Title.cs
+++ b/win/C#/Parsing/Title.cs
@@ -7,10 +7,9 @@
using System;
using System.Collections.Generic;
using System.Drawing;
+using System.Globalization;
using System.IO;
-using System.Windows.Forms;
using System.Text.RegularExpressions;
-using System.Globalization;
namespace Handbrake.Parsing
{
@@ -19,91 +18,82 @@ namespace Handbrake.Parsing
/// </summary>
public class Title
{
- private List<Chapter> m_chapters;
+ private static readonly CultureInfo Culture = new CultureInfo("en-US", false);
+ private readonly List<AudioTrack> m_audioTracks;
+ private readonly List<Chapter> m_chapters;
+ private readonly List<Subtitle> m_subtitles;
+ private float m_aspectRatio;
+ private int[] m_autoCrop;
+ private TimeSpan m_duration;
+ private Size m_resolution;
+ private int m_titleNumber;
+
+ /// <summary>
+ /// The constructor for this object
+ /// </summary>
+ public Title()
+ {
+ m_audioTracks = new List<AudioTrack>();
+ m_chapters = new List<Chapter>();
+ m_subtitles = new List<Subtitle>();
+ }
+
/// <summary>
/// Collection of chapters in this Title
/// </summary>
public List<Chapter> Chapters
{
- get
- {
- return this.m_chapters;
- }
+ get { return m_chapters; }
}
- private List<AudioTrack> m_audioTracks;
/// <summary>
/// Collection of audio tracks associated with this Title
/// </summary>
public List<AudioTrack> AudioTracks
{
- get
- {
- return this.m_audioTracks;
- }
+ get { return m_audioTracks; }
}
- private List<Subtitle> m_subtitles;
/// <summary>
/// Collection of subtitles associated with this Title
/// </summary>
public List<Subtitle> Subtitles
{
- get
- {
- return this.m_subtitles;
- }
+ get { return m_subtitles; }
}
- private int m_titleNumber;
/// <summary>
/// The track number of this Title
/// </summary>
public int TitleNumber
{
- get
- {
- return this.m_titleNumber;
- }
+ get { return m_titleNumber; }
}
- private TimeSpan m_duration;
/// <summary>
/// The length in time of this Title
/// </summary>
public TimeSpan Duration
{
- get
- {
- return this.m_duration;
- }
+ get { return m_duration; }
}
- private Size m_resolution;
/// <summary>
/// The resolution (width/height) of this Title
/// </summary>
public Size Resolution
{
- get
- {
- return this.m_resolution;
- }
+ get { return m_resolution; }
}
- private float m_aspectRatio;
/// <summary>
/// The aspect ratio of this Title
/// </summary>
public float AspectRatio
{
- get
- {
- return this.m_aspectRatio;
- }
+ get { return m_aspectRatio; }
}
- private int[] m_autoCrop;
/// <summary>
/// The automatically detected crop region for this Title.
/// This is an int array with 4 items in it as so:
@@ -114,20 +104,7 @@ namespace Handbrake.Parsing
/// </summary>
public int[] AutoCropDimensions
{
- get
- {
- return this.m_autoCrop;
- }
- }
-
- /// <summary>
- /// The constructor for this object
- /// </summary>
- public Title()
- {
- this.m_audioTracks = new List<AudioTrack>();
- this.m_chapters = new List<Chapter>();
- this.m_subtitles = new List<Subtitle>();
+ get { return m_autoCrop; }
}
/// <summary>
@@ -136,20 +113,18 @@ 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,
- this.m_duration.Minutes, this.m_duration.Seconds);
+ return string.Format("{0} ({1:00}:{2:00}:{3:00})", m_titleNumber, m_duration.Hours,
+ m_duration.Minutes, m_duration.Seconds);
}
- static readonly private CultureInfo Culture = new CultureInfo("en-US", false);
-
public static Title Parse(StringReader output)
{
- Title thisTitle = new Title();
+ var thisTitle = new Title();
Match m = Regex.Match(output.ReadLine(), @"^\+ title ([0-9]*):");
// Match track number for this title
if (m.Success)
- thisTitle.m_titleNumber = int.Parse(m.Groups[1].Value.Trim().ToString());
+ thisTitle.m_titleNumber = int.Parse(m.Groups[1].Value.Trim());
String testData = output.ReadLine();
@@ -160,7 +135,8 @@ namespace Handbrake.Parsing
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");
+ 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));
@@ -170,7 +146,11 @@ namespace Handbrake.Parsing
// 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) };
+ 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)
+ };
thisTitle.m_chapters.AddRange(Chapter.ParseList(output));
@@ -183,8 +163,8 @@ namespace Handbrake.Parsing
public static Title[] ParseList(string output)
{
- List<Title> titles = new List<Title>();
- StringReader sr = new StringReader(output);
+ var titles = new List<Title>();
+ var sr = new StringReader(output);
while (sr.Peek() == '+' || sr.Peek() == ' ')
{
@@ -192,10 +172,10 @@ namespace Handbrake.Parsing
if (sr.Peek() == ' ') // If the character is a space, then chances are it's the combing detected line.
sr.ReadLine(); // Skip over it
else
- titles.Add(Title.Parse(sr));
+ titles.Add(Parse(sr));
}
return titles.ToArray();
}
}
-}
+} \ No newline at end of file