OSDN Git Service

2ecff6fd593f98e0ea691ba238c1bfc2a4abc7cb
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmReadDVD.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.ComponentModel;\r
4 using System.Data;\r
5 using System.Drawing;\r
6 using System.Text;\r
7 using System.Windows.Forms;\r
8 \r
9 namespace Handbrake\r
10 {\r
11     public partial class frmReadDVD : Form\r
12     {\r
13 \r
14         string inputFile;\r
15 \r
16         public frmReadDVD(string inputFile)\r
17         {\r
18             InitializeComponent();\r
19             this.inputFile = inputFile;\r
20         }\r
21 \r
22         public void scan(string filename)\r
23         {\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
31             hbProc.Start();\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
35             hbProc.Close();\r
36 \r
37             String DvdData = errorReader.ReadToEnd();\r
38             DvdData = DvdData + "-- end --";\r
39 \r
40             String[] DvdDataArr = DvdData.Split('\n');\r
41             int DvdDataSize = DvdDataArr.Length -1;\r
42             String line = "";\r
43             int counter = 0;\r
44 \r
45             //\r
46             // Some varbiles used for parseing HandBrakes output\r
47             //\r
48 \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
57 \r
58             string fullTitleData  = "";\r
59 \r
60             // Position Pointers\r
61             bool chapterPointer  = false;\r
62             bool audioPointer = false;\r
63             bool subtitlePointer = false;\r
64 \r
65             // Error handling varibles\r
66             bool titleError = false;\r
67             bool readError = false;\r
68             \r
69             while (counter <= DvdDataSize)\r
70             {\r
71                 line = DvdDataArr[counter];\r
72                 counter++;\r
73                  \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
78                     add(fullTitleData);\r
79                     counter++;\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
84                         add(fullTitleData);\r
85                         counter = counter + 1;\r
86                     }\r
87                     titleData = line;\r
88                 }else if (line.Contains("+ duration")) {\r
89                     duationData = line;\r
90                 }else if (line.Contains("+ size")) {\r
91                     sizeData = line;\r
92                 }else if (line.Contains("+ autocrop")) {\r
93                     cropdata = line;\r
94                 }else if (line.Contains("+ chapters")) {\r
95                     chatperData = line;\r
96                     chapterPointer = true;\r
97                 }\r
98 \r
99                 // Get all the chapter information in 1 varible\r
100                 if (chapterPointer == true)\r
101                 {\r
102                     if (!line.Contains("+ audio"))\r
103                     {\r
104                         chapterPointer = false;\r
105                         audioPointer = true;\r
106                         audioData = line;\r
107                    }\r
108                     else \r
109                     {\r
110                         if (!chatperData.Equals(line))\r
111                         {\r
112                             chatperData = chatperData + " & " + line.Trim();\r
113                         }\r
114                     }\r
115                 }\r
116 \r
117                  // Get all the audio channel information in 1 varible\r
118                 if (audioPointer == true)\r
119                 { \r
120                     if (line.Contains("+ subtitle"))\r
121                     {\r
122                         audioPointer = false;\r
123                         subtitlePointer = true;\r
124                         subtitleData = line;\r
125                     } \r
126                     else \r
127                     {\r
128                         if (!audioData.Equals(line))\r
129                         {\r
130                             audioData = audioData + " & " + line.Trim();\r
131                         }\r
132                     }\r
133                  }\r
134 \r
135                  //Get all the subtitle data into 1 varible\r
136                  if (subtitlePointer == true)\r
137                  {\r
138                             if (line.Contains("+ subtitle")) \r
139                             {\r
140                                 subtitleData = line;\r
141                             } else \r
142                             {\r
143                                 if (!subtitleData.Equals(line))\r
144                                 {\r
145                                     subtitleData = subtitleData + " & " + line.Trim();\r
146                                 }\r
147                             }\r
148                   }\r
149 \r
150                   // Handle some of Handbrakes Error outputs if they occur.\r
151                   if (line.Contains("No title"))\r
152                   {\r
153                     titleError = true;\r
154                   }\r
155 \r
156                   if (line.Contains("***")) \r
157                   {\r
158                     readError = true;\r
159                   }\r
160 \r
161                  // Display error messages for errors detected above.\r
162                  if (readError == true)\r
163                  {\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
165                  }\r
166 \r
167                  if (titleError == true)\r
168                  {\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
170                  }\r
171 \r
172             }\r
173         }\r
174 \r
175         public void add(string titleData)\r
176         {\r
177             string[] titleInfo = new string[10];\r
178             string[] str = new string[1];\r
179 \r
180             string title;\r
181             string t ="";\r
182             string d ="";\r
183 \r
184             titleInfo = titleData.Split('~');\r
185             try\r
186             {\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
191             }\r
192 \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
197         }\r
198 \r
199         private void btn_ok_Click(object sender, EventArgs e)\r
200         {\r
201             start(inputFile);\r
202         }\r
203 \r
204        \r
205     }\r
206 }