OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / QueryParser.cs
1 /*  QueryParser.cs $\r
2     This file is part of the HandBrake source code.\r
3     Homepage: <http://handbrake.fr>.\r
4     It may be used under the terms of the GNU General Public License. */\r
5 \r
6 namespace Handbrake.Functions\r
7 {\r
8     using System;\r
9     using System.Collections;\r
10     using System.Globalization;\r
11     using System.Text.RegularExpressions;\r
12     using System.Windows.Forms;\r
13     using Model;\r
14 \r
15     /// <summary>\r
16     /// Parse a CLI Query\r
17     /// </summary>\r
18     public class QueryParser\r
19     {\r
20         /// <summary>\r
21         /// The Culture\r
22         /// </summary>\r
23         private static readonly CultureInfo Culture = new CultureInfo("en-US", false);\r
24 \r
25         #region Varibles\r
26 \r
27         #region Source Title / Chapters\r
28         /// <summary>\r
29         /// Gets or sets Title.\r
30         /// </summary>\r
31         public int Title { get; set; }\r
32 \r
33         /// <summary>\r
34         /// Gets or sets ChapterStart.\r
35         /// </summary>\r
36         public int ChapterStart { get; set; }\r
37 \r
38         /// <summary>\r
39         /// Gets or sets ChapterFinish.\r
40         /// </summary>\r
41         public int ChapterFinish { get; set; }\r
42         #endregion\r
43 \r
44         #region Output Settings\r
45         /// <summary>\r
46         /// Gets or sets the file Format. e.g mkv or mp4\r
47         /// </summary>\r
48         public string Format { get; set; }\r
49 \r
50         /// <summary>\r
51         /// Gets or sets a value indicating whether LargeMP4 support is enabled.\r
52         /// This is the 64bit MP4 file that allows >4GB files\r
53         /// </summary>\r
54         public bool LargeMP4 { get; set; }\r
55 \r
56         /// <summary>\r
57         /// Gets or sets a value indicating whether IpodAtom is inserted\r
58         /// </summary>\r
59         public bool IpodAtom { get; set; }\r
60 \r
61         /// <summary>\r
62         /// Gets or sets a value indicating whether OptimizeMP4 is enabed for web streaming\r
63         /// </summary>\r
64         public bool OptimizeMP4 { get; set; }\r
65         #endregion\r
66 \r
67         #region Picture Settings\r
68 \r
69         /// <summary>\r
70         /// Gets or sets Width.\r
71         /// </summary>\r
72         public int Width { get; set; }\r
73 \r
74         /// <summary>\r
75         /// Gets or sets Height.\r
76         /// </summary>\r
77         public int Height { get; set; }\r
78 \r
79         /// <summary>\r
80         /// Gets or sets MaxWidth.\r
81         /// </summary>\r
82         public int MaxWidth { get; set; }\r
83 \r
84         /// <summary>\r
85         /// Gets or sets MaxHeight.\r
86         /// </summary>\r
87         public int MaxHeight { get; set; }\r
88 \r
89         /// <summary>\r
90         /// Gets or sets CropValues.\r
91         /// </summary>\r
92         public string CropValues { get; set; }\r
93 \r
94         /// <summary>\r
95         /// Gets or sets CropTop.\r
96         /// </summary>\r
97         public string CropTop { get; set; }\r
98 \r
99         /// <summary>\r
100         /// Gets or sets CropBottom.\r
101         /// </summary>\r
102         public string CropBottom { get; set; }\r
103 \r
104         /// <summary>\r
105         /// Gets or sets CropLeft.\r
106         /// </summary>\r
107         public string CropLeft { get; set; }\r
108 \r
109         /// <summary>\r
110         /// Gets or sets CropRight.\r
111         /// </summary>\r
112         public string CropRight { get; set; }\r
113 \r
114         /// <summary>\r
115         /// Gets or sets AnamorphicMode.\r
116         /// </summary>\r
117         public int AnamorphicMode { get; set; }\r
118 \r
119         /// <summary>\r
120         /// Gets or sets a value indicating whether KeepDisplayAsect.\r
121         /// </summary>\r
122         public bool KeepDisplayAsect { get; set; }\r
123 \r
124         /// <summary>\r
125         /// Gets or sets DisplayWidthValue.\r
126         /// </summary>\r
127         public double DisplayWidthValue { get; set; }\r
128 \r
129         /// <summary>\r
130         /// Gets or sets PixelAspectWidth.\r
131         /// </summary>\r
132         public int PixelAspectWidth { get; set; }\r
133 \r
134         /// <summary>\r
135         /// Gets or sets PixelAspectHeight.\r
136         /// </summary>\r
137         public int PixelAspectHeight { get; set; }\r
138 \r
139         /// <summary>\r
140         /// Gets or sets AnamorphicModulus.\r
141         /// </summary>\r
142         public int AnamorphicModulus { get; set; }\r
143         #endregion\r
144 \r
145         #region Video Filters\r
146 \r
147         /// <summary>\r
148         /// Gets or sets DeTelecine.\r
149         /// </summary>\r
150         public string DeTelecine { get; set; }\r
151 \r
152         /// <summary>\r
153         /// Gets or sets DeBlock.\r
154         /// </summary>\r
155         public int DeBlock { get; set; }\r
156 \r
157         /// <summary>\r
158         /// Gets or sets DeInterlace.\r
159         /// </summary>\r
160         public string DeInterlace { get; set; }\r
161 \r
162         /// <summary>\r
163         /// Gets or sets DeNoise.\r
164         /// </summary>\r
165         public string DeNoise { get; set; }\r
166 \r
167         /// <summary>\r
168         /// Gets or sets Decomb.\r
169         /// </summary>\r
170         public string Decomb { get; set; }\r
171         #endregion\r
172 \r
173         #region Video Settings\r
174         /// <summary>\r
175         /// Gets or sets VideoEncoder.\r
176         /// </summary>\r
177         public string VideoEncoder { get; set; }\r
178 \r
179         /// <summary>\r
180         /// Gets or sets a value indicating whether Grayscale.\r
181         /// </summary>\r
182         public bool Grayscale { get; set; }\r
183 \r
184         /// <summary>\r
185         /// Gets or sets a value indicating whether TwoPass.\r
186         /// </summary>\r
187         public bool TwoPass { get; set; }\r
188 \r
189         /// <summary>\r
190         /// Gets or sets a value indicating whether TurboFirstPass.\r
191         /// </summary>\r
192         public bool TurboFirstPass { get; set; }\r
193 \r
194         /// <summary>\r
195         /// Gets or sets VideoFramerate.\r
196         /// </summary>\r
197         public string VideoFramerate { get; set; }\r
198 \r
199         /// <summary>\r
200         /// Gets or sets AverageVideoBitrate.\r
201         /// </summary>\r
202         public string AverageVideoBitrate { get; set; }\r
203 \r
204         /// <summary>\r
205         /// Gets or sets VideoTargetSize.\r
206         /// </summary>\r
207         public string VideoTargetSize { get; set; }\r
208 \r
209         /// <summary>\r
210         /// Gets or sets VideoQuality.\r
211         /// </summary>\r
212         public float VideoQuality { get; set; }\r
213         #endregion\r
214 \r
215         #region Audio Settings\r
216 \r
217         /// <summary>\r
218         /// Gets or sets AudioInformation.\r
219         /// </summary>\r
220         public ArrayList AudioInformation { get; set; }\r
221 \r
222         /// <summary>\r
223         /// Gets or sets Subtitles.\r
224         /// </summary>\r
225         public string Subtitles { get; set; }\r
226 \r
227         /// <summary>\r
228         /// Gets or sets a value indicating whether ForcedSubtitles.\r
229         /// </summary>\r
230         public bool ForcedSubtitles { get; set; }\r
231         #endregion\r
232 \r
233         #region Other\r
234         /// <summary>\r
235         /// Gets or sets a value indicating whether ChapterMarkers.\r
236         /// </summary>\r
237         public bool ChapterMarkers { get; set; }\r
238 \r
239         /// <summary>\r
240         /// Gets or sets H264Query.\r
241         /// </summary>\r
242         public string H264Query { get; set; }\r
243 \r
244         /// <summary>\r
245         /// Gets or sets a value indicating whether Verbose.\r
246         /// </summary>\r
247         public bool Verbose { get; set; }\r
248         #endregion\r
249 \r
250         #region Preset Information\r
251 \r
252         /// <summary>\r
253         /// Gets or sets PresetBuildNumber.\r
254         /// </summary>\r
255         public int PresetBuildNumber { get; set; }\r
256 \r
257         /// <summary>\r
258         /// Gets or sets PresetDescription.\r
259         /// </summary>\r
260         public string PresetDescription { get; set; }\r
261 \r
262         /// <summary>\r
263         /// Gets or sets PresetName.\r
264         /// </summary>\r
265         public string PresetName { get; set; }\r
266 \r
267         /// <summary>\r
268         /// Gets or sets Type.\r
269         /// </summary>\r
270         public string Type { get; set; }\r
271 \r
272         /// <summary>\r
273         /// Gets or sets a value indicating whether UsesMaxPictureSettings.\r
274         /// </summary>\r
275         public bool UsesMaxPictureSettings { get; set; }\r
276 \r
277         /// <summary>\r
278         /// Gets or sets a value indicating whether UsesPictureFilters.\r
279         /// </summary>\r
280         public bool UsesPictureFilters { get; set; }\r
281 \r
282         /// <summary>\r
283         /// Gets or sets a value indicating whether UsesPictureSettings.\r
284         /// </summary>\r
285         public bool UsesPictureSettings { get; set; }\r
286         #endregion\r
287 \r
288         #endregion\r
289 \r
290         /// <summary>\r
291         /// Takes in a query which can be in any order and parses it. \r
292         /// All varibles are then set so they can be used elsewhere.\r
293         /// </summary>\r
294         /// <param name="input">A ClI Query</param>\r
295         /// <returns>A Parsed Query</returns>\r
296         public static QueryParser Parse(string input)\r
297         {\r
298             var thisQuery = new QueryParser();\r
299 \r
300             #region Regular Expressions\r
301 \r
302             // Source\r
303             Match title = Regex.Match(input, @"-t ([0-9]*)");\r
304             Match chapters = Regex.Match(input, @"-c ([0-9-]*)");\r
305 \r
306             // Output Settings\r
307             Match format = Regex.Match(input, @"-f ([a-z0-9a-z0-9a-z0-9]*)");\r
308             Match grayscale = Regex.Match(input, @" -g");\r
309             Match largerMp4 = Regex.Match(input, @" -4");\r
310             Match ipodAtom = Regex.Match(input, @" -I");\r
311 \r
312             // Picture Settings Tab\r
313             Match width = Regex.Match(input, @"-w ([0-9]*)");\r
314             Match height = Regex.Match(input, @"-l ([0-9]*)");\r
315             Match maxWidth = Regex.Match(input, @"-X ([0-9]*)");\r
316             Match maxHeight = Regex.Match(input, @"-Y ([0-9]*)");\r
317             Match crop = Regex.Match(input, @"--crop ([0-9]*):([0-9]*):([0-9]*):([0-9]*)");\r
318 \r
319             Match looseAnamorphic = Regex.Match(input, @"--loose-anamorphic");\r
320             Match strictAnamorphic = Regex.Match(input, @"--strict-anamorphic");\r
321             Match customAnamorphic = Regex.Match(input, @"--custom-anamorphic");\r
322 \r
323             Match keepDisplayAsect = Regex.Match(input, @"--keep-display-aspect");\r
324             Match displayWidth = Regex.Match(input, @"--display-width ([0-9]*)");\r
325             Match pixelAspect = Regex.Match(input, @"--pixel-aspect ([0-9]*):([0-9]*)");\r
326             Match modulus = Regex.Match(input, @"--modulus ([0-9]*)");\r
327 \r
328             // Picture Settings - Filters\r
329             Match decomb = Regex.Match(input, @" --decomb");\r
330             Match decombValue = Regex.Match(input, @" --decomb=\""([a-zA-Z0-9.:]*)\""");\r
331             Match deinterlace = Regex.Match(input, @"--deinterlace=\""([a-zA-Z0-9.:]*)\""");\r
332             Match denoise = Regex.Match(input, @"--denoise=\""([a-zA-Z0-9.:]*)\""");\r
333             Match deblock = Regex.Match(input, @"--deblock=([0-9:]*)");\r
334             Match detelecine = Regex.Match(input, @"--detelecine");\r
335             Match detelecineValue = Regex.Match(input, @" --detelecine=\""([a-zA-Z0-9.:]*)\""");\r
336 \r
337             // Video Settings Tab\r
338             Match videoEncoder = Regex.Match(input, @"-e ([a-zA-Z0-9]*)");\r
339             Match videoFramerate = Regex.Match(input, @"-r ([0-9.]*)");\r
340             Match videoBitrate = Regex.Match(input, @"-b ([0-9]*)");\r
341             Match videoQuality = Regex.Match(input, @"-q ([0-9.]*)");\r
342             Match videoFilesize = Regex.Match(input, @"-S ([0-9.]*)");\r
343             Match twoPass = Regex.Match(input, @" -2");\r
344             Match turboFirstPass = Regex.Match(input, @" -T");\r
345             Match optimizeMP4 = Regex.Match(input, @" -O");\r
346 \r
347             // Audio Settings Tab\r
348             Match noAudio = Regex.Match(input, @"-a none");\r
349             Match audioTracks = Regex.Match(input, @"-a ([0-9,]*)");\r
350             Match audioTrackMixes = Regex.Match(input, @"-6 ([0-9a-zA-Z,]*)");\r
351             Match audioEncoders = Regex.Match(input, @"-E ([a-zA-Z0-9+,]*)");\r
352             Match audioBitrates = Regex.Match(input, @"-B ([0-9a-zA-Z,]*)"); // Auto = a-z\r
353             Match audioSampleRates = Regex.Match(input, @"-R ([0-9a-zA-Z.,]*)"); // Auto = a-z\r
354             Match drcValues = Regex.Match(input, @"-D ([0-9.,]*)");\r
355 \r
356             Match subtitles = Regex.Match(input, @"-s ([0-9a-zA-Z]*)");\r
357             Match subScan = Regex.Match(input, @" -U");\r
358             Match forcedSubtitles = Regex.Match(input, @" -F");\r
359 \r
360             // Chapters Tab\r
361             Match chapterMarkers = Regex.Match(input, @" -m");\r
362             Match chapterMarkersFileMode = Regex.Match(input, @"--markers");\r
363 \r
364             // H264 Tab\r
365             Match x264 = Regex.Match(input, @"-x ([.,/a-zA-Z0-9=:-]*)");\r
366 \r
367             // Program Options\r
368             Match verbose = Regex.Match(input, @" -v");\r
369 \r
370             #endregion\r
371 \r
372             #region Set Varibles\r
373 \r
374             try\r
375             {\r
376                 #region Source Tab\r
377 \r
378                 if (title.Success)\r
379                     thisQuery.Title = int.Parse(title.ToString().Replace("-t ", string.Empty));\r
380 \r
381                 if (chapters.Success)\r
382                 {\r
383                     string[] actTitles = chapters.ToString().Replace("-c ", string.Empty).Split('-');\r
384                     thisQuery.ChapterStart = int.Parse(actTitles[0]);\r
385                     if (actTitles.Length > 1)\r
386                     {\r
387                         thisQuery.ChapterFinish = int.Parse(actTitles[1]);\r
388                     }\r
389 \r
390                     if ((thisQuery.ChapterStart == 1) && (thisQuery.ChapterFinish == 0))\r
391                         thisQuery.ChapterFinish = thisQuery.ChapterStart;\r
392                 }\r
393 \r
394                 #endregion\r
395 \r
396                 #region Output Settings\r
397 \r
398                 if (format.Success)\r
399                     thisQuery.Format = format.ToString().Replace("-f ", string.Empty);\r
400                 thisQuery.LargeMP4 = largerMp4.Success;\r
401                 thisQuery.IpodAtom = ipodAtom.Success;\r
402                 thisQuery.OptimizeMP4 = optimizeMP4.Success;\r
403 \r
404                 #endregion\r
405 \r
406                 #region Picture Tab\r
407 \r
408                 if (width.Success)\r
409                     thisQuery.Width = int.Parse(width.Groups[0].Value.Replace("-w ", string.Empty));\r
410 \r
411                 if (height.Success)\r
412                     thisQuery.Height = int.Parse(height.Groups[0].Value.Replace("-l ", string.Empty));\r
413 \r
414                 if (maxWidth.Success)\r
415                     thisQuery.MaxWidth = int.Parse(maxWidth.Groups[0].Value.Replace("-X ", string.Empty));\r
416 \r
417                 if (maxHeight.Success)\r
418                     thisQuery.MaxHeight = int.Parse(maxHeight.Groups[0].Value.Replace("-Y ", string.Empty));\r
419 \r
420                 if (crop.Success)\r
421                 {\r
422                     thisQuery.CropValues = crop.ToString().Replace("--crop ", string.Empty);\r
423                     string[] actCropValues = thisQuery.CropValues.Split(':');\r
424                     thisQuery.CropTop = actCropValues[0];\r
425                     thisQuery.CropBottom = actCropValues[1];\r
426                     thisQuery.CropLeft = actCropValues[2];\r
427                     thisQuery.CropRight = actCropValues[3];\r
428                 }\r
429 \r
430                 if (strictAnamorphic.Success)\r
431                     thisQuery.AnamorphicMode = 1;\r
432                 else if (looseAnamorphic.Success)\r
433                     thisQuery.AnamorphicMode = 2;\r
434                 else if (customAnamorphic.Success)\r
435                     thisQuery.AnamorphicMode = 3;\r
436                 else\r
437                     thisQuery.AnamorphicMode = 0;\r
438 \r
439                 thisQuery.KeepDisplayAsect = keepDisplayAsect.Success;\r
440 \r
441                 if (displayWidth.Success)\r
442                     thisQuery.DisplayWidthValue =\r
443                         double.Parse(displayWidth.Groups[0].Value.Replace("--display-width ", string.Empty));\r
444 \r
445                 if (pixelAspect.Success)\r
446                     thisQuery.PixelAspectWidth = int.Parse(pixelAspect.Groups[1].Value.Replace("--pixel-aspect ", string.Empty));\r
447 \r
448                 if (pixelAspect.Success && pixelAspect.Groups.Count >= 3)\r
449                     thisQuery.PixelAspectHeight = int.Parse(pixelAspect.Groups[2].Value.Replace("--pixel-aspect ", string.Empty));\r
450 \r
451                 if (modulus.Success)\r
452                     thisQuery.AnamorphicModulus = int.Parse(modulus.Groups[0].Value.Replace("--modulus ", string.Empty));\r
453 \r
454                 #endregion\r
455 \r
456                 #region Filters\r
457 \r
458                 thisQuery.Decomb = "Off";\r
459                 if (decomb.Success)\r
460                 {\r
461                     thisQuery.Decomb = "Default";\r
462                     if (decombValue.Success)\r
463                         thisQuery.Decomb = decombValue.ToString().Replace("--decomb=", string.Empty).Replace("\"", string.Empty);\r
464                 }\r
465 \r
466                 thisQuery.DeInterlace = "Off";\r
467                 if (deinterlace.Success)\r
468                 {\r
469                     thisQuery.DeInterlace = deinterlace.ToString().Replace("--deinterlace=", string.Empty).Replace("\"", string.Empty);\r
470                     thisQuery.DeInterlace =\r
471                         thisQuery.DeInterlace.Replace("fast", "Fast").Replace("slow", "Slow").Replace("slower", "Slower");\r
472                     thisQuery.DeInterlace = thisQuery.DeInterlace.Replace("slowest", "Slowest");\r
473                 }\r
474 \r
475                 thisQuery.DeNoise = "Off";\r
476                 if (denoise.Success)\r
477                 {\r
478                     thisQuery.DeNoise = denoise.ToString().Replace("--denoise=", string.Empty).Replace("\"", string.Empty);\r
479                     thisQuery.DeNoise =\r
480                         thisQuery.DeNoise.Replace("weak", "Weak").Replace("medium", "Medium").Replace("strong", "Strong");\r
481                 }\r
482 \r
483                 string deblockValue = string.Empty;\r
484                 thisQuery.DeBlock = 0;\r
485                 if (deblock.Success)\r
486                     deblockValue = deblock.ToString().Replace("--deblock=", string.Empty);\r
487 \r
488                 int dval = 0;\r
489                 if (deblockValue != string.Empty)\r
490                     int.TryParse(deblockValue, out dval);\r
491                 thisQuery.DeBlock = dval;\r
492 \r
493                 thisQuery.DeTelecine = "Off";\r
494                 if (detelecine.Success)\r
495                 {\r
496                     thisQuery.DeTelecine = "Default";\r
497                     if (detelecineValue.Success)\r
498                         thisQuery.DeTelecine = detelecineValue.ToString().Replace("--detelecine=", string.Empty).Replace("\"", string.Empty);\r
499                 }\r
500 \r
501                 #endregion\r
502 \r
503                 #region Video Settings Tab\r
504 \r
505                 string videoEncoderConvertion = videoEncoder.ToString().Replace("-e ", string.Empty);\r
506                 switch (videoEncoderConvertion)\r
507                 {\r
508                     case "ffmpeg":\r
509                         videoEncoderConvertion = "MPEG-4 (FFmpeg)";\r
510                         break;\r
511                     case "x264":\r
512                         videoEncoderConvertion = "H.264 (x264)";\r
513                         break;\r
514                     case "theora":\r
515                         videoEncoderConvertion = "VP3 (Theora)";\r
516                         break;\r
517                     default:\r
518                         videoEncoderConvertion = "MPEG-4 (FFmpeg)";\r
519                         break;\r
520                 }\r
521                 thisQuery.VideoEncoder = videoEncoderConvertion;\r
522                 thisQuery.VideoFramerate = videoFramerate.Success\r
523                                                ? videoFramerate.ToString().Replace("-r ", string.Empty)\r
524                                                : "Same as source";\r
525                 thisQuery.Grayscale = grayscale.Success;\r
526                 thisQuery.TwoPass = twoPass.Success;\r
527                 thisQuery.TurboFirstPass = turboFirstPass.Success;\r
528 \r
529                 if (videoBitrate.Success)\r
530                     thisQuery.AverageVideoBitrate = videoBitrate.ToString().Replace("-b ", string.Empty);\r
531                 if (videoFilesize.Success)\r
532                     thisQuery.VideoTargetSize = videoFilesize.ToString().Replace("-S ", string.Empty);\r
533 \r
534                 if (videoQuality.Success)\r
535                 {\r
536                     float qConvert = float.Parse(videoQuality.ToString().Replace("-q ", string.Empty), Culture);\r
537                     thisQuery.VideoQuality = qConvert;\r
538                 }\r
539                 else\r
540                     thisQuery.VideoQuality = -1;\r
541 \r
542                 #endregion\r
543 \r
544                 #region Audio Tab\r
545 \r
546                 // Find out how many tracks we need to add by checking how many encoders or audio tracks are selected.\r
547                 int encoderCount = 0;\r
548                 if (audioEncoders.Success)\r
549                 {\r
550                     string[] audioDataCounters = audioEncoders.ToString().Replace("-E ", string.Empty).Split(',');\r
551                     encoderCount = audioDataCounters.Length;\r
552                 }\r
553 \r
554                 // Get the data from the regular expression results\r
555                 string[] trackData = null;\r
556                 string[] trackMixes = null;\r
557                 string[] trackEncoders = null;\r
558                 string[] trackBitrates = null;\r
559                 string[] trackSamplerates = null;\r
560                 string[] trackDRCvalues = null;\r
561 \r
562                 if (audioTracks.Success)\r
563                     trackData = audioTracks.ToString().Replace("-a ", string.Empty).Split(',');\r
564                 if (audioTrackMixes.Success)\r
565                     trackMixes = audioTrackMixes.ToString().Replace("-6 ", string.Empty).Split(',');\r
566                 if (audioEncoders.Success)\r
567                     trackEncoders = audioEncoders.ToString().Replace("-E ", string.Empty).Split(',');\r
568                 if (audioBitrates.Success)\r
569                     trackBitrates = audioBitrates.ToString().Replace("-B ", string.Empty).Split(',');\r
570                 if (audioSampleRates.Success)\r
571                     trackSamplerates = audioSampleRates.ToString().Replace("-R ", string.Empty).Split(',');\r
572                 if (drcValues.Success)\r
573                     trackDRCvalues = drcValues.ToString().Replace("-D ", string.Empty).Split(',');\r
574 \r
575                 // Create new Audio Track Classes and store them in the ArrayList\r
576                 ArrayList allAudioTrackInfo = new ArrayList();\r
577                 for (int x = 0; x < encoderCount; x++)\r
578                 {\r
579                     AudioTrack track = new AudioTrack();\r
580                     if (trackData != null)\r
581                         if (trackData.Length >= (x + 1)) // Audio Track\r
582                             track.Track = trackData[x].Trim();\r
583 \r
584                     if (trackMixes != null)\r
585                         if (trackMixes.Length >= (x + 1)) // Audio Mix\r
586                             track.MixDown = GetMixDown(trackMixes[x].Trim());\r
587 \r
588                     if (trackEncoders != null)\r
589                         if (trackEncoders.Length >= (x + 1)) // Audio Mix\r
590                             track.Encoder = GetAudioEncoder(trackEncoders[x].Trim());\r
591 \r
592                     if (trackBitrates != null)\r
593                         if (trackBitrates.Length >= (x + 1)) // Audio Encoder\r
594                             track.Bitrate = trackBitrates[x].Trim() == "auto" ? "Auto" : trackBitrates[x].Trim();\r
595 \r
596                     if (trackSamplerates != null)\r
597                         if (trackSamplerates.Length >= (x + 1)) // Audio SampleRate\r
598                             track.SampleRate = trackSamplerates[x].Trim() == "0" ? "Auto" : trackSamplerates[x].Trim();\r
599 \r
600                     if (trackDRCvalues != null)\r
601                         if (trackDRCvalues.Length >= (x + 1)) // Audio DRC Values\r
602                             track.DRC = trackDRCvalues[x].Trim();\r
603 \r
604                     allAudioTrackInfo.Add(track);\r
605                 }\r
606                 thisQuery.AudioInformation = allAudioTrackInfo;\r
607 \r
608                 // Subtitle Stuff\r
609                 if (subtitles.Success)\r
610                     thisQuery.Subtitles = subtitles.ToString().Replace("-s ", string.Empty);\r
611                 else\r
612                     thisQuery.Subtitles = subScan.Success ? "Autoselect" : "None";\r
613 \r
614                 thisQuery.ForcedSubtitles = forcedSubtitles.Success;\r
615 \r
616                 #endregion\r
617 \r
618                 #region Chapters Tab\r
619 \r
620                 if (chapterMarkersFileMode.Success || chapterMarkers.Success)\r
621                     thisQuery.ChapterMarkers = true;\r
622 \r
623                 #endregion\r
624 \r
625                 #region H.264 and other\r
626 \r
627                 if (x264.Success)\r
628                     thisQuery.H264Query = x264.ToString().Replace("-x ", string.Empty);\r
629 \r
630                 thisQuery.Verbose = verbose.Success;\r
631 \r
632                 #endregion\r
633             }\r
634             catch (Exception exc)\r
635             {\r
636                 MessageBox.Show("An error has occured in the Query Parser.\n\n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
637             }\r
638 \r
639             #endregion\r
640 \r
641             return thisQuery;\r
642         }\r
643 \r
644         /// <summary>\r
645         /// Get the GUI equiv to a CLI mixdown\r
646         /// </summary>\r
647         /// <param name="mixdown">The Audio Mixdown</param>\r
648         /// <returns>The GUI representation of the mixdown</returns>\r
649         private static string GetMixDown(string mixdown)\r
650         {\r
651             switch (mixdown.Trim())\r
652             {\r
653                 case "mono":\r
654                     return "Mono";\r
655                 case "stereo":\r
656                     return "Stereo";\r
657                 case "dpl1":\r
658                     return "Dolby Surround";\r
659                 case "dpl2":\r
660                     return "Dolby Pro Logic II";\r
661                 case "6ch":\r
662                     return "6 Channel Discrete";\r
663                 default:\r
664                     return "Automatic";\r
665             }\r
666         }\r
667 \r
668         /// <summary>\r
669         /// Get the GUI equiv to a CLI audio encoder\r
670         /// </summary>\r
671         /// <param name="audioEnc">The Audio Encoder</param>\r
672         /// <returns>The GUI representation of that audio encoder</returns>\r
673         private static string GetAudioEncoder(string audioEnc)\r
674         {\r
675             switch (audioEnc)\r
676             {\r
677                 case "faac":\r
678                     return "AAC (faac)";\r
679                 case "lame":\r
680                     return "MP3 (lame)";\r
681                 case "vorbis":\r
682                     return "Vorbis (vorbis)";\r
683                 case "ac3":\r
684                     return "AC3 Passthru";\r
685                 case "dts":\r
686                     return "DTS Passthru";\r
687                 default:\r
688                     return "AAC (faac)";\r
689             }\r
690         }\r
691     }\r
692 }