2 using System.Collections.Generic;
\r
4 using System.Text.RegularExpressions;
\r
5 using System.Windows.Forms;
\r
7 namespace Handbrake.Functions
\r
12 // All the Main Window GUI options
\r
16 private string q_source;
\r
18 /// Returns a String
\r
19 /// Full path of the source.
\r
21 public string Source
\r
25 return this.q_source;
\r
28 private int q_dvdTitle;
\r
30 /// Returns an Integer
\r
31 /// DVD Title number.
\r
37 return this.q_dvdTitle;
\r
41 private int q_chaptersStart;
\r
44 /// DVD Chapter number or chapter range.
\r
46 public int DVDChapterStart
\r
50 return this.q_chaptersStart;
\r
54 private int q_chaptersFinish;
\r
57 /// DVD Chapter number or chapter range.
\r
59 public int DVDChapterFinish
\r
63 return this.q_chaptersFinish;
\r
70 private string q_destination;
\r
72 /// Returns a String
\r
73 /// Full path of the destination.
\r
75 public string Destination
\r
79 return this.q_destination;
\r
83 private string q_format;
\r
85 /// Returns a String
\r
86 /// Full path of the destination.
\r
88 public string Format
\r
92 return this.q_format;
\r
96 private string q_videoEncoder;
\r
98 /// Returns an String
\r
99 /// The Video Encoder used.
\r
101 public string VideoEncoder
\r
105 return this.q_videoEncoder;
\r
109 private string q_audioEncoder;
\r
111 /// Returns an String
\r
112 /// The Audio Encoder used.
\r
114 public string AudioEncoder
\r
118 return this.q_audioEncoder;
\r
123 #region Picture Settings
\r
124 private int q_videoWidth;
\r
127 /// The selected Width for the encoding.
\r
133 return this.q_videoWidth;
\r
137 private int q_videoHeight;
\r
140 /// The selected Height for the encoding.
\r
146 return this.q_videoHeight;
\r
150 private string q_cropValues;
\r
152 /// Returns an String
\r
153 /// Cropping values.
\r
155 public string CropValues
\r
159 return this.q_cropValues;
\r
163 private string q_croptop;
\r
165 /// Returns an String
\r
166 /// Cropping values.
\r
168 public string CropTop
\r
172 return this.q_croptop;
\r
176 private string q_cropbottom;
\r
178 /// Returns an String
\r
179 /// Cropping values.
\r
181 public string CropBottom
\r
185 return this.q_cropbottom;
\r
189 private string q_cropLeft;
\r
191 /// Returns an String
\r
192 /// Cropping values.
\r
194 public string CropLeft
\r
198 return this.q_cropLeft;
\r
202 private string q_cropRight;
\r
204 /// Returns an String
\r
205 /// Cropping values.
\r
207 public string CropRight
\r
211 return this.q_cropRight;
\r
215 private Boolean q_detelecine;
\r
217 /// Returns a boolean to indicate wither DeTelecine is on or off
\r
219 public Boolean DeTelecine
\r
223 return this.q_detelecine;
\r
227 private Boolean q_vfr;
\r
229 /// Returns a boolean to indicate wither DeTelecine is on or off
\r
239 private Boolean q_deBlock;
\r
241 /// Returns a boolean to indicate wither DeBlock is on or off.
\r
243 public Boolean DeBlock
\r
247 return this.q_deBlock;
\r
251 private string q_deinterlace;
\r
253 /// Returns a string with the De-Interlace option used.
\r
255 public string DeInterlace
\r
259 return this.q_deinterlace;
\r
263 private string q_denoise;
\r
265 /// Returns a string with the DeNoise option used.
\r
267 public string DeNoise
\r
271 return this.q_denoise;
\r
275 private Boolean q_anamorphic;
\r
277 /// Returns a boolean to indicate wither Anamorphic is on or off.
\r
279 public Boolean Anamorphic
\r
283 return this.q_anamorphic;
\r
287 private Boolean q_looseAnamorphic;
\r
289 /// Returns a boolean to indicate wither Anamorphic is on or off.
\r
291 public Boolean LooseAnamorphic
\r
295 return this.q_looseAnamorphic;
\r
299 private Boolean q_chapterMarkers;
\r
301 /// Returns a boolean to indicate wither Chapter Markers is on or off.
\r
303 public Boolean ChapterMarkers
\r
307 return this.q_chapterMarkers;
\r
312 #region Video Settings
\r
313 private Boolean q_grayscale;
\r
315 /// Returns a boolean to indicate wither Grayscale is on or off.
\r
317 public Boolean Grayscale
\r
321 return this.q_grayscale;
\r
325 private Boolean q_twoPass;
\r
327 /// Returns a boolean to indicate wither Two Pass Encoding is on or off.
\r
329 public Boolean TwoPass
\r
333 return this.q_twoPass;
\r
337 private Boolean q_turboFirst;
\r
339 /// Returns a boolean to indicate wither Chapter Markers is on or off.
\r
341 public Boolean TurboFirstPass
\r
345 return this.q_turboFirst;
\r
349 private Boolean q_largeMp4;
\r
351 /// Returns a boolean to indicate wither Larger MP4 files is on or off.
\r
353 public Boolean LargeMP4
\r
357 return this.q_largeMp4;
\r
361 private Boolean q_ipodAtom;
\r
363 /// Returns a boolean to indicate wither Larger MP4 files is on or off.
\r
365 public Boolean IpodAtom
\r
369 return this.q_ipodAtom;
\r
373 private Boolean q_optimizeMp4;
\r
375 /// Returns a boolean to indicate wither Larger MP4 files is on or off.
\r
377 public Boolean OptimizeMP4
\r
381 return this.q_optimizeMp4;
\r
385 private string q_videoFramerate;
\r
387 /// Returns a string with the video Framerate
\r
389 public string VideoFramerate
\r
393 return this.q_videoFramerate;
\r
397 private string q_avgBitrate;
\r
399 /// Returns a string with the average video bitrate
\r
401 public string AverageVideoBitrate
\r
405 return this.q_avgBitrate;
\r
409 private string q_videoTargetSize;
\r
411 /// Returns a string with the video target size
\r
413 public string VideoTargetSize
\r
417 return this.q_videoTargetSize;
\r
421 private int q_videoQuality;
\r
423 /// Returns a int with the video quality value
\r
425 public int VideoQuality
\r
429 return this.q_videoQuality;
\r
433 private Boolean q_crf;
\r
435 /// Returns a boolean to indicate if CRF is on or off.
\r
446 #region Audio Settings
\r
447 private string q_audioBitrate;
\r
449 /// Returns a string with the audio bitrate
\r
451 public string AudioBitrate
\r
455 return this.q_audioBitrate;
\r
459 private string q_audioSamplerate;
\r
461 /// Returns a string with the audio sample rate
\r
463 public string AudioSampleBitrate
\r
467 return this.q_audioSamplerate;
\r
471 private string q_audioTrack1;
\r
473 /// Returns a string with the First selected Audio track
\r
475 public string AudioTrack1
\r
479 return this.q_audioTrack1;
\r
483 private string q_audioTrack2;
\r
485 /// Returns a string with the First selected Audio track
\r
487 public string AudioTrack2
\r
491 return this.q_audioTrack2;
\r
495 private string q_audioTrackMix;
\r
497 /// Returns a string with the First selected Audio track Mix
\r
499 public string AudioTrackMix
\r
503 return this.q_audioTrackMix;
\r
507 private double q_drc;
\r
509 /// Returns a string with the selected subtitle track
\r
520 private string q_subtitles;
\r
522 /// Returns a string with the selected subtitle track
\r
524 public string Subtitles
\r
528 return this.q_subtitles;
\r
532 private Boolean q_forcedSubs;
\r
534 /// Returns a string with the selected subtitle track
\r
536 public Boolean ForcedSubtitles
\r
540 return this.q_forcedSubs;
\r
547 private string q_h264;
\r
549 /// Returns a string with the Advanced H264 query string
\r
551 public string H264Query
\r
555 return this.q_h264;
\r
558 private Boolean q_verbose;
\r
560 /// Returns a string with the Advanced H264 query string
\r
562 public Boolean Verbose
\r
566 return this.q_verbose;
\r
573 // 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
574 public static QueryParser Parse(String input)
\r
576 QueryParser thisQuery = new QueryParser();
\r
580 Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9:\\\s\.]+)(?:\"")");
\r
581 Match source = r1.Match(input.Replace('"', '\"'));
\r
582 Match title = Regex.Match(input, @"-t ([0-9]*)");
\r
583 Match chapters = Regex.Match(input, @"-c ([0-9-]*)");
\r
584 Match format = Regex.Match(input, @"-f ([a-z0-9a-z0-9a-z0-9]*)");
\r
587 Regex r2 = new Regex(@"(-o)(?:\s\"")([a-zA-Z0-9:\\\s\.]+)(?:\"")");
\r
588 Match destination = r2.Match(input.Replace('"', '\"'));
\r
589 Match width = Regex.Match(input, @"-w ([0-9]*)");
\r
590 Match height = Regex.Match(input, @"-l ([0-9]*)");
\r
591 Match videoEncoder = Regex.Match(input, @"-e ([a-zA-Z0-9]*)");
\r
592 Match audioEncoder = Regex.Match(input, @"-E ([a-zA-Z0-9]*)");
\r
594 //Picture Settings Tab
\r
595 Match deinterlace = Regex.Match(input, @"--deinterlace=([a-z]*)");
\r
596 Match denoise = Regex.Match(input, @"--denoise=([a-z]*)");
\r
597 Match deblock = Regex.Match(input, @"--deblock");
\r
598 Match detelecine = Regex.Match(input, @"--detelecine");
\r
599 Match anamorphic = Regex.Match(input, @"-p ");
\r
600 Match chapterMarkers = Regex.Match(input, @"-m");
\r
601 Match crop = Regex.Match(input, @"--crop ([0-9]):([0-9]):([0-9]):([0-9])");
\r
602 Match vfr = Regex.Match(input, @"-V");
\r
603 Match lanamorphic = Regex.Match(input, @"-P");
\r
605 //Video Settings Tab
\r
606 Match videoFramerate = Regex.Match(input, @"-r ([0-9]*)");
\r
607 Match videoBitrate = Regex.Match(input, @"-b ([0-9]*)");
\r
608 Match videoQuality = Regex.Match(input, @"-q ([0-9.]*)");
\r
609 Match videoFilesize = Regex.Match(input, @"-S ([0-9.]*)");
\r
610 Match CRF = Regex.Match(input, @"-Q");
\r
611 Match twoPass = Regex.Match(input, @"-2");
\r
612 Match turboFirstPass = Regex.Match(input, @"-T");
\r
613 Match grayscale = Regex.Match(input, @"-g");
\r
614 Match largerMp4 = Regex.Match(input, @"-4");
\r
615 Match ipodAtom = Regex.Match(input, @"-I");
\r
616 Match optimizeMP4 = Regex.Match(input, @"-O");
\r
618 //Audio Settings Tab
\r
619 Match subtitles = Regex.Match(input, @"-s ([0-9a-zA-Z]*)");
\r
620 Match subScan = Regex.Match(input, @"-U");
\r
621 Match audioBitrate = Regex.Match(input, @"-B ([0-9]*)");
\r
622 Match audioSampleRate = Regex.Match(input, @"-R ([0-9.]*)");
\r
623 Match audioChannelsMix = Regex.Match(input, @"-6 ([0-9a-z0-9]*)"); // 1 -6 dpl2 // Broken
\r
624 Match audioTrack1 = Regex.Match(input, @"-a ([0-9]*)");
\r
625 Match audioTrack2 = Regex.Match(input, @"-a ([0-9]*),([0-9]*)");
\r
626 Match forcedSubtitles = Regex.Match(input, @"-F");
\r
627 Match drc = Regex.Match(input, @"-D ([0-9.]*)");
\r
630 Match x264 = Regex.Match(input, @"-x ([,a-zA-Z0-9=:-]*)");
\r
633 Match verbose = Regex.Match(input, @"-v");
\r
643 thisQuery.q_source = source.ToString().Replace("-i ", "").Replace("\"", "");
\r
644 if (title.Success != false)
\r
645 thisQuery.q_dvdTitle = int.Parse(title.ToString().Replace("-t ", ""));
\r
647 if (chapters.Success != false)
\r
649 string[] actTitles = new string[2];
\r
650 actTitles = chapters.ToString().Replace("-c ", "").Split('-');
\r
651 thisQuery.q_chaptersStart = int.Parse(actTitles[0]);
\r
652 if (actTitles.Length > 1)
\r
654 MessageBox.Show(actTitles[1]);
\r
655 thisQuery.q_chaptersFinish = int.Parse(actTitles[1]);
\r
658 if ((thisQuery.q_chaptersStart == 1) && (thisQuery.q_chaptersFinish == 0))
\r
659 thisQuery.q_chaptersFinish = thisQuery.q_chaptersStart;
\r
662 if (format.Success != false)
\r
663 thisQuery.q_format = format.ToString().Replace("-f ", "");
\r
670 #region Destination
\r
671 thisQuery.q_destination = destination.ToString().Replace("-o ", "").Replace("\"", "");
\r
673 string videoEncoderConvertion;
\r
674 string audioEncoderConvertion;
\r
676 videoEncoderConvertion = videoEncoder.ToString().Replace("-e ", "");
\r
677 switch (videoEncoderConvertion)
\r
680 videoEncoderConvertion = "Mpeg 4";
\r
683 videoEncoderConvertion = "Xvid";
\r
686 videoEncoderConvertion = "H.264";
\r
689 videoEncoderConvertion = "H.264 Baseline 1.3";
\r
692 videoEncoderConvertion = "H.264 (iPod)";
\r
695 videoEncoderConvertion = "Mpeg 4";
\r
698 thisQuery.q_videoEncoder = videoEncoderConvertion;
\r
700 audioEncoderConvertion = audioEncoder.ToString().Replace("-E ", "");
\r
701 switch (audioEncoderConvertion)
\r
704 audioEncoderConvertion = "AAC";
\r
707 audioEncoderConvertion = "MP3";
\r
710 audioEncoderConvertion = "Vorbis";
\r
713 audioEncoderConvertion = "AC3";
\r
716 audioEncoderConvertion = "AAC";
\r
719 thisQuery.q_audioEncoder = audioEncoderConvertion;
\r
722 if (width.Success != false)
\r
723 thisQuery.q_videoWidth = int.Parse(width.ToString().Replace("-w ", ""));
\r
725 if (height.Success != false)
\r
726 thisQuery.q_videoHeight = int.Parse(height.ToString().Replace("-l ", ""));
\r
731 //Picture Settings Tab
\r
733 #region Picture Tab
\r
734 if (crop.Success != false)
\r
736 thisQuery.q_cropValues = crop.ToString().Replace("--crop ", "");
\r
737 string[] actCropValues = new string[3];
\r
738 actCropValues = thisQuery.q_cropValues.Split(':');
\r
739 thisQuery.q_croptop = actCropValues[0];
\r
740 thisQuery.q_cropbottom = actCropValues[1];
\r
741 thisQuery.q_cropLeft = actCropValues[2];
\r
742 thisQuery.q_cropRight = actCropValues[3];
\r
745 thisQuery.q_detelecine = detelecine.Success;
\r
746 thisQuery.q_deBlock = deblock.Success;
\r
748 thisQuery.q_deinterlace = "None";
\r
749 if (deinterlace.Success != false)
\r
751 switch (deinterlace.ToString().Replace("--deinterlace=", ""))
\r
754 thisQuery.q_deinterlace = "Original (Fast)";
\r
757 thisQuery.q_deinterlace = "yadif (Slow)";
\r
760 thisQuery.q_deinterlace = "yadif + mcdeint (Slower)";
\r
763 thisQuery.q_deinterlace = "yadif + mcdeint (Slowest)";
\r
766 thisQuery.q_deinterlace = "None";
\r
771 thisQuery.q_denoise = "None";
\r
772 if (denoise.Success != false)
\r
774 switch (denoise.ToString().Replace("--denoise=", ""))
\r
777 thisQuery.q_denoise = "Weak";
\r
780 thisQuery.q_denoise = "Medium";
\r
783 thisQuery.q_denoise = "Strong";
\r
786 thisQuery.q_denoise = "None";
\r
791 thisQuery.q_anamorphic = anamorphic.Success;
\r
792 thisQuery.q_chapterMarkers = chapterMarkers.Success;
\r
793 thisQuery.q_vfr = vfr.Success;
\r
794 thisQuery.q_looseAnamorphic = lanamorphic.Success;
\r
799 //Video Settings Tab
\r
802 thisQuery.q_grayscale = grayscale.Success;
\r
803 thisQuery.q_twoPass = twoPass.Success;
\r
804 thisQuery.q_turboFirst = turboFirstPass.Success;
\r
805 thisQuery.q_largeMp4 = largerMp4.Success;
\r
806 if (videoFramerate.Success != false)
\r
807 thisQuery.q_videoFramerate = videoFramerate.ToString().Replace("-r ", "");
\r
809 thisQuery.q_videoFramerate = "Automatic";
\r
811 if (videoBitrate.Success != false)
\r
812 thisQuery.q_avgBitrate = videoBitrate.ToString().Replace("-b ", "");
\r
813 if (videoFilesize.Success != false)
\r
814 thisQuery.q_videoTargetSize = videoFilesize.ToString().Replace("-S ", "");
\r
816 double qConvert = 0;
\r
817 if (videoQuality.Success != false)
\r
819 qConvert = double.Parse(videoQuality.ToString().Replace("-q ", "")) * 100;
\r
820 qConvert = System.Math.Ceiling(qConvert);
\r
821 thisQuery.q_videoQuality = int.Parse(qConvert.ToString());
\r
823 thisQuery.q_crf = CRF.Success;
\r
824 thisQuery.q_ipodAtom = ipodAtom.Success;
\r
825 thisQuery.q_optimizeMp4 = optimizeMP4.Success;
\r
830 //Audio Settings Tab
\r
833 if (audioBitrate.Success != false)
\r
834 thisQuery.q_audioBitrate = audioBitrate.ToString().Replace("-B ", "");
\r
836 if (audioSampleRate.Success != false)
\r
837 thisQuery.q_audioSamplerate = audioSampleRate.ToString().Replace("-R ", "");
\r
839 if (audioTrack1.Success != false)
\r
840 thisQuery.q_audioTrack1 = audioTrack1.ToString().Replace("-a ", "");
\r
842 thisQuery.q_audioTrack1 = "Automatic";
\r
844 if (audioTrack2.Success != false)
\r
846 string[] audioChan = audioTrack2.ToString().Split(',');
\r
847 thisQuery.q_audioTrack2 = audioChan[1];
\r
850 thisQuery.q_audioTrack2 = "None";
\r
852 thisQuery.q_audioTrackMix = "Automatic";
\r
853 if (audioChannelsMix.Success != false)
\r
855 switch (audioChannelsMix.ToString().Replace("-6 ", "").Replace(" ", ""))
\r
858 thisQuery.q_audioTrackMix = "Mono";
\r
861 thisQuery.q_audioTrackMix = "Stereo";
\r
864 thisQuery.q_audioTrackMix = "Dolby Surround";
\r
867 thisQuery.q_audioTrackMix = "Dolby Pro Logic II";
\r
870 thisQuery.q_audioTrackMix = "6 Channel Discrete";
\r
873 thisQuery.q_audioTrackMix = "Automatic";
\r
878 if (subtitles.Success != false)
\r
879 thisQuery.q_subtitles = subtitles.ToString().Replace("-s ", "");
\r
882 if (subScan.Success)
\r
883 thisQuery.q_subtitles = "Autoselect";
\r
885 thisQuery.q_subtitles = "None";
\r
888 if (drc.Success != false)
\r
890 string value = drc.ToString().Replace("-D ", "");
\r
891 thisQuery.q_drc = double.Parse(value);
\r
895 thisQuery.q_drc = 0;
\r
898 thisQuery.q_forcedSubs = forcedSubtitles.Success;
\r
903 //H264 tab and other
\r
905 #region h264 and other
\r
909 if (x264.Success != false)
\r
911 thisQuery.q_h264 = x264.ToString().Replace("-x ", "");
\r
917 thisQuery.q_verbose = verbose.Success;
\r
920 catch (Exception exc)
\r
922 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