3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.m0k.org/>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.Collections.Generic;
\r
10 using System.Text.RegularExpressions;
\r
11 using System.Windows.Forms;
\r
13 namespace Handbrake.Functions
\r
18 // All the Main Window GUI options
\r
22 private string q_source;
\r
24 /// Returns a String
\r
25 /// Full path of the source.
\r
27 public string Source
\r
31 return this.q_source;
\r
34 private int q_dvdTitle;
\r
36 /// Returns an Integer
\r
37 /// DVD Title number.
\r
43 return this.q_dvdTitle;
\r
47 private int q_chaptersStart;
\r
50 /// DVD Chapter number or chapter range.
\r
52 public int DVDChapterStart
\r
56 return this.q_chaptersStart;
\r
60 private int q_chaptersFinish;
\r
63 /// DVD Chapter number or chapter range.
\r
65 public int DVDChapterFinish
\r
69 return this.q_chaptersFinish;
\r
76 private string q_destination;
\r
78 /// Returns a String
\r
79 /// Full path of the destination.
\r
81 public string Destination
\r
85 return this.q_destination;
\r
89 private string q_format;
\r
91 /// Returns a String
\r
92 /// Full path of the destination.
\r
94 public string Format
\r
98 return this.q_format;
\r
102 private string q_videoEncoder;
\r
104 /// Returns an String
\r
105 /// The Video Encoder used.
\r
107 public string VideoEncoder
\r
111 return this.q_videoEncoder;
\r
115 private string q_audioEncoder;
\r
117 /// Returns an String
\r
118 /// The Audio Encoder used.
\r
120 public string AudioEncoder
\r
124 return this.q_audioEncoder;
\r
129 #region Picture Settings
\r
130 private int q_videoWidth;
\r
133 /// The selected Width for the encoding.
\r
139 return this.q_videoWidth;
\r
143 private int q_videoHeight;
\r
146 /// The selected Height for the encoding.
\r
152 return this.q_videoHeight;
\r
156 private string q_cropValues;
\r
158 /// Returns an String
\r
159 /// Cropping values.
\r
161 public string CropValues
\r
165 return this.q_cropValues;
\r
169 private string q_croptop;
\r
171 /// Returns an String
\r
172 /// Cropping values.
\r
174 public string CropTop
\r
178 return this.q_croptop;
\r
182 private string q_cropbottom;
\r
184 /// Returns an String
\r
185 /// Cropping values.
\r
187 public string CropBottom
\r
191 return this.q_cropbottom;
\r
195 private string q_cropLeft;
\r
197 /// Returns an String
\r
198 /// Cropping values.
\r
200 public string CropLeft
\r
204 return this.q_cropLeft;
\r
208 private string q_cropRight;
\r
210 /// Returns an String
\r
211 /// Cropping values.
\r
213 public string CropRight
\r
217 return this.q_cropRight;
\r
221 private Boolean q_detelecine;
\r
223 /// Returns a boolean to indicate wither DeTelecine is on or off
\r
225 public Boolean DeTelecine
\r
229 return this.q_detelecine;
\r
233 private Boolean q_vfr;
\r
235 /// Returns a boolean to indicate wither DeTelecine is on or off
\r
245 private Boolean q_deBlock;
\r
247 /// Returns a boolean to indicate wither DeBlock is on or off.
\r
249 public Boolean DeBlock
\r
253 return this.q_deBlock;
\r
257 private string q_deinterlace;
\r
259 /// Returns a string with the De-Interlace option used.
\r
261 public string DeInterlace
\r
265 return this.q_deinterlace;
\r
269 private string q_denoise;
\r
271 /// Returns a string with the DeNoise option used.
\r
273 public string DeNoise
\r
277 return this.q_denoise;
\r
281 private Boolean q_anamorphic;
\r
283 /// Returns a boolean to indicate wither Anamorphic is on or off.
\r
285 public Boolean Anamorphic
\r
289 return this.q_anamorphic;
\r
293 private Boolean q_looseAnamorphic;
\r
295 /// Returns a boolean to indicate wither Anamorphic is on or off.
\r
297 public Boolean LooseAnamorphic
\r
301 return this.q_looseAnamorphic;
\r
305 private Boolean q_chapterMarkers;
\r
307 /// Returns a boolean to indicate wither Chapter Markers is on or off.
\r
309 public Boolean ChapterMarkers
\r
313 return this.q_chapterMarkers;
\r
318 #region Video Settings
\r
319 private Boolean q_grayscale;
\r
321 /// Returns a boolean to indicate wither Grayscale is on or off.
\r
323 public Boolean Grayscale
\r
327 return this.q_grayscale;
\r
331 private Boolean q_twoPass;
\r
333 /// Returns a boolean to indicate wither Two Pass Encoding is on or off.
\r
335 public Boolean TwoPass
\r
339 return this.q_twoPass;
\r
343 private Boolean q_turboFirst;
\r
345 /// Returns a boolean to indicate wither Chapter Markers is on or off.
\r
347 public Boolean TurboFirstPass
\r
351 return this.q_turboFirst;
\r
355 private Boolean q_largeMp4;
\r
357 /// Returns a boolean to indicate wither Larger MP4 files is on or off.
\r
359 public Boolean LargeMP4
\r
363 return this.q_largeMp4;
\r
367 private Boolean q_ipodAtom;
\r
369 /// Returns a boolean to indicate wither Larger MP4 files is on or off.
\r
371 public Boolean IpodAtom
\r
375 return this.q_ipodAtom;
\r
379 private Boolean q_optimizeMp4;
\r
381 /// Returns a boolean to indicate wither Larger MP4 files is on or off.
\r
383 public Boolean OptimizeMP4
\r
387 return this.q_optimizeMp4;
\r
391 private string q_videoFramerate;
\r
393 /// Returns a string with the video Framerate
\r
395 public string VideoFramerate
\r
399 return this.q_videoFramerate;
\r
403 private string q_avgBitrate;
\r
405 /// Returns a string with the average video bitrate
\r
407 public string AverageVideoBitrate
\r
411 return this.q_avgBitrate;
\r
415 private string q_videoTargetSize;
\r
417 /// Returns a string with the video target size
\r
419 public string VideoTargetSize
\r
423 return this.q_videoTargetSize;
\r
427 private int q_videoQuality;
\r
429 /// Returns a int with the video quality value
\r
431 public int VideoQuality
\r
435 return this.q_videoQuality;
\r
441 #region Audio Settings
\r
442 private string q_audioBitrate;
\r
444 /// Returns a string with the audio bitrate
\r
446 public string AudioBitrate
\r
450 return this.q_audioBitrate;
\r
454 private string q_audioSamplerate;
\r
456 /// Returns a string with the audio sample rate
\r
458 public string AudioSampleBitrate
\r
462 return this.q_audioSamplerate;
\r
466 private string q_audioTrack1;
\r
468 /// Returns a string with the First selected Audio track
\r
470 public string AudioTrack1
\r
474 return this.q_audioTrack1;
\r
478 private string q_audioTrack2;
\r
480 /// Returns a string with the First selected Audio track
\r
482 public string AudioTrack2
\r
486 return this.q_audioTrack2;
\r
490 private string q_audioTrackMix;
\r
492 /// Returns a string with the First selected Audio track Mix
\r
494 public string AudioTrackMix
\r
498 return this.q_audioTrackMix;
\r
502 private double q_drc;
\r
504 /// Returns a string with the selected subtitle track
\r
515 private string q_subtitles;
\r
517 /// Returns a string with the selected subtitle track
\r
519 public string Subtitles
\r
523 return this.q_subtitles;
\r
527 private Boolean q_forcedSubs;
\r
529 /// Returns a string with the selected subtitle track
\r
531 public Boolean ForcedSubtitles
\r
535 return this.q_forcedSubs;
\r
542 private string q_h264;
\r
544 /// Returns a string with the Advanced H264 query string
\r
546 public string H264Query
\r
550 return this.q_h264;
\r
553 private Boolean q_verbose;
\r
555 /// Returns a string with the Advanced H264 query string
\r
557 public Boolean Verbose
\r
561 return this.q_verbose;
\r
568 // Takes in a query which can be in any order and parses it. All varibles are then set so they can be used elsewhere.
\r
569 public static QueryParser Parse(String input)
\r
571 QueryParser thisQuery = new QueryParser();
\r
575 Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9:\\\s\.]+)(?:\"")");
\r
576 Match source = r1.Match(input.Replace('"', '\"'));
\r
577 Match title = Regex.Match(input, @"-t ([0-9]*)");
\r
578 Match chapters = Regex.Match(input, @"-c ([0-9-]*)");
\r
579 Match format = Regex.Match(input, @"-f ([a-z0-9a-z0-9a-z0-9]*)");
\r
582 Regex r2 = new Regex(@"(-o)(?:\s\"")([a-zA-Z0-9_\-:\\\s\.]+)(?:\"")");
\r
583 Match destination = r2.Match(input.Replace('"', '\"'));
\r
584 Match width = Regex.Match(input, @"-w ([0-9]*)");
\r
585 Match height = Regex.Match(input, @"-l ([0-9]*)");
\r
586 Match videoEncoder = Regex.Match(input, @"-e ([a-zA-Z0-9]*)");
\r
587 Match audioEncoder = Regex.Match(input, @"-E ([a-zA-Z0-9+]*)");
\r
589 //Picture Settings Tab
\r
590 Match deinterlace = Regex.Match(input, @"--deinterlace=([a-z]*)");
\r
591 Match denoise = Regex.Match(input, @"--denoise=([a-z]*)");
\r
592 Match deblock = Regex.Match(input, @"--deblock");
\r
593 Match detelecine = Regex.Match(input, @"--detelecine");
\r
594 Match anamorphic = Regex.Match(input, @"-p ");
\r
595 Match chapterMarkers = Regex.Match(input, @"-m");
\r
596 Match crop = Regex.Match(input, @"--crop ([0-9]):([0-9]):([0-9]):([0-9])");
\r
597 Match vfr = Regex.Match(input, @"-V");
\r
598 Match lanamorphic = Regex.Match(input, @"-P");
\r
600 //Video Settings Tab
\r
601 Match videoFramerate = Regex.Match(input, @"-r ([0-9]*)");
\r
602 Match videoBitrate = Regex.Match(input, @"-b ([0-9]*)");
\r
603 Match videoQuality = Regex.Match(input, @"-q ([0-9.]*)");
\r
604 Match videoFilesize = Regex.Match(input, @"-S ([0-9.]*)");
\r
605 Match twoPass = Regex.Match(input, @"-2");
\r
606 Match turboFirstPass = Regex.Match(input, @"-T");
\r
607 Match grayscale = Regex.Match(input, @"-g");
\r
608 Match largerMp4 = Regex.Match(input, @"-4");
\r
609 Match ipodAtom = Regex.Match(input, @"-I");
\r
610 Match optimizeMP4 = Regex.Match(input, @"-O");
\r
612 //Audio Settings Tab
\r
613 Match subtitles = Regex.Match(input, @"-s ([0-9a-zA-Z]*)");
\r
614 Match subScan = Regex.Match(input, @"-U");
\r
615 Match audioBitrate = Regex.Match(input, @"-B ([0-9]*)");
\r
616 Match audioSampleRate = Regex.Match(input, @"-R ([0-9.]*)");
\r
617 Match audioChannelsMix = Regex.Match(input, @"-6 ([0-9a-z0-9]*)"); // 1 -6 dpl2 // Broken
\r
618 Match audioTrack1 = Regex.Match(input, @"-a ([0-9]*)");
\r
619 Match audioTrack2 = Regex.Match(input, @"-a ([0-9]*),([0-9]*)");
\r
620 Match forcedSubtitles = Regex.Match(input, @"-F");
\r
621 Match drc = Regex.Match(input, @"-D ([0-9.]*)");
\r
624 Match x264 = Regex.Match(input, @"-x ([,a-zA-Z0-9=:-]*)");
\r
627 Match verbose = Regex.Match(input, @"-v");
\r
637 thisQuery.q_source = source.ToString().Replace("-i ", "").Replace("\"", "");
\r
638 if (title.Success != false)
\r
639 thisQuery.q_dvdTitle = int.Parse(title.ToString().Replace("-t ", ""));
\r
641 if (chapters.Success != false)
\r
643 string[] actTitles = new string[2];
\r
644 actTitles = chapters.ToString().Replace("-c ", "").Split('-');
\r
645 thisQuery.q_chaptersStart = int.Parse(actTitles[0]);
\r
646 if (actTitles.Length > 1)
\r
648 thisQuery.q_chaptersFinish = int.Parse(actTitles[1]);
\r
651 if ((thisQuery.q_chaptersStart == 1) && (thisQuery.q_chaptersFinish == 0))
\r
652 thisQuery.q_chaptersFinish = thisQuery.q_chaptersStart;
\r
655 if (format.Success != false)
\r
656 thisQuery.q_format = format.ToString().Replace("-f ", "");
\r
663 #region Destination
\r
664 thisQuery.q_destination = destination.ToString().Replace("-o ", "").Replace("\"", "");
\r
666 string videoEncoderConvertion;
\r
667 string audioEncoderConvertion;
\r
669 videoEncoderConvertion = videoEncoder.ToString().Replace("-e ", "");
\r
670 switch (videoEncoderConvertion)
\r
673 videoEncoderConvertion = "Mpeg 4";
\r
676 videoEncoderConvertion = "Xvid";
\r
679 videoEncoderConvertion = "H.264";
\r
682 videoEncoderConvertion = "H.264 Baseline 1.3";
\r
685 videoEncoderConvertion = "H.264 (iPod)";
\r
688 videoEncoderConvertion = "Mpeg 4";
\r
691 thisQuery.q_videoEncoder = videoEncoderConvertion;
\r
693 audioEncoderConvertion = audioEncoder.ToString().Replace("-E ", "");
\r
694 switch (audioEncoderConvertion)
\r
697 audioEncoderConvertion = "AAC";
\r
700 audioEncoderConvertion = "MP3";
\r
703 audioEncoderConvertion = "Vorbis";
\r
706 audioEncoderConvertion = "AC3";
\r
709 audioEncoderConvertion = "AAC + AC3";
\r
712 audioEncoderConvertion = "AAC";
\r
715 thisQuery.q_audioEncoder = audioEncoderConvertion;
\r
718 if (width.Success != false)
\r
719 thisQuery.q_videoWidth = int.Parse(width.ToString().Replace("-w ", ""));
\r
721 if (height.Success != false)
\r
722 thisQuery.q_videoHeight = int.Parse(height.ToString().Replace("-l ", ""));
\r
727 //Picture Settings Tab
\r
729 #region Picture Tab
\r
730 if (crop.Success != false)
\r
732 thisQuery.q_cropValues = crop.ToString().Replace("--crop ", "");
\r
733 string[] actCropValues = new string[3];
\r
734 actCropValues = thisQuery.q_cropValues.Split(':');
\r
735 thisQuery.q_croptop = actCropValues[0];
\r
736 thisQuery.q_cropbottom = actCropValues[1];
\r
737 thisQuery.q_cropLeft = actCropValues[2];
\r
738 thisQuery.q_cropRight = actCropValues[3];
\r
741 thisQuery.q_detelecine = detelecine.Success;
\r
742 thisQuery.q_deBlock = deblock.Success;
\r
744 thisQuery.q_deinterlace = "None";
\r
745 if (deinterlace.Success != false)
\r
747 switch (deinterlace.ToString().Replace("--deinterlace=", ""))
\r
750 thisQuery.q_deinterlace = "Fast";
\r
753 thisQuery.q_deinterlace = "Slow";
\r
756 thisQuery.q_deinterlace = "Slower";
\r
759 thisQuery.q_deinterlace = "Slowest";
\r
762 thisQuery.q_deinterlace = "None";
\r
767 thisQuery.q_denoise = "None";
\r
768 if (denoise.Success != false)
\r
770 switch (denoise.ToString().Replace("--denoise=", ""))
\r
773 thisQuery.q_denoise = "Weak";
\r
776 thisQuery.q_denoise = "Medium";
\r
779 thisQuery.q_denoise = "Strong";
\r
782 thisQuery.q_denoise = "None";
\r
787 thisQuery.q_anamorphic = anamorphic.Success;
\r
788 thisQuery.q_chapterMarkers = chapterMarkers.Success;
\r
789 thisQuery.q_vfr = vfr.Success;
\r
790 thisQuery.q_looseAnamorphic = lanamorphic.Success;
\r
795 //Video Settings Tab
\r
798 thisQuery.q_grayscale = grayscale.Success;
\r
799 thisQuery.q_twoPass = twoPass.Success;
\r
800 thisQuery.q_turboFirst = turboFirstPass.Success;
\r
801 thisQuery.q_largeMp4 = largerMp4.Success;
\r
802 if (videoFramerate.Success != false)
\r
803 thisQuery.q_videoFramerate = videoFramerate.ToString().Replace("-r ", "");
\r
805 thisQuery.q_videoFramerate = "Automatic";
\r
807 if (videoBitrate.Success != false)
\r
808 thisQuery.q_avgBitrate = videoBitrate.ToString().Replace("-b ", "");
\r
809 if (videoFilesize.Success != false)
\r
810 thisQuery.q_videoTargetSize = videoFilesize.ToString().Replace("-S ", "");
\r
812 double qConvert = 0;
\r
813 if (videoQuality.Success != false)
\r
815 qConvert = double.Parse(videoQuality.ToString().Replace("-q ", ""), Functions.CLI.Culture) * 100;
\r
816 qConvert = System.Math.Ceiling(qConvert);
\r
817 thisQuery.q_videoQuality = int.Parse(qConvert.ToString());
\r
819 thisQuery.q_ipodAtom = ipodAtom.Success;
\r
820 thisQuery.q_optimizeMp4 = optimizeMP4.Success;
\r
825 //Audio Settings Tab
\r
828 if (audioBitrate.Success != false)
\r
829 thisQuery.q_audioBitrate = audioBitrate.ToString().Replace("-B ", "");
\r
831 if (audioSampleRate.Success != false)
\r
832 thisQuery.q_audioSamplerate = audioSampleRate.ToString().Replace("-R ", "");
\r
834 if (audioTrack1.Success != false)
\r
835 thisQuery.q_audioTrack1 = audioTrack1.ToString().Replace("-a ", "");
\r
837 thisQuery.q_audioTrack1 = "Automatic";
\r
839 if (audioTrack2.Success != false)
\r
841 string[] audioChan = audioTrack2.ToString().Split(',');
\r
842 thisQuery.q_audioTrack2 = audioChan[1];
\r
845 thisQuery.q_audioTrack2 = "None";
\r
847 thisQuery.q_audioTrackMix = "Automatic";
\r
848 if (audioChannelsMix.Success != false)
\r
850 switch (audioChannelsMix.ToString().Replace("-6 ", "").Replace(" ", ""))
\r
853 thisQuery.q_audioTrackMix = "Mono";
\r
856 thisQuery.q_audioTrackMix = "Stereo";
\r
859 thisQuery.q_audioTrackMix = "Dolby Surround";
\r
862 thisQuery.q_audioTrackMix = "Dolby Pro Logic II";
\r
865 thisQuery.q_audioTrackMix = "6 Channel Discrete";
\r
868 thisQuery.q_audioTrackMix = "Automatic";
\r
873 if (subtitles.Success != false)
\r
874 thisQuery.q_subtitles = subtitles.ToString().Replace("-s ", "");
\r
877 if (subScan.Success)
\r
878 thisQuery.q_subtitles = "Autoselect";
\r
880 thisQuery.q_subtitles = "None";
\r
883 if (drc.Success != false)
\r
885 string value = drc.ToString().Replace("-D ", "");
\r
886 float drcValue = float.Parse(value);
\r
887 drcValue = drcValue * 10;
\r
888 thisQuery.q_drc = drcValue;
\r
892 thisQuery.q_drc = 0;
\r
895 thisQuery.q_forcedSubs = forcedSubtitles.Success;
\r
900 //H264 tab and other
\r
902 #region h264 and other
\r
906 if (x264.Success != false)
\r
908 thisQuery.q_h264 = x264.ToString().Replace("-x ", "");
\r
914 thisQuery.q_verbose = verbose.Success;
\r
917 catch (Exception exc)
\r
919 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