summaryrefslogtreecommitdiffstats
path: root/win/C#/frmReadDVD.cs
diff options
context:
space:
mode:
authorsr55 <[email protected]>2007-07-08 23:56:26 +0000
committersr55 <[email protected]>2007-07-08 23:56:26 +0000
commit16222f64e3f0f6dc7c256111bc191d3ff69419f6 (patch)
tree8eb466df7ecb9c698a28716994238b5aee1b7509 /win/C#/frmReadDVD.cs
parent978740968f3e369f4072752c7a3432c7dfdef335 (diff)
WinGui:
- C# Handbrake CLI output parsing code converted from vb.net project. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@660 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/frmReadDVD.cs')
-rw-r--r--win/C#/frmReadDVD.cs177
1 files changed, 162 insertions, 15 deletions
diff --git a/win/C#/frmReadDVD.cs b/win/C#/frmReadDVD.cs
index ca70a6ba1..2ecff6fd5 100644
--- a/win/C#/frmReadDVD.cs
+++ b/win/C#/frmReadDVD.cs
@@ -19,34 +19,181 @@ namespace Handbrake
this.inputFile = inputFile;
}
- private void frmReadDVD_Load(object sender, EventArgs e)
+ public void scan(string filename)
{
- //start(inputFile);
- }
-
- public void start(string filename)
- {
- MessageBox.Show(filename);
string query = "-i " + '"' + filename + '"' + " -t0";
System.Diagnostics.Process hbProc = new System.Diagnostics.Process();
hbProc.StartInfo.FileName = "hbcli.exe";
hbProc.StartInfo.RedirectStandardOutput = true;
hbProc.StartInfo.RedirectStandardError = true;
- //hbProc.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8;
- //hbProc.StartInfo.StandardErrorEncoding = System.Text.Encoding.UTF8;
hbProc.StartInfo.Arguments = query;
hbProc.StartInfo.UseShellExecute = false;
hbProc.Start();
+ System.IO.StreamReader errorReader = new System.IO.StreamReader(new System.IO.BufferedStream(hbProc.StandardError.BaseStream));
+ //rtf_dvdInfo.AppendText(errorReader.ReadToEnd());
+ hbProc.WaitForExit();
+ hbProc.Close();
+
+ String DvdData = errorReader.ReadToEnd();
+ DvdData = DvdData + "-- end --";
+
+ String[] DvdDataArr = DvdData.Split('\n');
+ int DvdDataSize = DvdDataArr.Length -1;
+ String line = "";
+ int counter = 0;
+
+ //
+ // Some varbiles used for parseing HandBrakes output
+ //
+
+ // DVD info stroage varibles
+ string titleData = "";
+ string duationData = "";
+ string sizeData = "";
+ string cropdata = "";
+ string chatperData = "";
+ string audioData = "";
+ string subtitleData = "";
+
+ string fullTitleData = "";
+
+ // Position Pointers
+ bool chapterPointer = false;
+ bool audioPointer = false;
+ bool subtitlePointer = false;
+
+ // Error handling varibles
+ bool titleError = false;
+ bool readError = false;
+
+ while (counter <= DvdDataSize)
+ {
+ line = DvdDataArr[counter];
+ counter++;
+
+ // Get all the 1 liner data and set chaper potiner to true when done
+ if (line.Contains("exited.")){
+ subtitlePointer = false;
+ fullTitleData = titleData.Trim() + " ~ " + duationData.Trim() + " ~ " + sizeData.Trim() + " ~ " + cropdata.Trim() + " ~ " + chatperData.Trim() + " ~ " + audioData.Trim() + " ~ " + subtitleData.Trim();
+ add(fullTitleData);
+ counter++;
+ }else if (line.Contains("+ title")){
+ if (titleData != "") {
+ subtitlePointer = true;
+ fullTitleData = titleData.Trim() + " ~ " + duationData.Trim() + " ~ " + sizeData.Trim() + " ~ " + cropdata.Trim() + " ~ " + chatperData.Trim() + " ~ " + audioData.Trim() + " ~ " + subtitleData.Trim();
+ add(fullTitleData);
+ counter = counter + 1;
+ }
+ titleData = line;
+ }else if (line.Contains("+ duration")) {
+ duationData = line;
+ }else if (line.Contains("+ size")) {
+ sizeData = line;
+ }else if (line.Contains("+ autocrop")) {
+ cropdata = line;
+ }else if (line.Contains("+ chapters")) {
+ chatperData = line;
+ chapterPointer = true;
+ }
+
+ // Get all the chapter information in 1 varible
+ if (chapterPointer == true)
+ {
+ if (!line.Contains("+ audio"))
+ {
+ chapterPointer = false;
+ audioPointer = true;
+ audioData = line;
+ }
+ else
+ {
+ if (!chatperData.Equals(line))
+ {
+ chatperData = chatperData + " & " + line.Trim();
+ }
+ }
+ }
+
+ // Get all the audio channel information in 1 varible
+ if (audioPointer == true)
+ {
+ if (line.Contains("+ subtitle"))
+ {
+ audioPointer = false;
+ subtitlePointer = true;
+ subtitleData = line;
+ }
+ else
+ {
+ if (!audioData.Equals(line))
+ {
+ audioData = audioData + " & " + line.Trim();
+ }
+ }
+ }
+
+ //Get all the subtitle data into 1 varible
+ if (subtitlePointer == true)
+ {
+ if (line.Contains("+ subtitle"))
+ {
+ subtitleData = line;
+ } else
+ {
+ if (!subtitleData.Equals(line))
+ {
+ subtitleData = subtitleData + " & " + line.Trim();
+ }
+ }
+ }
+
+ // Handle some of Handbrakes Error outputs if they occur.
+ if (line.Contains("No title"))
+ {
+ titleError = true;
+ }
+
+ if (line.Contains("***"))
+ {
+ readError = true;
+ }
+
+ // Display error messages for errors detected above.
+ if (readError == true)
+ {
+ MessageBox.Show("Some DVD Title information may be missing however you may still be able to select your required title for encoding!", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
+ }
+
+ if (titleError == true)
+ {
+ MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
+ }
+
+ }
+ }
+
+ public void add(string titleData)
+ {
+ string[] titleInfo = new string[10];
+ string[] str = new string[1];
+
+ string title;
+ string t ="";
+ string d ="";
- rtf_dvdInfo.Text = "-- Start --";
- while (hbProc.StandardOutput.BaseStream.CanRead && !hbProc.HasExited)
+ titleInfo = titleData.Split('~');
+ try
{
- rtf_dvdInfo.Text = rtf_dvdInfo.Text + "\n" + hbProc.StandardOutput.ReadLine();
- rtf_dvdInfo.Text = rtf_dvdInfo.Text + "\n" + hbProc.StandardError.ReadLine();
- MessageBox.Show("Test");
+ t = titleInfo[0].Trim().Substring(8).Replace(":", ""); // Title
+ d = titleInfo[1].Trim().Substring(12); //Duration
+ } catch(Exception){
+ MessageBox.Show("Incomplete DVD data found. Please copy the data on the View DVD Information tab and report this error.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
- rtf_dvdInfo.Text = rtf_dvdInfo.Text + "\n" + "-- End --";
+ //Now lets add the info to the main form dropdowns
+ frmMain form = (frmMain)frmMain.ActiveForm;
+ title = t + " " + " " + d + " ";
+ form.drp_dvdtitle.Items.Add(title);
}
private void btn_ok_Click(object sender, EventArgs e)