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