OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / QueryParser.cs
index 1b81331..a4bd1c1 100644 (file)
@@ -38,6 +38,19 @@ namespace Handbrake.Functions
             }\r
         }\r
 \r
+        private string q_format;\r
+        /// <summary>\r
+        /// Returns a String \r
+        /// Full path of the destination.\r
+        /// </summary>\r
+        public string Format\r
+        {\r
+            get\r
+            {\r
+                return this.q_format;\r
+            }\r
+        }\r
+\r
         private int q_dvdTitle;\r
         /// <summary>\r
         /// Returns an Integer\r
@@ -51,16 +64,29 @@ namespace Handbrake.Functions
             }\r
         }\r
 \r
-        private string q_dvdChapters;\r
+        private int q_chaptersStart;\r
         /// <summary>\r
-        /// Returns an String\r
+        /// Returns an Int\r
         /// DVD Chapter number or chapter range.\r
         /// </summary>\r
-        public string DVDChapters\r
+        public int DVDChapterStart\r
         {\r
             get\r
             {\r
-                return this.q_dvdChapters;\r
+                return this.q_chaptersStart;\r
+            }\r
+        }\r
+\r
+        private int q_chaptersFinish;\r
+        /// <summary>\r
+        /// Returns an Int\r
+        /// DVD Chapter number or chapter range.\r
+        /// </summary>\r
+        public int DVDChapterFinish\r
+        {\r
+            get\r
+            {\r
+                return this.q_chaptersFinish;\r
             }\r
         }\r
 \r
@@ -92,7 +118,7 @@ namespace Handbrake.Functions
 \r
         private int q_videoWidth;\r
         /// <summary>\r
-        /// Returns an Integer\r
+        /// Returns an Int\r
         /// The selected Width for the encoding.\r
         /// </summary>\r
         public int Width\r
@@ -105,7 +131,7 @@ namespace Handbrake.Functions
 \r
         private int q_videoHeight;\r
         /// <summary>\r
-        /// Returns an Integer\r
+        /// Returns an Int\r
         /// The selected Height for the encoding.\r
         /// </summary>\r
         public int Height\r
@@ -129,6 +155,58 @@ namespace Handbrake.Functions
             }\r
         }\r
 \r
+        private string q_croptop;\r
+        /// <summary>\r
+        /// Returns an String\r
+        /// Cropping values.\r
+        /// </summary>\r
+        public string CropTop\r
+        {\r
+            get\r
+            {\r
+                return this.q_croptop;\r
+            }\r
+        }\r
+\r
+        private string q_cropbottom;\r
+        /// <summary>\r
+        /// Returns an String\r
+        /// Cropping values.\r
+        /// </summary>\r
+        public string CropBottom\r
+        {\r
+            get\r
+            {\r
+                return this.q_cropbottom;\r
+            }\r
+        }\r
+\r
+        private string q_cropLeft;\r
+        /// <summary>\r
+        /// Returns an String\r
+        /// Cropping values.\r
+        /// </summary>\r
+        public string CropLeft\r
+        {\r
+            get\r
+            {\r
+                return this.q_cropLeft;\r
+            }\r
+        }\r
+\r
+        private string q_cropRight;\r
+        /// <summary>\r
+        /// Returns an String\r
+        /// Cropping values.\r
+        /// </summary>\r
+        public string CropRight\r
+        {\r
+            get\r
+            {\r
+                return this.q_cropRight;\r
+            }\r
+        }\r
+\r
         private Boolean q_detelecine;\r
         /// <summary>\r
         /// Returns a boolean to indicate wither DeTelecine is on or off\r
@@ -398,11 +476,14 @@ namespace Handbrake.Functions
         {\r
             QueryParser thisQuery = new QueryParser();\r
 \r
+            #region reg exp \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
+            Match format = Regex.Match(input, @"-f ([a-z0-9a-z0-9a-z0-9]*)");\r
+            //-f mp4\r
 \r
             //Destination\r
             Regex r2 = new Regex(@"(-o)(?:\s\"")([a-zA-Z0-9:\\\s\.]+)(?:\"")");\r
@@ -413,11 +494,11 @@ namespace Handbrake.Functions
             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 deinterlace = Regex.Match(input, @"--deinterlace=([a-z]*)");\r
+            Match denoise = Regex.Match(input, @"--denoise=([a-z]*)");\r
             Match deblock = Regex.Match(input, @"--deblock");\r
             Match detelecine = Regex.Match(input, @"--detelecine");\r
-            Match anamorphic = Regex.Match(input, @"-p");\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
@@ -436,7 +517,7 @@ namespace Handbrake.Functions
             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 audioChannelsMix = Regex.Match(input, @"-6 ([0-9a-z0-9]*)");  // 1 -6 dpl2 // Broken\r
             Match audioChannel = Regex.Match(input, @"-a ([0-9]*)");\r
 \r
             //H264 Tab\r
@@ -444,60 +525,265 @@ namespace Handbrake.Functions
             \r
             //Program Options\r
             Match verbose = Regex.Match(input, @"-v");\r
-             \r
-            \r
-            // ### NOTES ###\r
-            // May be an idea to add additional options such as CPU etc later.\r
+            #endregion\r
 \r
             try\r
             {\r
-                //Source\r
-                thisQuery.q_source = source.ToString();\r
-                if (title.ToString() != "")\r
+                //\r
+                // Source\r
+                //\r
+                #region Source Tab\r
+   \r
+                thisQuery.q_source = source.ToString().Replace("-i ", "").Replace("\"", "");\r
+                if (title.Success != false)\r
+                {\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
-                if (width.ToString() != "")\r
+                }\r
+\r
+                if (chapters.Success != false)\r
+                {\r
+                     string[] actTitles = new string[2];\r
+                     actTitles = chapters.ToString().Replace("-c ", "").Split('-');\r
+                     thisQuery.q_chaptersStart = int.Parse(actTitles[0]);\r
+                     thisQuery.q_chaptersFinish = int.Parse(actTitles[1]);\r
+                 }\r
+\r
+                 if (format.Success != false)\r
+                 {\r
+                     \r
+                     thisQuery.q_format = format.ToString().Replace("-f ", "");\r
+                 }\r
+                #endregion\r
+\r
+                //\r
+                // Destination\r
+                //\r
+                #region Destination\r
+                 thisQuery.q_destination = destination.ToString().Replace("-o ","").Replace("\"", "");\r
+\r
+                 string videoEncoderConvertion;\r
+                 string audioEncoderConvertion;\r
+\r
+                 videoEncoderConvertion = videoEncoder.ToString().Replace("-e ", "");\r
+                 switch (videoEncoderConvertion)\r
+                 {\r
+                    case "ffmpeg":\r
+                        videoEncoderConvertion = "Mpeg 4";\r
+                        break;\r
+                    case "xvid":\r
+                        videoEncoderConvertion = "Xvid";\r
+                        break;\r
+                    case "x264":\r
+                        videoEncoderConvertion = "H.264";\r
+                        break;\r
+                    case "x264b13":\r
+                        videoEncoderConvertion = "H.264 Baseline 1.3";\r
+                        break;\r
+                    case "x264b30":\r
+                        videoEncoderConvertion = "H.264 (iPod)";\r
+                        break;\r
+                    default:\r
+                        videoEncoderConvertion = "Mpeg 4";\r
+                        break;\r
+                 }\r
+                 thisQuery.q_videoEncoder = videoEncoderConvertion;\r
+\r
+                 audioEncoderConvertion = audioEncoder.ToString().Replace("-E ", "");\r
+                 switch (audioEncoderConvertion)\r
+                 {\r
+                    case "faac":\r
+                        audioEncoderConvertion = "AAC";\r
+                        break;\r
+                    case "lame":\r
+                        audioEncoderConvertion = "MP3";\r
+                        break;\r
+                    case "vorbis":\r
+                        audioEncoderConvertion = "Vorbis";\r
+                        break;\r
+                    case "ac3":\r
+                        audioEncoderConvertion = "AC3";\r
+                        break;\r
+                    default:\r
+                        audioEncoderConvertion = "AAC";\r
+                        break;\r
+                 }\r
+                 thisQuery.q_audioEncoder =audioEncoderConvertion;\r
+\r
+\r
+                 if (width.Success != false)\r
+                 {\r
                     thisQuery.q_videoWidth = int.Parse(width.ToString().Replace("-w ", ""));\r
-                if (height.ToString() != "")\r
+                 }\r
+                 if (height.Success != false)\r
+                 {\r
                     thisQuery.q_videoHeight = int.Parse(height.ToString().Replace("-l ", ""));\r
+                 }\r
+                 #endregion\r
 \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
+                //\r
+                #region Picture Tab\r
+                 if (crop.Success != false)\r
+                 {\r
+                    thisQuery.q_cropValues = crop.ToString().Replace("--crop ", "");\r
+                    string[] actCropValues = new string[3];\r
+                    actCropValues = thisQuery.q_cropValues.Split(':');\r
+                    thisQuery.q_croptop = actCropValues[0];\r
+                    thisQuery.q_cropbottom = actCropValues[1];\r
+                    thisQuery.q_cropLeft = actCropValues[2];\r
+                    thisQuery.q_cropRight = actCropValues[3];\r
+                 }\r
+\r
+                 thisQuery.q_detelecine = detelecine.Success;\r
+                 thisQuery.q_deBlock = deblock.Success;\r
+\r
+                 thisQuery.q_deinterlace = "None";\r
+                 if (deinterlace.Success != false)\r
+                 {\r
+                     switch (deinterlace.ToString().Replace("--deinterlace=", ""))\r
+                     {\r
+                         case "fast":\r
+                             thisQuery.q_deinterlace = "Original (Fast)";\r
+                             break;\r
+                         case "slow":\r
+                             thisQuery.q_deinterlace = "yadif (Slow)";\r
+                             break;\r
+                         case "slower":\r
+                             thisQuery.q_deinterlace = "yadif + mcdeint (Slower)";\r
+                             break;\r
+                         case "slowest":\r
+                             thisQuery.q_deinterlace = "yadif + mcdeint (Slowest)";\r
+                             break;\r
+                         default:\r
+                             thisQuery.q_deinterlace = "None";\r
+                             break;\r
+                     }\r
+                 }\r
+\r
+                 thisQuery.q_denoise = "None";\r
+                 if (denoise.Success != false)\r
+                 {\r
+                     switch (denoise.ToString().Replace("--denoise=", ""))\r
+                     {\r
+                         case "weak":\r
+                             thisQuery.q_denoise = "Weak";\r
+                             break;\r
+                         case "medium":\r
+                             thisQuery.q_denoise = "Medium";\r
+                             break;\r
+                         case "strong":\r
+                             thisQuery.q_denoise = "Strong";\r
+                             break;\r
+                         default:\r
+                             thisQuery.q_denoise = "None";\r
+                             break;\r
+                     }\r
+                    \r
+                 }\r
+                 thisQuery.q_anamorphic = anamorphic.Success;\r
+                 thisQuery.q_chapterMarkers = chapterMarkers.Success;\r
+                 #endregion\r
+\r
+                //\r
                 //Video Settings Tab\r
+                //\r
+                #region Video\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
-                if (videoQuality.ToString() != "")\r
-                    thisQuery.q_videoQuality = int.Parse(videoQuality.ToString());\r
+                if (videoFramerate.Success != false)\r
+                {\r
+                    thisQuery.q_videoFramerate = videoFramerate.ToString().Replace("-r ", "");\r
+                }\r
+                if (videoBitrate.Success != false)\r
+                {\r
+                    thisQuery.q_avgBitrate = videoBitrate.ToString().Replace("-b ", "");\r
+                }\r
+                if (videoFilesize.Success != false)\r
+                {\r
+                    thisQuery.q_videoTargetSize = videoFilesize.ToString().Replace("-S ", "");\r
+                }\r
+\r
+                double qConvert = 0;\r
+                if (videoQuality.Success != false)\r
+                {\r
+                    qConvert = double.Parse(videoQuality.ToString().Replace("-q ", "")) * 100;\r
+                    qConvert = System.Math.Ceiling(qConvert);\r
+                    thisQuery.q_videoQuality = int.Parse(qConvert.ToString());\r
+                }\r
                 thisQuery.q_crf = CRF.Success;\r
+                #endregion\r
 \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
+                //\r
+                #region Audio\r
+                if (audioBitrate.Success != false)\r
+                {\r
+                    thisQuery.q_audioBitrate = audioBitrate.ToString().Replace("-B ", "");\r
+                }\r
+                if (audioSampleRate.Success != false)\r
+                {\r
+                    thisQuery.q_audioSamplerate = audioSampleRate.ToString().Replace("-R ", "");\r
+                }\r
+                if (audioChannel.Success != false)\r
+                {\r
+                    thisQuery.q_audioTrack1 = audioChannel.ToString().Replace("-a ", "");\r
+                }\r
+                else\r
+                {\r
+                    thisQuery.q_audioTrack1 = "Automatic";\r
+                }\r
+\r
+                thisQuery.q_audioTrackMix = "Automatic";\r
+                if (audioChannelsMix.Success != false)\r
+                {\r
+                    switch (audioChannelsMix.ToString().Replace("-6 ", "").Replace(" ",""))\r
+                    {\r
+                        case "mono":\r
+                            thisQuery.q_audioTrackMix = "Mono";\r
+                            break;\r
+                        case "stereo":\r
+                            thisQuery.q_audioTrackMix = "Stereo";\r
+                            break;\r
+                        case "dpl1":\r
+                            thisQuery.q_audioTrackMix = "Dolby Surround";\r
+                            break;\r
+                        case "dpl2":\r
+                            thisQuery.q_audioTrackMix = "Dolby Pro Logic II";\r
+                            break;\r
+                        case "6ch":\r
+                            thisQuery.q_audioTrackMix = "6 Channel Discrete";\r
+                            break;\r
+                        default:\r
+                            thisQuery.q_audioTrackMix = "Automatic";\r
+                            break;\r
+                    }\r
+                   \r
+                }\r
+                if (subtitles.Success != false)\r
+                {\r
+                    thisQuery.q_subtitles = subtitles.ToString().Replace("-s ", "");\r
+                }\r
+                else\r
+                {\r
+                    thisQuery.q_subtitles = "None";\r
+                }\r
+                #endregion\r
+\r
+                //\r
                 //H264 Tab\r
-                thisQuery.q_h264 = x264.ToString();\r
+                //\r
+                if (x264.Success != false)\r
+                {\r
+                    thisQuery.q_h264 = x264.ToString().Replace("-x ", "");\r
+                }\r
 \r
+                //\r
                 //Progam Options\r
+                //\r
                 thisQuery.q_verbose = verbose.Success;\r
             }\r
             catch (Exception exc)\r
@@ -508,4 +794,4 @@ namespace Handbrake.Functions
             return thisQuery;\r
         }\r
     }\r
-}\r
+}
\ No newline at end of file