OSDN Git Service

import jp-0.9.3
[handbrake-jp/handbrake-jp.git] / win / C# / Functions / QueryParser.cs
1 /*  QueryParser.cs $\r
2         \r
3            This file is part of the HandBrake source code.\r
4            Homepage: <http://handbrake.fr>.\r
5            It may be used under the terms of the GNU General Public License. */\r
6 \r
7 using System;\r
8 using System.Collections.Generic;\r
9 using System.Text;\r
10 using System.Text.RegularExpressions;\r
11 using System.Windows.Forms;\r
12 \r
13 namespace Handbrake.Functions\r
14 {\r
15     class QueryParser\r
16     {\r
17 \r
18         // All the Main Window GUI options\r
19         #region Varibles\r
20 \r
21         #region Source\r
22 \r
23         private string q_source;\r
24         /// <summary>\r
25         /// Returns a String \r
26         /// Full path of the source.\r
27         /// </summary>\r
28         public string Source\r
29         {\r
30             get\r
31             {\r
32                 return this.q_source;\r
33             }\r
34         }\r
35 \r
36         private int q_dvdTitle;\r
37         /// <summary>\r
38         /// Returns an Integer\r
39         /// DVD Title number.\r
40         /// </summary>\r
41         public int DVDTitle\r
42         {\r
43             get\r
44             {\r
45                 return this.q_dvdTitle;\r
46             }\r
47         }\r
48 \r
49         private int q_chaptersStart;\r
50         /// <summary>\r
51         /// Returns an Int\r
52         /// DVD Chapter number or chapter range.\r
53         /// </summary>\r
54         public int DVDChapterStart\r
55         {\r
56             get\r
57             {\r
58                 return this.q_chaptersStart;\r
59             }\r
60         }\r
61 \r
62         private int q_chaptersFinish;\r
63         /// <summary>\r
64         /// Returns an Int\r
65         /// DVD Chapter number or chapter range.\r
66         /// </summary>\r
67         public int DVDChapterFinish\r
68         {\r
69             get\r
70             {\r
71                 return this.q_chaptersFinish;\r
72             }\r
73         }\r
74 #endregion\r
75 \r
76         #region Destination\r
77 \r
78         private string q_destination;\r
79         /// <summary>\r
80         /// Returns a String \r
81         /// Full path of the destination.\r
82         /// </summary>\r
83         public string Destination\r
84         {\r
85             get\r
86             {\r
87                 return this.q_destination;\r
88             }\r
89         }\r
90 \r
91         private string q_format;\r
92         /// <summary>\r
93         /// Returns a String \r
94         /// Full path of the destination.\r
95         /// </summary>\r
96         public string Format\r
97         {\r
98             get\r
99             {\r
100                 return this.q_format;\r
101             }\r
102         }\r
103 \r
104         private string q_videoEncoder;\r
105         /// <summary>\r
106         /// Returns an String\r
107         /// The Video Encoder used.\r
108         /// </summary>\r
109         public string VideoEncoder\r
110         {\r
111             get\r
112             {\r
113                 return this.q_videoEncoder;\r
114             }\r
115         }\r
116         #endregion\r
117 \r
118         #region Picture Settings\r
119         private int q_videoWidth;\r
120         /// <summary>\r
121         /// Returns an Int\r
122         /// The selected Width for the encoding.\r
123         /// </summary>\r
124         public int Width\r
125         {\r
126             get\r
127             {\r
128                 return this.q_videoWidth;\r
129             }\r
130         }\r
131 \r
132         private int q_videoHeight;\r
133         /// <summary>\r
134         /// Returns an Int\r
135         /// The selected Height for the encoding.\r
136         /// </summary>\r
137         public int Height\r
138         {\r
139             get\r
140             {\r
141                 return this.q_videoHeight;\r
142             }\r
143         }\r
144 \r
145         private int q_maxWidth;\r
146         /// <summary>\r
147         /// Returns an Int\r
148         /// The selected Width for the encoding.\r
149         /// </summary>\r
150         public int MaxWidth\r
151         {\r
152             get\r
153             {\r
154                 return this.q_maxWidth;\r
155             }\r
156         }\r
157 \r
158         private int q_maxHeight;\r
159         /// <summary>\r
160         /// Returns an Int\r
161         /// The selected Height for the encoding.\r
162         /// </summary>\r
163         public int MaxHeight\r
164         {\r
165             get\r
166             {\r
167                 return this.q_maxHeight;\r
168             }\r
169         }\r
170 \r
171         private string q_cropValues;\r
172         /// <summary>\r
173         /// Returns an String\r
174         /// Cropping values.\r
175         /// </summary>\r
176         public string CropValues\r
177         {\r
178             get\r
179             {\r
180                 return this.q_cropValues;\r
181             }\r
182         }\r
183 \r
184         private string q_croptop;\r
185         /// <summary>\r
186         /// Returns an String\r
187         /// Cropping values.\r
188         /// </summary>\r
189         public string CropTop\r
190         {\r
191             get\r
192             {\r
193                 return this.q_croptop;\r
194             }\r
195         }\r
196 \r
197         private string q_cropbottom;\r
198         /// <summary>\r
199         /// Returns an String\r
200         /// Cropping values.\r
201         /// </summary>\r
202         public string CropBottom\r
203         {\r
204             get\r
205             {\r
206                 return this.q_cropbottom;\r
207             }\r
208         }\r
209 \r
210         private string q_cropLeft;\r
211         /// <summary>\r
212         /// Returns an String\r
213         /// Cropping values.\r
214         /// </summary>\r
215         public string CropLeft\r
216         {\r
217             get\r
218             {\r
219                 return this.q_cropLeft;\r
220             }\r
221         }\r
222 \r
223         private string q_cropRight;\r
224         /// <summary>\r
225         /// Returns an String\r
226         /// Cropping values.\r
227         /// </summary>\r
228         public string CropRight\r
229         {\r
230             get\r
231             {\r
232                 return this.q_cropRight;\r
233             }\r
234         }\r
235 \r
236         private Boolean q_detelecine;\r
237         /// <summary>\r
238         /// Returns a boolean to indicate wither DeTelecine is on or off\r
239         /// </summary>\r
240         public Boolean DeTelecine\r
241         {\r
242             get\r
243             {\r
244                 return this.q_detelecine;\r
245             }\r
246         }\r
247 \r
248         private int q_deBlock;\r
249         /// <summary>\r
250         /// Returns a boolean to indicate wither DeBlock is on or off.\r
251         /// </summary>\r
252         public int DeBlock\r
253         {\r
254             get\r
255             {\r
256                 return this.q_deBlock;\r
257             }\r
258         }\r
259 \r
260         private string q_deinterlace;\r
261         /// <summary>\r
262         /// Returns a string with the De-Interlace option used.\r
263         /// </summary>\r
264         public string DeInterlace\r
265         {\r
266             get\r
267             {\r
268                 return this.q_deinterlace;\r
269             }\r
270         }\r
271 \r
272         private string q_denoise;\r
273         /// <summary>\r
274         /// Returns a string with the DeNoise option used.\r
275         /// </summary>\r
276         public string DeNoise\r
277         {\r
278             get\r
279             {\r
280                 return this.q_denoise;\r
281             }\r
282         }\r
283 \r
284         private Boolean q_decomb;\r
285         /// <summary>\r
286         /// Returns a string with the DeNoise option used.\r
287         /// </summary>\r
288         public Boolean Decomb\r
289         {\r
290             get\r
291             {\r
292                 return this.q_decomb;\r
293             }\r
294         }\r
295 \r
296         private Boolean q_anamorphic;\r
297         /// <summary>\r
298         /// Returns a boolean to indicate wither Anamorphic is on or off.\r
299         /// </summary>\r
300         public Boolean Anamorphic\r
301         {\r
302             get\r
303             {\r
304                 return this.q_anamorphic;\r
305             }\r
306         }\r
307 \r
308         private Boolean q_looseAnamorphic;\r
309         /// <summary>\r
310         /// Returns a boolean to indicate wither Anamorphic is on or off.\r
311         /// </summary>\r
312         public Boolean LooseAnamorphic\r
313         {\r
314             get\r
315             {\r
316                 return this.q_looseAnamorphic;\r
317             }\r
318         }\r
319 \r
320         private Boolean q_chapterMarkers;\r
321         /// <summary>\r
322         /// Returns a boolean to indicate wither Chapter Markers is on or off.\r
323         /// </summary>\r
324         public Boolean ChapterMarkers\r
325         {\r
326             get\r
327             {\r
328                 return this.q_chapterMarkers;\r
329             }\r
330         }\r
331         #endregion\r
332 \r
333         #region Video Settings\r
334         private Boolean q_grayscale;\r
335         /// <summary>\r
336         /// Returns a boolean to indicate wither Grayscale is on or off.\r
337         /// </summary>\r
338         public Boolean Grayscale\r
339         {\r
340             get\r
341             {\r
342                 return this.q_grayscale;\r
343             }\r
344         }\r
345 \r
346         private Boolean q_twoPass;\r
347         /// <summary>\r
348         /// Returns a boolean to indicate wither Two Pass Encoding is on or off.\r
349         /// </summary>\r
350         public Boolean TwoPass\r
351         {\r
352             get\r
353             {\r
354                 return this.q_twoPass;\r
355             }\r
356         }\r
357 \r
358         private Boolean q_turboFirst;\r
359         /// <summary>\r
360         /// Returns a boolean to indicate wither Chapter Markers is on or off.\r
361         /// </summary>\r
362         public Boolean TurboFirstPass\r
363         {\r
364             get\r
365             {\r
366                 return this.q_turboFirst;\r
367             }\r
368         }\r
369 \r
370         private Boolean q_largeMp4;\r
371         /// <summary>\r
372         /// Returns a boolean to indicate wither Larger MP4 files is on or off.\r
373         /// </summary>\r
374         public Boolean LargeMP4\r
375         {\r
376             get\r
377             {\r
378                 return this.q_largeMp4;\r
379             }\r
380         }\r
381 \r
382         private Boolean q_ipodAtom;\r
383         /// <summary>\r
384         /// Returns a boolean to indicate wither Larger MP4 files is on or off.\r
385         /// </summary>\r
386         public Boolean IpodAtom\r
387         {\r
388             get\r
389             {\r
390                 return this.q_ipodAtom;\r
391             }\r
392         }\r
393 \r
394         private Boolean q_optimizeMp4;\r
395         /// <summary>\r
396         /// Returns a boolean to indicate wither Larger MP4 files is on or off.\r
397         /// </summary>\r
398         public Boolean OptimizeMP4\r
399         {\r
400             get\r
401             {\r
402                 return this.q_optimizeMp4;\r
403             }\r
404         }\r
405 \r
406         private string q_videoFramerate;\r
407         /// <summary>\r
408         /// Returns a string with the video Framerate\r
409         /// </summary>\r
410         public string VideoFramerate\r
411         {\r
412             get\r
413             {\r
414                 return this.q_videoFramerate;\r
415             }\r
416         }\r
417 \r
418         private string q_avgBitrate;\r
419         /// <summary>\r
420         /// Returns a string with the average video bitrate\r
421         /// </summary>\r
422         public string AverageVideoBitrate\r
423         {\r
424             get\r
425             {\r
426                 return this.q_avgBitrate;\r
427             }\r
428         }\r
429 \r
430         private string q_videoTargetSize;\r
431         /// <summary>\r
432         /// Returns a string with the video target size\r
433         /// </summary>\r
434         public string VideoTargetSize\r
435         {\r
436             get\r
437             {\r
438                 return this.q_videoTargetSize;\r
439             }\r
440         }\r
441 \r
442         private int q_videoQuality;\r
443         /// <summary>\r
444         /// Returns a int with the video quality value\r
445         /// </summary>\r
446         public int VideoQuality\r
447         {\r
448             get\r
449             {\r
450                 return this.q_videoQuality;\r
451             }\r
452         }\r
453 \r
454         #endregion\r
455 \r
456         #region Audio Settings\r
457         private string q_audioTrack1;\r
458         /// <summary>\r
459         /// Returns a string with the selected Audio track\r
460         /// </summary>\r
461         public string AudioTrack1\r
462         {\r
463             get\r
464             {\r
465                 return this.q_audioTrack1;\r
466             }\r
467         }\r
468 \r
469         private string q_audioTrack2;\r
470         /// <summary>\r
471         /// Returns a string with the selected Audio track\r
472         /// </summary>\r
473         public string AudioTrack2\r
474         {\r
475             get\r
476             {\r
477                 return this.q_audioTrack2;\r
478             }\r
479         }\r
480 \r
481         private string q_audioTrack3;\r
482         /// <summary>\r
483         /// Returns a string with the selected Audio track\r
484         /// </summary>\r
485         public string AudioTrack3\r
486         {\r
487             get\r
488             {\r
489                 return this.q_audioTrack3;\r
490             }\r
491         }\r
492 \r
493         private string q_audioTrack4;\r
494         /// <summary>\r
495         /// Returns a string with the selected Audio track\r
496         /// </summary>\r
497         public string AudioTrack4\r
498         {\r
499             get\r
500             {\r
501                 return this.q_audioTrack4;\r
502             }\r
503         }\r
504 \r
505         private string q_audioTrackMix1;\r
506         /// <summary>\r
507         /// Returns a string with the First selected Audio track Mix\r
508         /// </summary>\r
509         public string AudioTrackMix1\r
510         {\r
511             get\r
512             {\r
513                 return this.q_audioTrackMix1;\r
514             }\r
515         }\r
516 \r
517         private string q_audioTrackMix2;\r
518         /// <summary>\r
519         /// Returns a string with the First selected Audio track Mix\r
520         /// </summary>\r
521         public string AudioTrackMix2\r
522         {\r
523             get\r
524             {\r
525                 return this.q_audioTrackMix2;\r
526             }\r
527         }\r
528 \r
529         private string q_audioTrackMix3;\r
530         /// <summary>\r
531         /// Returns a string with the First selected Audio track Mix\r
532         /// </summary>\r
533         public string AudioTrackMix3\r
534         {\r
535             get\r
536             {\r
537                 return this.q_audioTrackMix3;\r
538             }\r
539         }\r
540 \r
541         private string q_audioTrackMix4;\r
542         /// <summary>\r
543         /// Returns a string with the First selected Audio track Mix\r
544         /// </summary>\r
545         public string AudioTrackMix4\r
546         {\r
547             get\r
548             {\r
549                 return this.q_audioTrackMix4;\r
550             }\r
551         }\r
552 \r
553         private string q_audioEncoder1;\r
554         /// <summary>\r
555         /// Returns an String\r
556         /// The Audio Encoder used.\r
557         /// </summary>\r
558         public string AudioEncoder1\r
559         {\r
560             get\r
561             {\r
562                 return this.q_audioEncoder1;\r
563             }\r
564         }\r
565 \r
566         private string q_audioEncoder2;\r
567         /// <summary>\r
568         /// Returns an String\r
569         /// The Audio Encoder used.\r
570         /// </summary>\r
571         public string AudioEncoder2\r
572         {\r
573             get\r
574             {\r
575                 return this.q_audioEncoder2;\r
576             }\r
577         }\r
578 \r
579         private string q_audioEncoder3;\r
580         /// <summary>\r
581         /// Returns an String\r
582         /// The Audio Encoder used.\r
583         /// </summary>\r
584         public string AudioEncoder3\r
585         {\r
586             get\r
587             {\r
588                 return this.q_audioEncoder3;\r
589             }\r
590         }\r
591 \r
592         private string q_audioEncoder4;\r
593         /// <summary>\r
594         /// Returns an String\r
595         /// The Audio Encoder used.\r
596         /// </summary>\r
597         public string AudioEncoder4\r
598         {\r
599             get\r
600             {\r
601                 return this.q_audioEncoder4;\r
602             }\r
603         }\r
604 \r
605         private string q_audioBitrate1;\r
606         /// <summary>\r
607         /// Returns a string with the audio bitrate\r
608         /// </summary>\r
609         public string AudioBitrate1\r
610         {\r
611             get\r
612             {\r
613                 return this.q_audioBitrate1;\r
614             }\r
615         }\r
616 \r
617         private string q_audioBitrate2;\r
618         /// <summary>\r
619         /// Returns a string with the audio bitrate\r
620         /// </summary>\r
621         public string AudioBitrate2\r
622         {\r
623             get\r
624             {\r
625                 return this.q_audioBitrate2;\r
626             }\r
627         }\r
628 \r
629         private string q_audioBitrate3;\r
630         /// <summary>\r
631         /// Returns a string with the audio bitrate\r
632         /// </summary>\r
633         public string AudioBitrate3\r
634         {\r
635             get\r
636             {\r
637                 return this.q_audioBitrate3;\r
638             }\r
639         }\r
640 \r
641         private string q_audioBitrate4;\r
642         /// <summary>\r
643         /// Returns a string with the audio bitrate\r
644         /// </summary>\r
645         public string AudioBitrate4\r
646         {\r
647             get\r
648             {\r
649                 return this.q_audioBitrate4;\r
650             }\r
651         }\r
652 \r
653         private string q_audioSamplerate1;\r
654         /// <summary>\r
655         /// Returns a string with the audio sample rate\r
656         /// </summary>\r
657         public string AudioSamplerate1\r
658         {\r
659             get\r
660             {\r
661                 return this.q_audioSamplerate1;\r
662             }\r
663         }\r
664 \r
665         private string q_audioSamplerate2;\r
666         /// <summary>\r
667         /// Returns a string with the audio sample rate\r
668         /// </summary>\r
669         public string AudioSamplerate2\r
670         {\r
671             get\r
672             {\r
673                 return this.q_audioSamplerate2;\r
674             }\r
675         }\r
676 \r
677         private string q_audioSamplerate3;\r
678         /// <summary>\r
679         /// Returns a string with the audio sample rate\r
680         /// </summary>\r
681         public string AudioSamplerate3\r
682         {\r
683             get\r
684             {\r
685                 return this.q_audioSamplerate3;\r
686             }\r
687         }\r
688 \r
689         private string q_audioSamplerate4;\r
690         /// <summary>\r
691         /// Returns a string with the audio sample rate\r
692         /// </summary>\r
693         public string AudioSamplerate4\r
694         {\r
695             get\r
696             {\r
697                 return this.q_audioSamplerate4;\r
698             }\r
699         }\r
700 \r
701         private double q_drc1;\r
702         /// <summary>\r
703         /// Returns a string with the selected subtitle track\r
704         /// </summary>\r
705         public double DRC1\r
706         {\r
707             get\r
708             {\r
709                 return this.q_drc1;\r
710             }\r
711         }\r
712 \r
713         private double q_drc2;\r
714         /// <summary>\r
715         /// Returns a string with the selected subtitle track\r
716         /// </summary>\r
717         public double DRC2\r
718         {\r
719             get\r
720             {\r
721                 return this.q_drc2;\r
722             }\r
723         }\r
724 \r
725         private double q_drc3;\r
726         /// <summary>\r
727         /// Returns a string with the selected subtitle track\r
728         /// </summary>\r
729         public double DRC3\r
730         {\r
731             get\r
732             {\r
733                 return this.q_drc3;\r
734             }\r
735         }\r
736 \r
737         private double q_drc4;\r
738         /// <summary>\r
739         /// Returns a string with the selected subtitle track\r
740         /// </summary>\r
741         public double DRC4\r
742         {\r
743             get\r
744             {\r
745                 return this.q_drc4;\r
746             }\r
747         }\r
748 \r
749         private string q_subtitles;\r
750         /// <summary>\r
751         /// Returns a string with the selected subtitle track\r
752         /// </summary>\r
753         public string Subtitles\r
754         {\r
755             get\r
756             {\r
757                 return this.q_subtitles;\r
758             }\r
759         }\r
760 \r
761         private Boolean q_forcedSubs;\r
762         /// <summary>\r
763         /// Returns a string with the selected subtitle track\r
764         /// </summary>\r
765         public Boolean ForcedSubtitles\r
766         {\r
767             get\r
768             {\r
769                 return this.q_forcedSubs;\r
770             }\r
771         }\r
772 \r
773         #endregion\r
774 \r
775         #region Other\r
776         private string q_h264;\r
777         /// <summary>\r
778         /// Returns a string with the Advanced H264 query string\r
779         /// </summary>\r
780         public string H264Query\r
781         {\r
782             get\r
783             {\r
784                 return this.q_h264;\r
785             }\r
786         }\r
787         private Boolean q_verbose;\r
788         /// <summary>\r
789         /// Returns a string with the Advanced H264 query string\r
790         /// </summary>\r
791         public Boolean Verbose\r
792         {\r
793             get\r
794             {\r
795                 return this.q_verbose;\r
796             }\r
797         }\r
798         #endregion\r
799 \r
800         #endregion\r
801 \r
802         /// <summary>\r
803         /// Takes in a query which can be in any order and parses it. \r
804         /// All varibles are then set so they can be used elsewhere.\r
805         /// </summary>\r
806         /// <param name="input">A ClI Query</param>\r
807         /// <returns>A Parsed Query</returns>\r
808  \r
809         public static QueryParser Parse(String input)\r
810         {\r
811             QueryParser thisQuery = new QueryParser();\r
812 \r
813             #region Regular Expressions\r
814             //Source\r
815             Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9_\-:\\\s\.]+)(?:\"")");\r
816             Match source = r1.Match(input.Replace('"', '\"'));\r
817             Match title = Regex.Match(input, @"-t ([0-9]*)");\r
818             Match chapters = Regex.Match(input, @"-c ([0-9-]*)");\r
819             Match format = Regex.Match(input, @"-f ([a-z0-9a-z0-9a-z0-9]*)");\r
820 \r
821             //Destination\r
822             Regex r2 = new Regex(@"(-o)(?:\s\"")([a-zA-Z0-9_\-:\\\s\.]+)(?:\"")");\r
823             Match destination = r2.Match(input.Replace('"', '\"'));\r
824             Match videoEncoder = Regex.Match(input, @"-e ([a-zA-Z0-9]*)");\r
825 \r
826             //Picture Settings Tab\r
827             Match width = Regex.Match(input, @"-w ([0-9]*)");\r
828             Match height = Regex.Match(input, @"-l ([0-9]*)");\r
829             Match maxWidth = Regex.Match(input, @"-X ([0-9]*)");\r
830             Match maxHeight = Regex.Match(input, @"-Y ([0-9]*)");\r
831             Match deinterlace = Regex.Match(input, @"--deinterlace=\""([a-zA-Z]*)\""");\r
832             Match denoise = Regex.Match(input, @"--denoise=\""([a-zA-Z]*)\""");\r
833             Match deblock = Regex.Match(input, @"--deblock=([0-9]*)");\r
834             Match detelecine = Regex.Match(input, @"--detelecine");\r
835             Match anamorphic = Regex.Match(input, @" -p ");\r
836             Match chapterMarkers = Regex.Match(input, @" -m");\r
837             Match chapterMarkersFileMode = Regex.Match(input, @"--markers");\r
838             Match crop = Regex.Match(input, @"--crop ([0-9]*):([0-9]*):([0-9]*):([0-9]*)");\r
839             Match lanamorphic = Regex.Match(input, @" -P");\r
840             Match decomb = Regex.Match(input, @" --decomb");\r
841 \r
842             //Video Settings Tab\r
843             Match videoFramerate = Regex.Match(input, @"-r ([0-9]*)");\r
844             Match videoBitrate = Regex.Match(input, @"-b ([0-9]*)");\r
845             Match videoQuality = Regex.Match(input, @"-q ([0-9.]*)");\r
846             Match videoFilesize = Regex.Match(input, @"-S ([0-9.]*)");\r
847             Match twoPass = Regex.Match(input, @" -2");\r
848             Match turboFirstPass = Regex.Match(input, @" -T");\r
849             Match grayscale = Regex.Match(input, @" -g");\r
850             Match largerMp4 = Regex.Match(input, @" -4");\r
851             Match ipodAtom = Regex.Match(input, @" -I");\r
852             Match optimizeMP4 = Regex.Match(input, @" -O");\r
853 \r
854             //Audio Settings Tab\r
855             Match audioTrack1 = Regex.Match(input, @"-a ([0-9]*)");\r
856             Match audioTrack2 = Regex.Match(input, @"-a ([0-9]*),([0-9]*)");\r
857             Match audioTrack3 = Regex.Match(input, @"-a ([0-9]*),([0-9]*),([0-9]*)");\r
858             Match audioTrack4 = Regex.Match(input, @"-a ([0-9]*),([0-9]*),([0-9]*),([0-9]*)");\r
859 \r
860             Match audioTrack1Mix = Regex.Match(input, @"-6 ([0-9a-z0-9]*)");  \r
861             Match audioTrack2Mix = Regex.Match(input, @"-6 ([0-9a-z0-9]*),([0-9a-z0-9]*)");\r
862             Match audioTrack3Mix = Regex.Match(input, @"-6 ([0-9a-z0-9]*),([0-9a-z0-9]*),([0-9a-z0-9]*)");\r
863             Match audioTrack4Mix = Regex.Match(input, @"-6 ([0-9a-z0-9]*),([0-9a-z0-9]*),([0-9a-z0-9]*),([0-9a-z0-9]*)"); \r
864 \r
865             Match audioEncoder1 = Regex.Match(input, @"-E ([a-zA-Z0-9+]*)");\r
866             Match audioEncoder2 = Regex.Match(input, @"-E ([a-zA-Z0-9+]*),([a-zA-Z0-9+]*)");\r
867             Match audioEncoder3 = Regex.Match(input, @"-E ([a-zA-Z0-9+]*),([a-zA-Z0-9+]*),([a-zA-Z0-9+]*)");\r
868             Match audioEncoder4 = Regex.Match(input, @"-E ([a-zA-Z0-9+]*),([a-zA-Z0-9+]*),([a-zA-Z0-9+]*),([a-zA-Z0-9+]*)");\r
869 \r
870             Match audioBitrate1 = Regex.Match(input, @"-B ([0-9]*)");\r
871             Match audioBitrate2 = Regex.Match(input, @"-B ([0-9]*),([0-9]*)");\r
872             Match audioBitrate3 = Regex.Match(input, @"-B ([0-9]*),([0-9]*),([0-9]*)");\r
873             Match audioBitrate4 = Regex.Match(input, @"-B ([0-9]*),([0-9]*),([0-9]*),([0-9]*)");\r
874 \r
875             Match audioSampleRate1 = Regex.Match(input, @"-R ([0-9.]*)");\r
876             Match audioSampleRate2 = Regex.Match(input, @"-R ([0-9.]*),([0-9.]*)");\r
877             Match audioSampleRate3 = Regex.Match(input, @"-R ([0-9.]*),([0-9.]*),([0-9.]*)");\r
878             Match audioSampleRate4 = Regex.Match(input, @"-R ([0-9.]*),([0-9.]*),([0-9.]*),([0-9.]*)");\r
879 \r
880             Match drc1 = Regex.Match(input, @"-D ([0-9.]*)");\r
881             Match drc2 = Regex.Match(input, @"-D ([0-9.]*),([0-9.]*)");\r
882             Match drc3 = Regex.Match(input, @"-D ([0-9.]*),([0-9.]*),([0-9.]*)");\r
883             Match drc4 = Regex.Match(input, @"-D ([0-9.]*),([0-9.]*),([0-9.]*),([0-9.]*)");\r
884 \r
885             Match subtitles = Regex.Match(input, @"-s ([0-9a-zA-Z]*)");\r
886             Match subScan = Regex.Match(input, @" -U");\r
887             Match forcedSubtitles = Regex.Match(input, @" -F");\r
888 \r
889             //H264 Tab\r
890             Match x264 = Regex.Match(input, @"-x ([.,/a-zA-Z0-9=:-]*)");\r
891 \r
892             //Program Options\r
893             Match verbose = Regex.Match(input, @" -v");\r
894             #endregion\r
895 \r
896             #region Set Varibles\r
897             try\r
898             {\r
899       \r
900                 #region Source Tab\r
901 \r
902                 thisQuery.q_source = source.ToString().Replace("-i ", "").Replace("\"", "");\r
903                 if (title.Success != false)\r
904                     thisQuery.q_dvdTitle = int.Parse(title.ToString().Replace("-t ", ""));\r
905 \r
906                 if (chapters.Success != false)\r
907                 {\r
908                     string[] actTitles = new string[2];\r
909                     actTitles = chapters.ToString().Replace("-c ", "").Split('-');\r
910                     thisQuery.q_chaptersStart = int.Parse(actTitles[0]);\r
911                     if (actTitles.Length > 1)\r
912                     {\r
913                         thisQuery.q_chaptersFinish = int.Parse(actTitles[1]);\r
914                     }\r
915 \r
916                     if ((thisQuery.q_chaptersStart == 1) && (thisQuery.q_chaptersFinish == 0))\r
917                         thisQuery.q_chaptersFinish = thisQuery.q_chaptersStart;\r
918                 }\r
919 \r
920                 if (format.Success != false)\r
921                     thisQuery.q_format = format.ToString().Replace("-f ", "");\r
922 \r
923                 #endregion\r
924 \r
925                 #region Destination\r
926                 thisQuery.q_destination = destination.ToString().Replace("-o ", "").Replace("\"", "");\r
927 \r
928                 string videoEncoderConvertion;\r
929 \r
930                 videoEncoderConvertion = videoEncoder.ToString().Replace("-e ", "");\r
931                 switch (videoEncoderConvertion)\r
932                 {\r
933                     case "ffmpeg":\r
934                         videoEncoderConvertion = "MPEG-4 (FFmpeg)";\r
935                         break;\r
936                     case "xvid":\r
937                         videoEncoderConvertion = "MPEG-4 (XviD)";\r
938                         break;\r
939                     case "x264":\r
940                         videoEncoderConvertion = "H.264 (x264)";\r
941                         break;\r
942                     case "theora":\r
943                         videoEncoderConvertion = "VP3 (Theora)";\r
944                         break;\r
945                     default:\r
946                         videoEncoderConvertion = "MPEG-4 (FFmpeg)";\r
947                         break;\r
948                 }\r
949                 thisQuery.q_videoEncoder = videoEncoderConvertion;\r
950 \r
951                 #endregion\r
952 \r
953                 #region Picture Tab\r
954 \r
955                 if (width.Success != false)\r
956                     thisQuery.q_videoWidth = int.Parse(width.ToString().Replace("-w ", ""));\r
957 \r
958                 if (height.Success != false)\r
959                     thisQuery.q_videoHeight = int.Parse(height.ToString().Replace("-l ", ""));\r
960 \r
961                 if (maxWidth.Success != false)\r
962                     thisQuery.q_maxWidth = int.Parse(maxWidth.ToString().Replace("-X ", ""));\r
963 \r
964                 if (maxHeight.Success != false)\r
965                     thisQuery.q_maxHeight = int.Parse(maxHeight.ToString().Replace("-Y ", ""));\r
966 \r
967                 if (crop.Success != false)\r
968                 {\r
969                     thisQuery.q_cropValues = crop.ToString().Replace("--crop ", "");\r
970                     string[] actCropValues = new string[3];\r
971                     actCropValues = thisQuery.q_cropValues.Split(':');\r
972                     thisQuery.q_croptop = actCropValues[0];\r
973                     thisQuery.q_cropbottom = actCropValues[1];\r
974                     thisQuery.q_cropLeft = actCropValues[2];\r
975                     thisQuery.q_cropRight = actCropValues[3];\r
976                 }\r
977 \r
978                 // Deblock Slider\r
979                 string deblockValue = "";\r
980                 thisQuery.q_deBlock = 0;\r
981                 if (deblock.Success != false)\r
982                     deblockValue = deblock.ToString().Replace("--deblock=", "");\r
983 \r
984                 if (deblockValue != "")\r
985                     int.TryParse(deblockValue, out thisQuery.q_deBlock);\r
986 \r
987                 thisQuery.q_detelecine = detelecine.Success;\r
988                 thisQuery.q_decomb = decomb.Success;\r
989 \r
990                 thisQuery.q_deinterlace = "None";\r
991                 if (deinterlace.Success != false)\r
992                 {\r
993                     switch (deinterlace.ToString().Replace("--deinterlace=", "").Replace("\"",""))\r
994                     {\r
995                         case "fast":\r
996                             thisQuery.q_deinterlace = "Fast";\r
997                             break;\r
998                         case "slow":\r
999                             thisQuery.q_deinterlace = "Slow";\r
1000                             break;\r
1001                         case "slower":\r
1002                             thisQuery.q_deinterlace = "Slower";\r
1003                             break;\r
1004                         case "slowest":\r
1005                             thisQuery.q_deinterlace = "Slowest";\r
1006                             break;\r
1007                         default:\r
1008                             thisQuery.q_deinterlace = "None";\r
1009                             break;\r
1010                     }\r
1011                 }\r
1012 \r
1013                 thisQuery.q_denoise = "None";\r
1014                 if (denoise.Success != false)\r
1015                 {\r
1016                     switch (denoise.ToString().Replace("--denoise=", "").Replace("\"", ""))\r
1017                     {\r
1018                         case "weak":\r
1019                             thisQuery.q_denoise = "Weak";\r
1020                             break;\r
1021                         case "medium":\r
1022                             thisQuery.q_denoise = "Medium";\r
1023                             break;\r
1024                         case "strong":\r
1025                             thisQuery.q_denoise = "Strong";\r
1026                             break;\r
1027                         default:\r
1028                             thisQuery.q_denoise = "None";\r
1029                             break;\r
1030                     }\r
1031 \r
1032                 }\r
1033                 thisQuery.q_anamorphic = anamorphic.Success;\r
1034                 if (chapterMarkersFileMode.Success == true || chapterMarkers.Success == true)\r
1035                     thisQuery.q_chapterMarkers = true;\r
1036                 \r
1037                 thisQuery.q_looseAnamorphic = lanamorphic.Success;\r
1038 \r
1039                 #endregion\r
1040      \r
1041                 #region Video Settings Tab\r
1042                 thisQuery.q_grayscale = grayscale.Success;\r
1043                 thisQuery.q_twoPass = twoPass.Success;\r
1044                 thisQuery.q_turboFirst = turboFirstPass.Success;\r
1045                 thisQuery.q_largeMp4 = largerMp4.Success;\r
1046                 if (videoFramerate.Success != false)\r
1047                     thisQuery.q_videoFramerate = videoFramerate.ToString().Replace("-r ", "");\r
1048                 else\r
1049                     thisQuery.q_videoFramerate = "Same as source";\r
1050 \r
1051                 if (videoBitrate.Success != false)\r
1052                     thisQuery.q_avgBitrate = videoBitrate.ToString().Replace("-b ", "");\r
1053                 if (videoFilesize.Success != false)\r
1054                     thisQuery.q_videoTargetSize = videoFilesize.ToString().Replace("-S ", "");\r
1055 \r
1056                 double qConvert = 0;\r
1057                 if (videoQuality.Success != false)\r
1058                 {\r
1059                     qConvert = double.Parse(videoQuality.ToString().Replace("-q ", ""), Functions.Encode.Culture) * 100;\r
1060                     qConvert = System.Math.Ceiling(qConvert);\r
1061                     thisQuery.q_videoQuality = int.Parse(qConvert.ToString());\r
1062                 }\r
1063                 thisQuery.q_ipodAtom = ipodAtom.Success;\r
1064                 thisQuery.q_optimizeMp4 = optimizeMP4.Success;\r
1065 \r
1066                 #endregion\r
1067 \r
1068                 #region Audio Tab\r
1069 \r
1070                 // Tracks\r
1071                 if (audioTrack1.Success != false)\r
1072                     thisQuery.q_audioTrack1 = audioTrack1.ToString().Replace("-a ", "");\r
1073                 else\r
1074                     thisQuery.q_audioTrack1 = "Automatic";\r
1075 \r
1076                 if (audioTrack2.Success != false)\r
1077                 {\r
1078                     string[] audioChan = audioTrack2.ToString().Split(',');\r
1079                     thisQuery.q_audioTrack2 = audioChan[1];\r
1080                 }\r
1081                 else\r
1082                     thisQuery.q_audioTrack2 = "None";\r
1083 \r
1084                 if (audioTrack3.Success != false)\r
1085                 {\r
1086                     string[] audioChan = audioTrack3.ToString().Split(',');\r
1087                     thisQuery.q_audioTrack3 = audioChan[2];\r
1088                 }\r
1089                 else\r
1090                     thisQuery.q_audioTrack3 = "None";\r
1091 \r
1092                 if (audioTrack4.Success != false)\r
1093                 {\r
1094                     string[] audioChan = audioTrack4.ToString().Split(',');\r
1095                     thisQuery.q_audioTrack4 = audioChan[3];\r
1096                 }\r
1097                 else\r
1098                     thisQuery.q_audioTrack4 = "None";\r
1099 \r
1100     \r
1101                 // Mixdowns\r
1102                 thisQuery.q_audioTrackMix1 = "Automatic";\r
1103                 if (audioTrack1Mix.Success != false)\r
1104                 {\r
1105                     thisQuery.q_audioTrackMix1 = getMixDown(audioTrack1Mix.ToString().Replace("-6 ", "").Replace(" ", ""));\r
1106                 }\r
1107 \r
1108                 thisQuery.q_audioTrackMix2 = "Automatic";\r
1109                 if (audioTrack2Mix.Success != false)\r
1110                 {\r
1111                     string[] audio2mix = audioTrack2Mix.ToString().Split(',');\r
1112                     audio2mix[1] = audio2mix[1].Trim();\r
1113                     thisQuery.q_audioTrackMix2 = getMixDown(audio2mix[1]);\r
1114                 }\r
1115 \r
1116                 thisQuery.q_audioTrackMix3 = "Automatic";\r
1117                 if (audioTrack3Mix.Success != false)\r
1118                 {\r
1119                     string[] audio3mix = audioTrack3Mix.ToString().Split(',');\r
1120                     audio3mix[1] = audio3mix[2].Trim();\r
1121                     thisQuery.q_audioTrackMix3 = getMixDown(audio3mix[1]);\r
1122                 }\r
1123 \r
1124                 thisQuery.q_audioTrackMix4 = "Automatic";\r
1125                 if (audioTrack4Mix.Success != false)\r
1126                 {\r
1127                     string[] audio4mix = audioTrack4Mix.ToString().Split(',');\r
1128                     audio4mix[1] = audio4mix[3].Trim();\r
1129                     thisQuery.q_audioTrackMix4 = getMixDown(audio4mix[1]);\r
1130                 }\r
1131                 \r
1132 \r
1133                 // Audio Encoders\r
1134                 if (audioEncoder1.Success != false)\r
1135                     thisQuery.q_audioEncoder1 = getAudioEncoder(audioEncoder1.ToString().Replace("-E ", ""));\r
1136 \r
1137                 if (audioEncoder2.Success != false)\r
1138                 {\r
1139                     string[] audio2enc = audioEncoder2.ToString().Split(',');\r
1140                     thisQuery.q_audioEncoder2 = getAudioEncoder(audio2enc[1].Trim());\r
1141                 }\r
1142 \r
1143                 if (audioEncoder3.Success != false)\r
1144                 {\r
1145                     string[] audio3enc = audioEncoder3.ToString().Split(',');\r
1146                     thisQuery.q_audioEncoder3 = getAudioEncoder(audio3enc[2].Trim());\r
1147                 }\r
1148 \r
1149                 if (audioEncoder4.Success != false)\r
1150                 {\r
1151                     string[] audio4enc = audioEncoder4.ToString().Split(',');\r
1152                     thisQuery.q_audioEncoder4 = getAudioEncoder(audio4enc[3].Trim());\r
1153                 }\r
1154 \r
1155 \r
1156                 // Audio Bitrate\r
1157                 if (audioBitrate1.Success != false)\r
1158                     thisQuery.q_audioBitrate1 = audioBitrate1.ToString().Replace("-B ", "").Trim();\r
1159                 else\r
1160                     thisQuery.q_audioBitrate1 = "";\r
1161 \r
1162                 if (audioBitrate2.Success != false)\r
1163                 {\r
1164                     string[] audioBitrateSelect = audioBitrate2.ToString().Split(',');\r
1165                     thisQuery.q_audioBitrate2 = audioBitrateSelect[1].Trim();\r
1166                 }\r
1167                 else\r
1168                     thisQuery.q_audioBitrate2 = "";\r
1169 \r
1170                 if (audioBitrate3.Success != false)\r
1171                 {\r
1172                     string[] audioBitrateSelect = audioBitrate3.ToString().Split(',');\r
1173                     thisQuery.q_audioBitrate3 = audioBitrateSelect[2].Trim();\r
1174                 }\r
1175                 else\r
1176                     thisQuery.q_audioBitrate3 = "";\r
1177 \r
1178                 if (audioBitrate4.Success != false)\r
1179                 {\r
1180                     string[] audioBitrateSelect = audioBitrate4.ToString().Split(',');\r
1181                     thisQuery.q_audioBitrate4 = audioBitrateSelect[3].Trim();\r
1182                 }\r
1183                 else\r
1184                     thisQuery.q_audioBitrate4 = "";\r
1185 \r
1186 \r
1187                 // Audio Sample Rate\r
1188                 // Make sure to change 0 to Auto\r
1189                 if (audioSampleRate1.Success != false)\r
1190                 {\r
1191                     thisQuery.q_audioSamplerate1 = audioSampleRate1.ToString().Replace("-R ", "").Trim();\r
1192                     if (thisQuery.q_audioSamplerate1 == "0")\r
1193                         thisQuery.q_audioSamplerate1 = "Auto";\r
1194                 }\r
1195                 else\r
1196                     thisQuery.q_audioSamplerate1 = "Auto";\r
1197 \r
1198                 if (audioSampleRate2.Success != false)\r
1199                 {\r
1200                     string[] audioSRSelect = audioSampleRate2.ToString().Split(',');\r
1201                     if (audioSRSelect[1] == "0")\r
1202                         audioSRSelect[1] = "Auto";\r
1203                     thisQuery.q_audioSamplerate2 = audioSRSelect[1].Trim();\r
1204                 }\r
1205 \r
1206                 if (audioSampleRate3.Success != false)\r
1207                 {\r
1208                     string[] audioSRSelect = audioSampleRate3.ToString().Split(',');\r
1209                     if (audioSRSelect[1] == "0")\r
1210                         audioSRSelect[1] = "Auto";\r
1211                     thisQuery.q_audioSamplerate3 = audioSRSelect[2].Trim();\r
1212                 }\r
1213 \r
1214                 if (audioSampleRate4.Success != false)\r
1215                 {\r
1216                     string[] audioSRSelect = audioSampleRate4.ToString().Split(',');\r
1217                     if (audioSRSelect[1] == "0")\r
1218                         audioSRSelect[1] = "Auto";\r
1219                     thisQuery.q_audioSamplerate4 = audioSRSelect[3].Trim();\r
1220                 }\r
1221 \r
1222                 // DRC\r
1223                 if (drc1.Success != false)\r
1224                 {\r
1225                     string value = drc1.ToString().Replace("-D ", "");\r
1226                     float drcValue = float.Parse(value);\r
1227                     drcValue = drcValue * 10;\r
1228                     thisQuery.q_drc1 = drcValue;\r
1229                 }\r
1230                 else\r
1231                     thisQuery.q_drc1 = 10;\r
1232 \r
1233                 if (drc2.Success != false)\r
1234                 {\r
1235                     string[] drcPoint = drc2.ToString().Split(',');\r
1236                     string value = drcPoint[1];\r
1237                     float drcValue = float.Parse(value);\r
1238                     drcValue = drcValue * 10;\r
1239                     thisQuery.q_drc2 = drcValue;\r
1240                 }\r
1241                 else\r
1242                     thisQuery.q_drc2 = 10;\r
1243 \r
1244                 if (drc3.Success != false)\r
1245                 {\r
1246                     string[] drcPoint = drc3.ToString().Split(',');\r
1247                     string value = drcPoint[2];\r
1248                     float drcValue = float.Parse(value);\r
1249                     drcValue = drcValue * 10;\r
1250                     thisQuery.q_drc3 = drcValue;\r
1251                 }\r
1252                 else\r
1253                     thisQuery.q_drc3 = 10;\r
1254 \r
1255                 if (drc4.Success != false)\r
1256                 {\r
1257                     string[] drcPoint = drc4.ToString().Split(',');\r
1258                     string value = drcPoint[3];\r
1259                     float drcValue = float.Parse(value);\r
1260                     drcValue = drcValue * 10;\r
1261                     thisQuery.q_drc4 = drcValue;\r
1262                 }\r
1263                 else\r
1264                     thisQuery.q_drc4 = 10;\r
1265 \r
1266 \r
1267                 // Subtitle Stuff\r
1268                 if (subtitles.Success != false)\r
1269                     thisQuery.q_subtitles = subtitles.ToString().Replace("-s ", "");\r
1270                 else\r
1271                 {\r
1272                     if (subScan.Success)\r
1273                         thisQuery.q_subtitles = "Autoselect";\r
1274                     else\r
1275                         thisQuery.q_subtitles = "None";\r
1276                 }\r
1277 \r
1278                 thisQuery.q_forcedSubs = forcedSubtitles.Success;\r
1279 \r
1280                 #endregion\r
1281 \r
1282                 #region H.264 and other\r
1283                 //\r
1284                 //H264 Tab\r
1285                 //\r
1286                 if (x264.Success != false)\r
1287                     thisQuery.q_h264 = x264.ToString().Replace("-x ", "");\r
1288 \r
1289                 //\r
1290                 //Progam Options\r
1291                 //\r
1292                 thisQuery.q_verbose = verbose.Success;\r
1293                 #endregion\r
1294             }\r
1295             catch (Exception exc)\r
1296             {\r
1297                 MessageBox.Show("An error has occured in the Query Parser. Please report this error on the forum in the 'Windows' support section. \n\n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
1298             }\r
1299             #endregion\r
1300 \r
1301             return thisQuery;\r
1302         }\r
1303 \r
1304         private static string getMixDown(string mixdown)\r
1305         {\r
1306             switch (mixdown)\r
1307             {\r
1308                 case "mono":\r
1309                     return "Mono";\r
1310                 case "stereo":\r
1311                     return "Stereo";\r
1312                 case "dpl1":\r
1313                     return "Dolby Surround";\r
1314                 case "dpl2":\r
1315                     return "Dolby Pro Logic II";\r
1316                 case "6ch":\r
1317                     return "6 Channel Discrete";\r
1318                 default:\r
1319                     return "Automatic";\r
1320             }\r
1321         }\r
1322         private static string getAudioEncoder(string audioEnc)\r
1323         {\r
1324             switch (audioEnc)\r
1325             {\r
1326                 case "faac":\r
1327                     return "AAC";\r
1328                 case "lame":\r
1329                     return "MP3";\r
1330                 case "vorbis":\r
1331                     return "Vorbis";\r
1332                 case "ac3":\r
1333                     return "AC3";\r
1334                 default:\r
1335                     return "AAC";\r
1336             }\r
1337         }\r
1338     }\r
1339 }