diff options
author | brianmario <[email protected]> | 2007-07-09 22:26:54 +0000 |
---|---|---|
committer | brianmario <[email protected]> | 2007-07-09 22:26:54 +0000 |
commit | 67570f0d1a66754708b519467443d81549841746 (patch) | |
tree | 954e91fc001ceda75d1573563bf4af2623c18b16 /win/C#/Parsing | |
parent | f443f516c2f56d2b64bd1b6c050ff75801b80112 (diff) |
added new parsing code to parse cli output into objects
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@667 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/Parsing')
-rw-r--r-- | win/C#/Parsing/AudioTrack.cs | 103 | ||||
-rw-r--r-- | win/C#/Parsing/Chapter.cs | 84 | ||||
-rw-r--r-- | win/C#/Parsing/DVD.cs | 38 | ||||
-rw-r--r-- | win/C#/Parsing/Subtitle.cs | 63 | ||||
-rw-r--r-- | win/C#/Parsing/Title.cs | 184 |
5 files changed, 472 insertions, 0 deletions
diff --git a/win/C#/Parsing/AudioTrack.cs b/win/C#/Parsing/AudioTrack.cs new file mode 100644 index 000000000..6232da2a9 --- /dev/null +++ b/win/C#/Parsing/AudioTrack.cs @@ -0,0 +1,103 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+
+namespace Handbrake.Parsing
+{
+ public class AudioTrack
+ {
+ private int m_trackNumber;
+ public int TrackNumber
+ {
+ get
+ {
+ return this.m_trackNumber;
+ }
+ }
+
+ private string m_language;
+ public string Language
+ {
+ get
+ {
+ return this.m_language;
+ }
+ }
+
+ private string m_format;
+ public string Format
+ {
+ get
+ {
+ return this.m_format;
+ }
+ }
+
+ private string m_subFormat;
+ public string SubFormat
+ {
+ get
+ {
+ return this.m_subFormat;
+ }
+ }
+
+ private int m_frequency;
+ public int Frequency
+ {
+ get
+ {
+ return this.m_frequency;
+ }
+ }
+
+ private int m_bitrate;
+ public int Bitrate
+ {
+ get
+ {
+ return this.m_bitrate;
+ }
+ }
+
+ public static AudioTrack Parse(StreamReader output)
+ {
+ string curLine = output.ReadLine();
+ if (!curLine.Contains(" + subtitle tracks:"))
+ {
+ 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];
+ thisTrack.m_subFormat = splitter[3];
+ thisTrack.m_frequency = int.Parse(splitter[4]);
+ thisTrack.m_bitrate = int.Parse(splitter[5]);
+ return thisTrack;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public static AudioTrack[] ParseList(StreamReader output)
+ {
+ List<AudioTrack> tracks = new List<AudioTrack>();
+ while (true) // oh glorious hack, serve me well
+ {
+ AudioTrack thisTrack = AudioTrack.Parse(output);
+ if (thisTrack != null)
+ {
+ tracks.Add(thisTrack);
+ }
+ else
+ {
+ break;
+ }
+ }
+ return tracks.ToArray();
+ }
+ }
+}
diff --git a/win/C#/Parsing/Chapter.cs b/win/C#/Parsing/Chapter.cs new file mode 100644 index 000000000..630ab0905 --- /dev/null +++ b/win/C#/Parsing/Chapter.cs @@ -0,0 +1,84 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+
+namespace Handbrake.Parsing
+{
+ public class Chapter
+ {
+ private int m_chapterNumber;
+ public int ChapterNumber
+ {
+ get
+ {
+ return this.m_chapterNumber;
+ }
+ }
+
+ private int[] m_cellRange;
+ public int[] CellRange
+ {
+ get
+ {
+ return this.m_cellRange;
+ }
+ }
+
+ private int m_blocks;
+ public int BlockCount
+ {
+ get
+ {
+ return this.m_blocks;
+ }
+ }
+
+ private TimeSpan m_duration;
+ public TimeSpan Duration
+ {
+ get
+ {
+ return this.m_duration;
+ }
+ }
+
+ public static Chapter Parse(StreamReader output)
+ {
+ string curLine = output.ReadLine();
+ if (!curLine.Contains(" + audio tracks:"))
+ {
+ Chapter thisChapter = new Chapter();
+ string[] splitter = curLine.Split(new string[] { " + ", ": cells ", ", ", " blocks, duration ", "->" }, StringSplitOptions.RemoveEmptyEntries);
+ thisChapter.m_chapterNumber = int.Parse(splitter[0]);
+ thisChapter.m_cellRange = new int[2] { int.Parse(splitter[1]), int.Parse(splitter[2]) };
+ thisChapter.m_blocks = int.Parse(splitter[3]);
+ thisChapter.m_duration = TimeSpan.Parse(splitter[4]);
+ return thisChapter;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public static Chapter[] ParseList(StreamReader output)
+ {
+ List<Chapter> chapters = new List<Chapter>();
+ string curLine = output.ReadLine();
+ while (!curLine.Contains(" + audio tracks:"))
+ {
+ Chapter thisChapter = Chapter.Parse(output);
+ if (thisChapter != null)
+ {
+ chapters.Add(thisChapter);
+ }
+ else
+ {
+ break;
+ }
+ }
+ return chapters.ToArray();
+ }
+ }
+}
diff --git a/win/C#/Parsing/DVD.cs b/win/C#/Parsing/DVD.cs new file mode 100644 index 000000000..50751ccf2 --- /dev/null +++ b/win/C#/Parsing/DVD.cs @@ -0,0 +1,38 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+
+namespace Handbrake.Parsing
+{
+ public class DVD
+ {
+ private List<Title> m_titles;
+ public List<Title> Titles
+ {
+ get
+ {
+ return this.m_titles;
+ }
+ }
+
+ public DVD()
+ {
+ this.m_titles = new List<Title>();
+ }
+
+ public static DVD Parse(StreamReader output)
+ {
+ DVD thisDVD = new DVD();
+ while (!output.EndOfStream)
+ {
+ string curLine = output.ReadLine();
+ if (curLine.Contains("Scanning title"))
+ {
+ thisDVD.m_titles.AddRange(Title.ParseList(output));
+ }
+ }
+ return thisDVD;
+ }
+ }
+}
diff --git a/win/C#/Parsing/Subtitle.cs b/win/C#/Parsing/Subtitle.cs new file mode 100644 index 000000000..a9c169ddc --- /dev/null +++ b/win/C#/Parsing/Subtitle.cs @@ -0,0 +1,63 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+
+namespace Handbrake.Parsing
+{
+ public class Subtitle
+ {
+ private int m_trackNumber;
+ public int TrackNumber
+ {
+ get
+ {
+ return this.m_trackNumber;
+ }
+ }
+
+ private string m_language;
+ public string Language
+ {
+ get
+ {
+ return this.m_language;
+ }
+ }
+
+ public static Subtitle Parse(StreamReader output)
+ {
+ string curLine = output.ReadLine();
+ if (!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];
+ return thisSubtitle;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public static Subtitle[] ParseList(StreamReader output)
+ {
+ List<Subtitle> subtitles = new List<Subtitle>();
+ while ((char)output.Peek() != '+') // oh glorious hack, serve me well
+ {
+ Subtitle thisSubtitle = Subtitle.Parse(output);
+ if (thisSubtitle != null)
+ {
+ subtitles.Add(thisSubtitle);
+ }
+ else
+ {
+ break;
+ }
+ }
+ return subtitles.ToArray();
+ }
+ }
+}
diff --git a/win/C#/Parsing/Title.cs b/win/C#/Parsing/Title.cs new file mode 100644 index 000000000..5df7a6bb4 --- /dev/null +++ b/win/C#/Parsing/Title.cs @@ -0,0 +1,184 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Drawing;
+using System.IO;
+
+namespace Handbrake.Parsing
+{
+ public class Title
+ {
+ private List<Chapter> m_chapters;
+ public List<Chapter> Chapters
+ {
+ get
+ {
+ return this.m_chapters;
+ }
+ }
+
+ private List<AudioTrack> m_audioTracks;
+ public List<AudioTrack> AudioTracks
+ {
+ get
+ {
+ return this.m_audioTracks;
+ }
+ }
+
+ private List<Subtitle> m_subtitles;
+ public List<Subtitle> Subtitles
+ {
+ get
+ {
+ return this.m_subtitles;
+ }
+ }
+
+ private int m_vts;
+ public int Vts
+ {
+ get
+ {
+ return this.m_vts;
+ }
+ }
+
+ private int m_ttn;
+ public int Ttn
+ {
+ get
+ {
+ return this.m_ttn;
+ }
+ }
+
+ private int[] m_cellRange;
+ public int[] CellRange
+ {
+ get
+ {
+ return this.m_cellRange;
+ }
+ }
+
+ private int m_blockCount;
+ public int BlockCount
+ {
+ get
+ {
+ return this.m_blockCount;
+ }
+ }
+
+ private int m_titleNumber;
+ public int TitleNumber
+ {
+ get
+ {
+ return this.m_titleNumber;
+ }
+ }
+
+ private TimeSpan m_duration;
+ public TimeSpan Duration
+ {
+ get
+ {
+ return this.m_duration;
+ }
+ }
+
+ private Size m_resolution;
+ public Size Resolution
+ {
+ get
+ {
+ return this.m_resolution;
+ }
+ }
+
+ private float m_aspectRatio;
+ public float AspectRatio
+ {
+ get
+ {
+ return this.m_aspectRatio;
+ }
+ }
+
+ private float m_fps;
+ public float Fps
+ {
+ get
+ {
+ return this.m_fps;
+ }
+ }
+
+ private int[] m_autoCrop;
+ public int[] AutoCropDimensions
+ {
+ get
+ {
+ return this.m_autoCrop;
+ }
+ }
+
+ public Title()
+ {
+ this.m_audioTracks = new List<AudioTrack>();
+ this.m_chapters = new List<Chapter>();
+ this.m_subtitles = new List<Subtitle>();
+ this.m_cellRange = new int[2];
+ }
+
+ public static Title Parse(StreamReader output)
+ {
+ Title thisTitle = new Title();
+
+ /*
+ * This will be converted to use Regex soon, I promise ;)
+ * brianmario - 7/9/07
+ */
+
+ string curLine = output.ReadLine();
+ thisTitle.m_titleNumber = int.Parse(curLine.Substring(curLine.Length - 2, 1));
+ curLine = output.ReadLine();
+ string[] splitter = curLine.Split(',');
+ thisTitle.m_vts = int.Parse(splitter[0].Substring(8));
+ thisTitle.m_ttn = int.Parse(splitter[1].Substring(5));
+ splitter = splitter[2].Trim().Split(' ', '(', ')');
+ thisTitle.m_blockCount = int.Parse(splitter[3]);
+ splitter = splitter[1].Split('-', '>');
+ thisTitle.m_cellRange[0] = int.Parse(splitter[0]);
+ thisTitle.m_cellRange[1] = int.Parse(splitter[2]);
+ 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());
+ thisTitle.m_fps = float.Parse(splitter[3].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]) };
+ 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)
+ {
+ List<Title> titles = new List<Title>();
+ while ((char)output.Peek() == '+')
+ {
+ titles.Add(Title.Parse(output));
+ }
+ return titles.ToArray();
+ }
+ }
+}
|