--- /dev/null
+using System;\r
+using System.Collections.Generic;\r
+using System.Text;\r
+using System.Text.RegularExpressions;\r
+using System.Windows.Forms;\r
+\r
+namespace Handbrake.Functions\r
+{\r
+ class QueryParser\r
+ {\r
+\r
+ // All the Main Window GUI options\r
+ #region Varibles\r
+ \r
+ private string q_source;\r
+ /// <summary>\r
+ /// Returns a String \r
+ /// Full path of the source.\r
+ /// </summary>\r
+ public string Source\r
+ {\r
+ get\r
+ {\r
+ return this.q_source;\r
+ }\r
+ }\r
+\r
+ private string q_destination;\r
+ /// <summary>\r
+ /// Returns a String \r
+ /// Full path of the destination.\r
+ /// </summary>\r
+ public string Destination\r
+ {\r
+ get\r
+ {\r
+ return this.q_destination;\r
+ }\r
+ }\r
+\r
+ private int q_dvdTitle;\r
+ /// <summary>\r
+ /// Returns an Integer\r
+ /// DVD Title number.\r
+ /// </summary>\r
+ public int DVDTitle\r
+ {\r
+ get\r
+ {\r
+ return this.q_dvdTitle;\r
+ }\r
+ }\r
+\r
+ private string q_dvdChapters;\r
+ /// <summary>\r
+ /// Returns an String\r
+ /// DVD Chapter number or chapter range.\r
+ /// </summary>\r
+ public string DVDChapters\r
+ {\r
+ get\r
+ {\r
+ return this.q_dvdChapters;\r
+ }\r
+ }\r
+\r
+ private string q_videoEncoder;\r
+ /// <summary>\r
+ /// Returns an String\r
+ /// The Video Encoder used.\r
+ /// </summary>\r
+ public string VideoEncoder\r
+ {\r
+ get\r
+ {\r
+ return this.q_videoEncoder;\r
+ }\r
+ }\r
+\r
+ private string q_audioEncoder;\r
+ /// <summary>\r
+ /// Returns an String\r
+ /// The Audio Encoder used.\r
+ /// </summary>\r
+ public string AudioEncoder\r
+ {\r
+ get\r
+ {\r
+ return this.q_audioEncoder;\r
+ }\r
+ }\r
+\r
+ private int q_videoWidth;\r
+ /// <summary>\r
+ /// Returns an Integer\r
+ /// The selected Width for the encoding.\r
+ /// </summary>\r
+ public int Width\r
+ {\r
+ get\r
+ {\r
+ return this.q_videoWidth;\r
+ }\r
+ }\r
+\r
+ private int q_videoHeight;\r
+ /// <summary>\r
+ /// Returns an Integer\r
+ /// The selected Height for the encoding.\r
+ /// </summary>\r
+ public int Height\r
+ {\r
+ get\r
+ {\r
+ return this.q_videoHeight;\r
+ }\r
+ }\r
+\r
+ private string q_cropValues;\r
+ /// <summary>\r
+ /// Returns an String\r
+ /// Cropping values.\r
+ /// </summary>\r
+ public string CropValues\r
+ {\r
+ get\r
+ {\r
+ return this.q_cropValues;\r
+ }\r
+ }\r
+\r
+ private Boolean q_detelecine;\r
+ /// <summary>\r
+ /// Returns a boolean to indicate wither DeTelecine is on or off\r
+ /// </summary>\r
+ public Boolean DeTelecine\r
+ {\r
+ get\r
+ {\r
+ return this.q_detelecine;\r
+ }\r
+ }\r
+\r
+ private Boolean q_deBlock;\r
+ /// <summary>\r
+ /// Returns a boolean to indicate wither DeBlock is on or off.\r
+ /// </summary>\r
+ public Boolean DeBlock\r
+ {\r
+ get\r
+ {\r
+ return this.q_deBlock;\r
+ }\r
+ }\r
+\r
+ private string q_deinterlace;\r
+ /// <summary>\r
+ /// Returns a string with the De-Interlace option used.\r
+ /// </summary>\r
+ public string DeInterlace\r
+ {\r
+ get\r
+ {\r
+ return this.q_deinterlace;\r
+ }\r
+ }\r
+\r
+ private string q_denoise;\r
+ /// <summary>\r
+ /// Returns a string with the DeNoise option used.\r
+ /// </summary>\r
+ public string DeNoise\r
+ {\r
+ get\r
+ {\r
+ return this.q_denoise;\r
+ }\r
+ }\r
+\r
+ private Boolean q_anamorphic;\r
+ /// <summary>\r
+ /// Returns a boolean to indicate wither Anamorphic is on or off.\r
+ /// </summary>\r
+ public Boolean Anamorphic\r
+ {\r
+ get\r
+ {\r
+ return this.q_anamorphic;\r
+ }\r
+ }\r
+\r
+ private Boolean q_chapterMarkers;\r
+ /// <summary>\r
+ /// Returns a boolean to indicate wither Chapter Markers is on or off.\r
+ /// </summary>\r
+ public Boolean ChapterMarkers\r
+ {\r
+ get\r
+ {\r
+ return this.q_chapterMarkers;\r
+ }\r
+ }\r
+\r
+ private Boolean q_grayscale;\r
+ /// <summary>\r
+ /// Returns a boolean to indicate wither Grayscale is on or off.\r
+ /// </summary>\r
+ public Boolean Grayscale\r
+ {\r
+ get\r
+ {\r
+ return this.q_grayscale;\r
+ }\r
+ }\r
+\r
+ private Boolean q_twoPass;\r
+ /// <summary>\r
+ /// Returns a boolean to indicate wither Two Pass Encoding is on or off.\r
+ /// </summary>\r
+ public Boolean TwoPass\r
+ {\r
+ get\r
+ {\r
+ return this.q_twoPass;\r
+ }\r
+ }\r
+\r
+ private Boolean q_turboFirst;\r
+ /// <summary>\r
+ /// Returns a boolean to indicate wither Chapter Markers is on or off.\r
+ /// </summary>\r
+ public Boolean TurboFirstPass\r
+ {\r
+ get\r
+ {\r
+ return this.q_turboFirst;\r
+ }\r
+ }\r
+\r
+ private Boolean q_largeMp4;\r
+ /// <summary>\r
+ /// Returns a boolean to indicate wither Larger MP4 files is on or off.\r
+ /// </summary>\r
+ public Boolean LargeMP4\r
+ {\r
+ get\r
+ {\r
+ return this.q_largeMp4;\r
+ }\r
+ }\r
+\r
+ private string q_videoFramerate;\r
+ /// <summary>\r
+ /// Returns a string with the video Framerate\r
+ /// </summary>\r
+ public string VideoFramerate\r
+ {\r
+ get\r
+ {\r
+ return this.q_videoFramerate;\r
+ }\r
+ }\r
+\r
+ private string q_avgBitrate;\r
+ /// <summary>\r
+ /// Returns a string with the average video bitrate\r
+ /// </summary>\r
+ public string AverageVideoBitrate\r
+ {\r
+ get\r
+ {\r
+ return this.q_avgBitrate;\r
+ }\r
+ }\r
+\r
+ private string q_videoTargetSize;\r
+ /// <summary>\r
+ /// Returns a string with the video target size\r
+ /// </summary>\r
+ public string VideoTargetSize\r
+ {\r
+ get\r
+ {\r
+ return this.q_videoTargetSize;\r
+ }\r
+ }\r
+\r
+ private int q_videoQuality;\r
+ /// <summary>\r
+ /// Returns a int with the video quality value\r
+ /// </summary>\r
+ public int VideoQuality\r
+ {\r
+ get\r
+ {\r
+ return this.q_videoQuality;\r
+ }\r
+ }\r
+\r
+ private Boolean q_crf;\r
+ /// <summary>\r
+ /// Returns a boolean to indicate if CRF is on or off.\r
+ /// </summary>\r
+ public Boolean CRF\r
+ {\r
+ get\r
+ {\r
+ return this.q_crf;\r
+ }\r
+ }\r
+\r
+ private string q_audioBitrate;\r
+ /// <summary>\r
+ /// Returns a string with the audio bitrate\r
+ /// </summary>\r
+ public string AudioBitrate\r
+ {\r
+ get\r
+ {\r
+ return this.q_audioBitrate;\r
+ }\r
+ }\r
+\r
+ private string q_audioSamplerate;\r
+ /// <summary>\r
+ /// Returns a string with the audio sample rate\r
+ /// </summary>\r
+ public string AudioSampleBitrate\r
+ {\r
+ get\r
+ {\r
+ return this.q_audioSamplerate;\r
+ }\r
+ }\r
+\r
+ private string q_audioTrack1;\r
+ /// <summary>\r
+ /// Returns a string with the First selected Audio track\r
+ /// </summary>\r
+ public string AudioTrack1\r
+ {\r
+ get\r
+ {\r
+ return this.q_audioTrack1;\r
+ }\r
+ }\r
+\r
+ private string q_audioTrackMix;\r
+ /// <summary>\r
+ /// Returns a string with the First selected Audio track Mix\r
+ /// </summary>\r
+ public string AudioTrackMix\r
+ {\r
+ get\r
+ {\r
+ return this.q_audioTrackMix;\r
+ }\r
+ }\r
+\r
+ private string q_subtitles;\r
+ /// <summary>\r
+ /// Returns a string with the selected subtitle track\r
+ /// </summary>\r
+ public string Subtitles\r
+ {\r
+ get\r
+ {\r
+ return this.q_subtitles;\r
+ }\r
+ }\r
+\r
+ private string q_h264;\r
+ /// <summary>\r
+ /// Returns a string with the Advanced H264 query string\r
+ /// </summary>\r
+ public string H264Query\r
+ {\r
+ get\r
+ {\r
+ return this.q_h264;\r
+ }\r
+ }\r
+ private Boolean q_verbose;\r
+ /// <summary>\r
+ /// Returns a string with the Advanced H264 query string\r
+ /// </summary>\r
+ public Boolean Verbose\r
+ {\r
+ get\r
+ {\r
+ return this.q_verbose;\r
+ }\r
+ }\r
+ #endregion\r
+\r
+ // 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
+ public static QueryParser Parse(String input)\r
+ {\r
+ QueryParser thisQuery = new QueryParser();\r
+\r
+ // Example Input\r
+ // -i "C:\Documents and Settings\Scott\Desktop\Files\DVD\Test Image.iso" \r
+ //-t 1 -c 3-5 -o "C:\test.mp4" -e x264 -E faac -w 720 -l 400 --crop 0:0:0:0\r
+ //-s 1 --deinterlace="1:-1:1" -g -m -b 2500 -2 -r 25 -T -4 --deblock --detelecine \r
+ //--denoise=7:7:5:5 -x bframes=3:ref=1:subme=5:me=umh:no-fast-pskip=1:trellis=2 -B 160 -R 48 -a 1 -6 stereo -v \r
+ //-q 0.45 -Q -S 2134\r
+\r
+\r
+ //Source\r
+ Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9:\\\s\.]+)(?:\"")");\r
+ Match source = r1.Match(input.Replace('"', '\"'));\r
+ Match title = Regex.Match(input, @"-t ([0-9]*)");\r
+ Match chapters = Regex.Match(input, @"-c ([0-9-]*)");\r
+\r
+ //Destination\r
+ Regex r2 = new Regex(@"(-o)(?:\s\"")([a-zA-Z0-9:\\\s\.]+)(?:\"")");\r
+ Match destination = r2.Match(input.Replace('"', '\"'));\r
+ Match width = Regex.Match(input, @"-w ([0-9]*)");\r
+ Match height = Regex.Match(input, @"-l ([0-9]*)");\r
+ Match videoEncoder = Regex.Match(input, @"-e ([a-zA-Z0-9]*)");\r
+ Match audioEncoder = Regex.Match(input, @"-E ([a-zA-Z0-9]*)");\r
+\r
+ //Picture Settings Tab\r
+ Match deinterlace = Regex.Match(input, @"--deinterlace=([0-9:-]*)"); // DOES NOT WORK. Needs Fixed\r
+ Match denoise = Regex.Match(input, @"--denoise=([0-9:]*)");\r
+ Match deblock = Regex.Match(input, @"--deblock");\r
+ Match detelecine = Regex.Match(input, @"--detelecine");\r
+ Match anamorphic = Regex.Match(input, @"-p");\r
+ Match chapterMarkers = Regex.Match(input, @"-m");\r
+ Match crop = Regex.Match(input, @"--crop ([0-9]):([0-9]):([0-9]):([0-9])");\r
+\r
+ //Video Settings Tab\r
+ Match videoFramerate = Regex.Match(input, @"-r ([0-9]*)");\r
+ Match videoBitrate = Regex.Match(input, @"-b ([0-9]*)");\r
+ Match videoQuality = Regex.Match(input, @"-q ([0-9.]*)");\r
+ Match videoFilesize = Regex.Match(input, @"-S ([0-9.]*)");\r
+ Match CRF = Regex.Match(input, @"-Q");\r
+ Match twoPass = Regex.Match(input, @"-2");\r
+ Match turboFirstPass = Regex.Match(input, @"-T");\r
+ Match grayscale = Regex.Match(input, @"-g");\r
+ Match largerMp4 = Regex.Match(input, @"-4");\r
+\r
+ //Audio Settings Tab\r
+ Match subtitles = Regex.Match(input, @"-s ([0-9]*)");\r
+ Match audioBitrate = Regex.Match(input, @"-B ([0-9]*)");\r
+ Match audioSampleRate = Regex.Match(input, @"-R ([0-9.]*)");\r
+ Match audioChannelsMix = Regex.Match(input, @"-6 ([a-zA-Z0-9]*)");\r
+ Match audioChannel = Regex.Match(input, @"-a ([0-9]*)");\r
+\r
+ //H264 Tab\r
+ Match x264 = Regex.Match(input, @"-x ([a-zA-Z0-9=:-]*)");\r
+ \r
+ //Program Options\r
+ Match verbose = Regex.Match(input, @"-v");\r
+ \r
+ \r
+ // ### NOTES ###\r
+ // The following code needs alot of error handling added to it at some point.\r
+ // May be an idea to add additional options such as CPU etc later.\r
+\r
+ try\r
+ {\r
+ //Source\r
+ thisQuery.q_source = source.ToString();\r
+ thisQuery.q_dvdTitle = int.Parse(title.ToString().Replace("-t ", ""));\r
+ thisQuery.q_dvdChapters = chapters.ToString();\r
+\r
+ //Destination\r
+ thisQuery.q_destination = destination.ToString();\r
+ thisQuery.q_videoEncoder = videoEncoder.ToString();\r
+ thisQuery.q_audioEncoder = audioEncoder.ToString();\r
+ thisQuery.q_videoWidth = int.Parse(width.ToString().Replace("-w ", ""));\r
+ thisQuery.q_videoHeight = int.Parse(height.ToString().Replace("-l ", ""));\r
+\r
+ //Picture Settings Tab\r
+ thisQuery.q_cropValues = crop.ToString();\r
+ thisQuery.q_detelecine = detelecine.Success;\r
+ thisQuery.q_deBlock = deblock.Success;\r
+ thisQuery.q_deinterlace = deinterlace.ToString();\r
+ thisQuery.q_denoise = denoise.ToString();\r
+ thisQuery.q_anamorphic = anamorphic.Success;\r
+ thisQuery.q_chapterMarkers = chapterMarkers.Success;\r
+\r
+ //Video Settings Tab\r
+ thisQuery.q_grayscale = grayscale.Success;\r
+ thisQuery.q_twoPass = twoPass.Success;\r
+ thisQuery.q_turboFirst = turboFirstPass.Success;\r
+ thisQuery.q_largeMp4 = largerMp4.Success;\r
+ thisQuery.q_videoFramerate = videoFramerate.ToString();\r
+ thisQuery.q_avgBitrate = videoBitrate.ToString();\r
+ thisQuery.q_videoTargetSize = videoFilesize.ToString();\r
+ thisQuery.q_videoQuality = int.Parse(videoQuality.ToString());\r
+ thisQuery.q_crf = CRF.Success;\r
+\r
+ //Audio Settings Tab\r
+ thisQuery.q_audioBitrate = audioBitrate.ToString();\r
+ thisQuery.q_audioSamplerate = audioSampleRate.ToString();\r
+ thisQuery.q_audioTrack1 = audioChannel.ToString();\r
+ thisQuery.q_audioTrackMix = audioChannelsMix.ToString();\r
+ thisQuery.q_subtitles = subtitles.ToString();\r
+\r
+ //H264 Tab\r
+ thisQuery.q_h264 = x264.ToString();\r
+\r
+ //Progam Options\r
+ thisQuery.q_verbose = verbose.Success;\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show(exc.ToString());\r
+ }\r
+\r
+ return thisQuery;\r
+ }\r
+ }\r
+}\r