OSDN Git Service

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