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 hbProc.WaitForExit();
\r
36 //Parsing.DVD thisDvd = Parsing.DVD.Parse(errorReader);
\r
38 String DvdData = errorReader.ReadToEnd();
\r
39 DvdData = DvdData + "-- end --";
\r
41 String[] DvdDataArr = DvdData.Split('\n');
\r
42 int DvdDataSize = DvdDataArr.Length -1;
\r
47 // Some varbiles used for parseing HandBrakes output
\r
50 // DVD info stroage varibles
\r
51 string titleData = "";
\r
52 string duationData = "";
\r
53 string sizeData = "";
\r
54 string cropdata = "";
\r
55 string chatperData = "";
\r
56 string audioData = "";
\r
57 string subtitleData = "";
\r
59 string fullTitleData = "";
\r
61 // Position Pointers
\r
62 bool chapterPointer = false;
\r
63 bool audioPointer = false;
\r
64 bool subtitlePointer = false;
\r
66 // Error handling varibles
\r
67 bool titleError = false;
\r
68 bool readError = false;
\r
70 while (counter <= DvdDataSize)
\r
72 line = DvdDataArr[counter];
\r
75 // Get all the 1 liner data and set chaper potiner to true when done
\r
76 if (line.Contains("exited.")){
\r
77 subtitlePointer = false;
\r
78 fullTitleData = titleData.Trim() + " ~ " + duationData.Trim() + " ~ " + sizeData.Trim() + " ~ " + cropdata.Trim() + " ~ " + chatperData.Trim() + " ~ " + audioData.Trim() + " ~ " + subtitleData.Trim();
\r
79 add(fullTitleData, titleData, duationData);
\r
81 }else if (line.Contains("+ title")){
\r
82 if (titleData != "") {
\r
83 subtitlePointer = true;
\r
84 fullTitleData = titleData.Trim() + " ~ " + duationData.Trim() + " ~ " + sizeData.Trim() + " ~ " + cropdata.Trim() + " ~ " + chatperData.Trim() + " ~ " + audioData.Trim() + " ~ " + subtitleData.Trim();
\r
85 add(fullTitleData, titleData, duationData);
\r
86 counter = counter + 1;
\r
89 }else if (line.Contains("+ duration")) {
\r
91 }else if (line.Contains("+ size")) {
\r
93 }else if (line.Contains("+ autocrop")) {
\r
95 }else if (line.Contains("+ chapters")) {
\r
97 chapterPointer = true;
\r
100 // Get all the chapter information in 1 varible
\r
101 if (chapterPointer == true)
\r
103 if (!line.Contains("+ audio"))
\r
105 chapterPointer = false;
\r
106 audioPointer = true;
\r
111 if (!chatperData.Equals(line))
\r
113 chatperData = chatperData + " & " + line.Trim();
\r
118 // Get all the audio channel information in 1 varible
\r
119 if (audioPointer == true)
\r
121 if (line.Contains("+ subtitle"))
\r
123 audioPointer = false;
\r
124 subtitlePointer = true;
\r
125 subtitleData = line;
\r
129 if (!audioData.Equals(line))
\r
131 audioData = audioData + " & " + line.Trim();
\r
136 //Get all the subtitle data into 1 varible
\r
137 if (subtitlePointer == true)
\r
139 if (line.Contains("+ subtitle"))
\r
141 subtitleData = line;
\r
144 if (!subtitleData.Equals(line))
\r
146 subtitleData = subtitleData + " & " + line.Trim();
\r
151 // Handle some of Handbrakes Error outputs if they occur.
\r
152 if (line.Contains("No title"))
\r
157 if (line.Contains("***"))
\r
162 // Display error messages for errors detected above.
\r
163 if (readError == true)
\r
165 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
168 if (titleError == true)
\r
170 MessageBox.Show("No Title(s) found. Please make sure you have selected a valid, non-copy protected source.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
\r
176 public void add(string fullTitleData, string titleData, string durationData)
\r
181 string t = titleData.Trim().Substring(8).Replace(":", "");
\r
182 string d = durationData.Trim().Substring(12);
\r
184 // Lets store the captured full title data as a string in the programs settings file.
\r
185 // This can then be used by the DVD title dropdown menu to populate other fields.
\r
187 Properties.Settings.Default.FullDVDInfo = Properties.Settings.Default.FullDVDInfo + " \n " + fullTitleData;
\r
189 //Now lets add the info to the main form dropdowns
\r
190 frmMain form = (frmMain)frmMain.ActiveForm;
\r
191 string title = t + " " + " " + d + " ";
\r
192 form.drp_dvdtitle.Items.Add(title);
\r
196 // Don't really need to do anything about it.
\r
201 private void btn_ok_Click(object sender, EventArgs e)
\r