2 using System.Collections.Generic;
\r
3 using System.ComponentModel;
\r
5 using System.Drawing;
\r
7 using System.Windows.Forms;
\r
11 public partial class frmReadDVD : Form
\r
16 public frmReadDVD(string inputFile)
\r
18 InitializeComponent();
\r
19 this.inputFile = inputFile;
\r
22 public void scan(string filename)
\r
24 string query = "-i " + '"' + filename + '"' + " -t0";
\r
25 System.Diagnostics.Process hbProc = new System.Diagnostics.Process();
\r
26 hbProc.StartInfo.FileName = "hbcli.exe";
\r
27 hbProc.StartInfo.RedirectStandardOutput = true;
\r
28 hbProc.StartInfo.RedirectStandardError = true;
\r
29 hbProc.StartInfo.Arguments = query;
\r
30 hbProc.StartInfo.UseShellExecute = false;
\r
32 System.IO.StreamReader errorReader = new System.IO.StreamReader(new System.IO.BufferedStream(hbProc.StandardError.BaseStream));
\r
33 //rtf_dvdInfo.AppendText(errorReader.ReadToEnd());
\r
34 hbProc.WaitForExit();
\r
37 String DvdData = errorReader.ReadToEnd();
\r
38 DvdData = DvdData + "-- end --";
\r
40 String[] DvdDataArr = DvdData.Split('\n');
\r
41 int DvdDataSize = DvdDataArr.Length -1;
\r
46 // Some varbiles used for parseing HandBrakes output
\r
49 // DVD info stroage varibles
\r
50 string titleData = "";
\r
51 string duationData = "";
\r
52 string sizeData = "";
\r
53 string cropdata = "";
\r
54 string chatperData = "";
\r
55 string audioData = "";
\r
56 string subtitleData = "";
\r
58 string fullTitleData = "";
\r
60 // Position Pointers
\r
61 bool chapterPointer = false;
\r
62 bool audioPointer = false;
\r
63 bool subtitlePointer = false;
\r
65 // Error handling varibles
\r
66 bool titleError = false;
\r
67 bool readError = false;
\r
69 while (counter <= DvdDataSize)
\r
71 line = DvdDataArr[counter];
\r
74 // Get all the 1 liner data and set chaper potiner to true when done
\r
75 if (line.Contains("exited.")){
\r
76 subtitlePointer = false;
\r
77 fullTitleData = titleData.Trim() + " ~ " + duationData.Trim() + " ~ " + sizeData.Trim() + " ~ " + cropdata.Trim() + " ~ " + chatperData.Trim() + " ~ " + audioData.Trim() + " ~ " + subtitleData.Trim();
\r
80 }else if (line.Contains("+ title")){
\r
81 if (titleData != "") {
\r
82 subtitlePointer = true;
\r
83 fullTitleData = titleData.Trim() + " ~ " + duationData.Trim() + " ~ " + sizeData.Trim() + " ~ " + cropdata.Trim() + " ~ " + chatperData.Trim() + " ~ " + audioData.Trim() + " ~ " + subtitleData.Trim();
\r
85 counter = counter + 1;
\r
88 }else if (line.Contains("+ duration")) {
\r
90 }else if (line.Contains("+ size")) {
\r
92 }else if (line.Contains("+ autocrop")) {
\r
94 }else if (line.Contains("+ chapters")) {
\r
96 chapterPointer = true;
\r
99 // Get all the chapter information in 1 varible
\r
100 if (chapterPointer == true)
\r
102 if (!line.Contains("+ audio"))
\r
104 chapterPointer = false;
\r
105 audioPointer = true;
\r
110 if (!chatperData.Equals(line))
\r
112 chatperData = chatperData + " & " + line.Trim();
\r
117 // Get all the audio channel information in 1 varible
\r
118 if (audioPointer == true)
\r
120 if (line.Contains("+ subtitle"))
\r
122 audioPointer = false;
\r
123 subtitlePointer = true;
\r
124 subtitleData = line;
\r
128 if (!audioData.Equals(line))
\r
130 audioData = audioData + " & " + line.Trim();
\r
135 //Get all the subtitle data into 1 varible
\r
136 if (subtitlePointer == true)
\r
138 if (line.Contains("+ subtitle"))
\r
140 subtitleData = line;
\r
143 if (!subtitleData.Equals(line))
\r
145 subtitleData = subtitleData + " & " + line.Trim();
\r
150 // Handle some of Handbrakes Error outputs if they occur.
\r
151 if (line.Contains("No title"))
\r
156 if (line.Contains("***"))
\r
161 // Display error messages for errors detected above.
\r
162 if (readError == true)
\r
164 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);
\r
167 if (titleError == true)
\r
169 MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
175 public void add(string titleData)
\r
177 string[] titleInfo = new string[10];
\r
178 string[] str = new string[1];
\r
184 titleInfo = titleData.Split('~');
\r
187 t = titleInfo[0].Trim().Substring(8).Replace(":", ""); // Title
\r
188 d = titleInfo[1].Trim().Substring(12); //Duration
\r
189 } catch(Exception){
\r
190 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);
\r
193 //Now lets add the info to the main form dropdowns
\r
194 frmMain form = (frmMain)frmMain.ActiveForm;
\r
195 title = t + " " + " " + d + " ";
\r
196 form.drp_dvdtitle.Items.Add(title);
\r
199 private void btn_ok_Click(object sender, EventArgs e)
\r