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
435 #region Audio Settings
\r
436 private string q_audioBitrate;
\r
438 /// Returns a string with the audio bitrate
\r
440 public string AudioBitrate
\r
444 return this.q_audioBitrate;
\r
448 private string q_audioSamplerate;
\r
450 /// Returns a string with the audio sample rate
\r
452 public string AudioSampleBitrate
\r
456 return this.q_audioSamplerate;
\r
460 private string q_audioTrack1;
\r
462 /// Returns a string with the First selected Audio track
\r
464 public string AudioTrack1
\r
468 return this.q_audioTrack1;
\r
472 private string q_audioTrack2;
\r
474 /// Returns a string with the First selected Audio track
\r
476 public string AudioTrack2
\r
480 return this.q_audioTrack2;
\r
484 private string q_audioTrackMix;
\r
486 /// Returns a string with the First selected Audio track Mix
\r
488 public string AudioTrackMix
\r
492 return this.q_audioTrackMix;
\r
496 private double q_drc;
\r
498 /// Returns a string with the selected subtitle track
\r
509 private string q_subtitles;
\r
511 /// Returns a string with the selected subtitle track
\r
513 public string Subtitles
\r
517 return this.q_subtitles;
\r
521 private Boolean q_forcedSubs;
\r
523 /// Returns a string with the selected subtitle track
\r
525 public Boolean ForcedSubtitles
\r
529 return this.q_forcedSubs;
\r
536 private string q_h264;
\r
538 /// Returns a string with the Advanced H264 query string
\r
540 public string H264Query
\r
544 return this.q_h264;
\r
547 private Boolean q_verbose;
\r
549 /// Returns a string with the Advanced H264 query string
\r
551 public Boolean Verbose
\r
555 return this.q_verbose;
\r
562 // 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
563 public static QueryParser Parse(String input)
\r
565 QueryParser thisQuery = new QueryParser();
\r
569 Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9:\\\s\.]+)(?:\"")");
\r
570 Match source = r1.Match(input.Replace('"', '\"'));
\r
571 Match title = Regex.Match(input, @"-t ([0-9]*)");
\r
572 Match chapters = Regex.Match(input, @"-c ([0-9-]*)");
\r
573 Match format = Regex.Match(input, @"-f ([a-z0-9a-z0-9a-z0-9]*)");
\r
576 Regex r2 = new Regex(@"(-o)(?:\s\"")([a-zA-Z0-9:\\\s\.]+)(?:\"")");
\r
577 Match destination = r2.Match(input.Replace('"', '\"'));
\r
578 Match width = Regex.Match(input, @"-w ([0-9]*)");
\r
579 Match height = Regex.Match(input, @"-l ([0-9]*)");
\r
580 Match videoEncoder = Regex.Match(input, @"-e ([a-zA-Z0-9]*)");
\r
581 Match audioEncoder = Regex.Match(input, @"-E ([a-zA-Z0-9]*)");
\r
583 //Picture Settings Tab
\r
584 Match deinterlace = Regex.Match(input, @"--deinterlace=([a-z]*)");
\r
585 Match denoise = Regex.Match(input, @"--denoise=([a-z]*)");
\r
586 Match deblock = Regex.Match(input, @"--deblock");
\r
587 Match detelecine = Regex.Match(input, @"--detelecine");
\r
588 Match anamorphic = Regex.Match(input, @"-p ");
\r
589 Match chapterMarkers = Regex.Match(input, @"-m");
\r
590 Match crop = Regex.Match(input, @"--crop ([0-9]):([0-9]):([0-9]):([0-9])");
\r
591 Match vfr = Regex.Match(input, @"-V");
\r
592 Match lanamorphic = Regex.Match(input, @"-P");
\r
594 //Video Settings Tab
\r
595 Match videoFramerate = Regex.Match(input, @"-r ([0-9]*)");
\r
596 Match videoBitrate = Regex.Match(input, @"-b ([0-9]*)");
\r
597 Match videoQuality = Regex.Match(input, @"-q ([0-9.]*)");
\r
598 Match videoFilesize = Regex.Match(input, @"-S ([0-9.]*)");
\r
599 Match twoPass = Regex.Match(input, @"-2");
\r
600 Match turboFirstPass = Regex.Match(input, @"-T");
\r
601 Match grayscale = Regex.Match(input, @"-g");
\r
602 Match largerMp4 = Regex.Match(input, @"-4");
\r
603 Match ipodAtom = Regex.Match(input, @"-I");
\r
604 Match optimizeMP4 = Regex.Match(input, @"-O");
\r
606 //Audio Settings Tab
\r
607 Match subtitles = Regex.Match(input, @"-s ([0-9a-zA-Z]*)");
\r
608 Match subScan = Regex.Match(input, @"-U");
\r
609 Match audioBitrate = Regex.Match(input, @"-B ([0-9]*)");
\r
610 Match audioSampleRate = Regex.Match(input, @"-R ([0-9.]*)");
\r
611 Match audioChannelsMix = Regex.Match(input, @"-6 ([0-9a-z0-9]*)"); // 1 -6 dpl2 // Broken
\r
612 Match audioTrack1 = Regex.Match(input, @"-a ([0-9]*)");
\r
613 Match audioTrack2 = Regex.Match(input, @"-a ([0-9]*),([0-9]*)");
\r
614 Match forcedSubtitles = Regex.Match(input, @"-F");
\r
615 Match drc = Regex.Match(input, @"-D ([0-9.]*)");
\r
618 Match x264 = Regex.Match(input, @"-x ([,a-zA-Z0-9=:-]*)");
\r
621 Match verbose = Regex.Match(input, @"-v");
\r
631 thisQuery.q_source = source.ToString().Replace("-i ", "").Replace("\"", "");
\r
632 if (title.Success != false)
\r
633 thisQuery.q_dvdTitle = int.Parse(title.ToString().Replace("-t ", ""));
\r
635 if (chapters.Success != false)
\r
637 string[] actTitles = new string[2];
\r
638 actTitles = chapters.ToString().Replace("-c ", "").Split('-');
\r
639 thisQuery.q_chaptersStart = int.Parse(actTitles[0]);
\r
640 if (actTitles.Length > 1)
\r
642 MessageBox.Show(actTitles[1]);
\r
643 thisQuery.q_chaptersFinish = int.Parse(actTitles[1]);
\r
646 if ((thisQuery.q_chaptersStart == 1) && (thisQuery.q_chaptersFinish == 0))
\r
647 thisQuery.q_chaptersFinish = thisQuery.q_chaptersStart;
\r
650 if (format.Success != false)
\r
651 thisQuery.q_format = format.ToString().Replace("-f ", "");
\r
658 #region Destination
\r
659 thisQuery.q_destination = destination.ToString().Replace("-o ", "").Replace("\"", "");
\r
661 string videoEncoderConvertion;
\r
662 string audioEncoderConvertion;
\r
664 videoEncoderConvertion = videoEncoder.ToString().Replace("-e ", "");
\r
665 switch (videoEncoderConvertion)
\r
668 videoEncoderConvertion = "Mpeg 4";
\r
671 videoEncoderConvertion = "Xvid";
\r
674 videoEncoderConvertion = "H.264";
\r
677 videoEncoderConvertion = "H.264 Baseline 1.3";
\r
680 videoEncoderConvertion = "H.264 (iPod)";
\r
683 videoEncoderConvertion = "Mpeg 4";
\r
686 thisQuery.q_videoEncoder = videoEncoderConvertion;
\r
688 audioEncoderConvertion = audioEncoder.ToString().Replace("-E ", "");
\r
689 switch (audioEncoderConvertion)
\r
692 audioEncoderConvertion = "AAC";
\r
695 audioEncoderConvertion = "MP3";
\r
698 audioEncoderConvertion = "Vorbis";
\r
701 audioEncoderConvertion = "AC3";
\r
704 audioEncoderConvertion = "AAC";
\r
707 thisQuery.q_audioEncoder = audioEncoderConvertion;
\r
710 if (width.Success != false)
\r
711 thisQuery.q_videoWidth = int.Parse(width.ToString().Replace("-w ", ""));
\r
713 if (height.Success != false)
\r
714 thisQuery.q_videoHeight = int.Parse(height.ToString().Replace("-l ", ""));
\r
719 //Picture Settings Tab
\r
721 #region Picture Tab
\r
722 if (crop.Success != false)
\r
724 thisQuery.q_cropValues = crop.ToString().Replace("--crop ", "");
\r
725 string[] actCropValues = new string[3];
\r
726 actCropValues = thisQuery.q_cropValues.Split(':');
\r
727 thisQuery.q_croptop = actCropValues[0];
\r
728 thisQuery.q_cropbottom = actCropValues[1];
\r
729 thisQuery.q_cropLeft = actCropValues[2];
\r
730 thisQuery.q_cropRight = actCropValues[3];
\r
733 thisQuery.q_detelecine = detelecine.Success;
\r
734 thisQuery.q_deBlock = deblock.Success;
\r
736 thisQuery.q_deinterlace = "None";
\r
737 if (deinterlace.Success != false)
\r
739 switch (deinterlace.ToString().Replace("--deinterlace=", ""))
\r
742 thisQuery.q_deinterlace = "Original (Fast)";
\r
745 thisQuery.q_deinterlace = "yadif (Slow)";
\r
748 thisQuery.q_deinterlace = "yadif + mcdeint (Slower)";
\r
751 thisQuery.q_deinterlace = "yadif + mcdeint (Slowest)";
\r
754 thisQuery.q_deinterlace = "None";
\r
759 thisQuery.q_denoise = "None";
\r
760 if (denoise.Success != false)
\r
762 switch (denoise.ToString().Replace("--denoise=", ""))
\r
765 thisQuery.q_denoise = "Weak";
\r
768 thisQuery.q_denoise = "Medium";
\r
771 thisQuery.q_denoise = "Strong";
\r
774 thisQuery.q_denoise = "None";
\r
779 thisQuery.q_anamorphic = anamorphic.Success;
\r
780 thisQuery.q_chapterMarkers = chapterMarkers.Success;
\r
781 thisQuery.q_vfr = vfr.Success;
\r
782 thisQuery.q_looseAnamorphic = lanamorphic.Success;
\r
787 //Video Settings Tab
\r
790 thisQuery.q_grayscale = grayscale.Success;
\r
791 thisQuery.q_twoPass = twoPass.Success;
\r
792 thisQuery.q_turboFirst = turboFirstPass.Success;
\r
793 thisQuery.q_largeMp4 = largerMp4.Success;
\r
794 if (videoFramerate.Success != false)
\r
795 thisQuery.q_videoFramerate = videoFramerate.ToString().Replace("-r ", "");
\r
797 thisQuery.q_videoFramerate = "Automatic";
\r
799 if (videoBitrate.Success != false)
\r
800 thisQuery.q_avgBitrate = videoBitrate.ToString().Replace("-b ", "");
\r
801 if (videoFilesize.Success != false)
\r
802 thisQuery.q_videoTargetSize = videoFilesize.ToString().Replace("-S ", "");
\r
804 double qConvert = 0;
\r
805 if (videoQuality.Success != false)
\r
807 qConvert = double.Parse(videoQuality.ToString().Replace("-q ", "")) * 100;
\r
808 qConvert = System.Math.Ceiling(qConvert);
\r
809 thisQuery.q_videoQuality = int.Parse(qConvert.ToString());
\r
811 thisQuery.q_ipodAtom = ipodAtom.Success;
\r
812 thisQuery.q_optimizeMp4 = optimizeMP4.Success;
\r
817 //Audio Settings Tab
\r
820 if (audioBitrate.Success != false)
\r
821 thisQuery.q_audioBitrate = audioBitrate.ToString().Replace("-B ", "");
\r
823 if (audioSampleRate.Success != false)
\r
824 thisQuery.q_audioSamplerate = audioSampleRate.ToString().Replace("-R ", "");
\r
826 if (audioTrack1.Success != false)
\r
827 thisQuery.q_audioTrack1 = audioTrack1.ToString().Replace("-a ", "");
\r
829 thisQuery.q_audioTrack1 = "Automatic";
\r
831 if (audioTrack2.Success != false)
\r
833 string[] audioChan = audioTrack2.ToString().Split(',');
\r
834 thisQuery.q_audioTrack2 = audioChan[1];
\r
837 thisQuery.q_audioTrack2 = "None";
\r
839 thisQuery.q_audioTrackMix = "Automatic";
\r
840 if (audioChannelsMix.Success != false)
\r
842 switch (audioChannelsMix.ToString().Replace("-6 ", "").Replace(" ", ""))
\r
845 thisQuery.q_audioTrackMix = "Mono";
\r
848 thisQuery.q_audioTrackMix = "Stereo";
\r
851 thisQuery.q_audioTrackMix = "Dolby Surround";
\r
854 thisQuery.q_audioTrackMix = "Dolby Pro Logic II";
\r
857 thisQuery.q_audioTrackMix = "6 Channel Discrete";
\r
860 thisQuery.q_audioTrackMix = "Automatic";
\r
865 if (subtitles.Success != false)
\r
866 thisQuery.q_subtitles = subtitles.ToString().Replace("-s ", "");
\r
869 if (subScan.Success)
\r
870 thisQuery.q_subtitles = "Autoselect";
\r
872 thisQuery.q_subtitles = "None";
\r
875 if (drc.Success != false)
\r
877 string value = drc.ToString().Replace("-D ", "");
\r
878 thisQuery.q_drc = double.Parse(value);
\r
882 thisQuery.q_drc = 0;
\r
885 thisQuery.q_forcedSubs = forcedSubtitles.Success;
\r
890 //H264 tab and other
\r
892 #region h264 and other
\r
896 if (x264.Success != false)
\r
898 thisQuery.q_h264 = x264.ToString().Replace("-x ", "");
\r
904 thisQuery.q_verbose = verbose.Success;
\r
907 catch (Exception exc)
\r
909 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