OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / QueryParser.cs
index 5557b51..413f8fa 100644 (file)
@@ -9,75 +9,81 @@ using System.Globalization;
 using System.Text.RegularExpressions;\r
 using System.Windows.Forms;\r
 using System.Collections;\r
+using Handbrake.Model;\r
 \r
 namespace Handbrake.Functions\r
 {\r
-    internal class QueryParser\r
+    public class QueryParser\r
     {\r
         private static readonly CultureInfo Culture = new CultureInfo("en-US", false);\r
 \r
         #region Varibles\r
 \r
-        #region Source\r
-        public int DVDTitle { get; private set; }\r
-        public int DVDChapterStart { get; private set; }\r
-        public int DVDChapterFinish { get; private set; }\r
-        #endregion\r
-\r
-        #region Output Settings\r
-        public string Format { get; private set; }\r
-        public Boolean LargeMP4 { get; private set; }\r
-        public Boolean IpodAtom { get; private set; }\r
-        public Boolean OptimizeMP4 { get; private set; }\r
-        #endregion\r
-\r
-        #region Picture Settings\r
-        public int Width { get; private set; }\r
-        public int Height { get; private set; }\r
-        public int MaxWidth { get; private set; }\r
-        public int MaxHeight { get; private set; }\r
-        public string CropValues { get; private set; }\r
-        public string CropTop { get; private set; }\r
-        public string CropBottom { get; private set; }\r
-        public string CropLeft { get; private set; }\r
-        public string CropRight { get; private set; }\r
-        public Boolean Anamorphic { get; private set; }\r
-        public Boolean LooseAnamorphic { get; private set; }\r
-        #endregion\r
-\r
-        #region Video Filters\r
-        public string DeTelecine { get; private set; }\r
-        public int DeBlock { get; private set; }\r
-        public string DeInterlace { get; private set; }\r
-        public string DeNoise { get; private set; }\r
-        public string Decomb { get; private set; }\r
-        #endregion\r
-\r
-        #region Video Settings\r
-        public string VideoEncoder { get; private set; }\r
-        public Boolean Grayscale { get; private set; }\r
-        public Boolean TwoPass { get; private set; }\r
-        public Boolean TurboFirstPass { get; private set; }\r
-        public string VideoFramerate { get; private set; }\r
-        public string AverageVideoBitrate { get; private set; }\r
-        public string VideoTargetSize { get; private set; }\r
-        public float VideoQuality { get; private set; }\r
-        #endregion\r
-\r
-        #region Audio Settings\r
-        public ArrayList AudioInformation { get; private set; }\r
-        public string Subtitles { get; private set; }\r
-        public Boolean ForcedSubtitles { get; private set; }\r
-        #endregion\r
-\r
-        #region Chapter Markers\r
-        public Boolean ChapterMarkers { get; private set; }\r
-        #endregion\r
-\r
-        #region Other\r
-        public string H264Query { get; private set; }\r
-        public Boolean Verbose { get; private set; }\r
-        #endregion\r
+        // Source\r
+        public int DVDTitle { get; set; }\r
+        public int DVDChapterStart { get; set; }\r
+        public int DVDChapterFinish { get; set; }\r
+\r
+        // Output Settings\r
+        public string Format { get; set; }\r
+        public Boolean LargeMP4 { get; set; }\r
+        public Boolean IpodAtom { get; set; }\r
+        public Boolean OptimizeMP4 { get; set; }\r
+\r
+        // Picture Settings\r
+        public int Width { get; set; }\r
+        public int Height { get; set; }\r
+        public int MaxWidth { get; set; }\r
+        public int MaxHeight { get; set; }\r
+        public string CropValues { get; set; }\r
+        public string CropTop { get; set; }\r
+        public string CropBottom { get; set; }\r
+        public string CropLeft { get; set; }\r
+        public string CropRight { get; set; }\r
+        public int AnamorphicMode { get; set; }\r
+        public Boolean KeepDisplayAsect { get; set; }\r
+        public double DisplayWidthValue { get; set; }\r
+        public int PixelAspectWidth { get; set; }\r
+        public int PixelAspectHeight { get; set; }\r
+        public int AnamorphicModulus { get; set; }\r
+\r
+        // Video Filters\r
+        public string DeTelecine { get; set; }\r
+        public int DeBlock { get; set; }\r
+        public string DeInterlace { get; set; }\r
+        public string DeNoise { get; set; }\r
+        public string Decomb { get; set; }\r
+\r
+        // Video Settings\r
+        public string VideoEncoder { get; set; }\r
+        public Boolean Grayscale { get; set; }\r
+        public Boolean TwoPass { get; set; }\r
+        public Boolean TurboFirstPass { get; set; }\r
+        public string VideoFramerate { get; set; }\r
+        public string AverageVideoBitrate { get; set; }\r
+        public string VideoTargetSize { get; set; }\r
+        public float VideoQuality { get; set; }\r
+\r
+        // Audio Settings\r
+        public ArrayList AudioInformation { get; set; }\r
+        public string Subtitles { get; set; }\r
+        public Boolean ForcedSubtitles { get; set; }\r
+\r
+        // Chapter Markers\r
+        public Boolean ChapterMarkers { get; set; }\r
+\r
+        // Other\r
+        public string H264Query { get; set; }\r
+        public Boolean Verbose { get; set; }\r
+\r
+        // Preset Information\r
+        public int PresetBuildNumber { get; set; }\r
+        public string PresetDescription { get; set; }\r
+        public string PresetName { get; set; }\r
+        public string Type { get; set; }\r
+        public Boolean UsesMaxPictureSettings { get; set; }\r
+        public Boolean UsesPictureFilters { get; set; }\r
+        public Boolean UsesPictureSettings { get; set; }\r
 \r
         #endregion\r
 \r
@@ -93,10 +99,6 @@ namespace Handbrake.Functions
 \r
             #region Regular Expressions\r
 \r
-            // Useful Destination Finder\r
-            //Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9?';!^%&*()_\-:\\\s\.]+)(?:\"")");\r
-            //Match source = r1.Match(input.Replace('"', '\"'));\r
-\r
             //Source\r
             Match title = Regex.Match(input, @"-t ([0-9]*)");\r
             Match chapters = Regex.Match(input, @"-c ([0-9-]*)");\r
@@ -113,8 +115,15 @@ namespace Handbrake.Functions
             Match maxWidth = Regex.Match(input, @"-X ([0-9]*)");\r
             Match maxHeight = Regex.Match(input, @"-Y ([0-9]*)");\r
             Match crop = Regex.Match(input, @"--crop ([0-9]*):([0-9]*):([0-9]*):([0-9]*)");\r
-            Match lanamorphic = Regex.Match(input, @" -P");\r
-            Match anamorphic = Regex.Match(input, @" -p ");\r
+\r
+            Match looseAnamorphic = Regex.Match(input, @"--loose-anamorphic");\r
+            Match strictAnamorphic = Regex.Match(input, @"--strict-anamorphic");\r
+            Match customAnamorphic = Regex.Match(input, @"--custom-anamorphic");\r
+\r
+            Match keepDisplayAsect = Regex.Match(input, @"--keep-display-aspect");\r
+            Match displayWidth = Regex.Match(input, @"--display-width ([0-9*])");\r
+            Match pixelAspect = Regex.Match(input, @"--pixel-aspect ([0-9]*):([0-9]*)");\r
+            Match modulus = Regex.Match(input, @"--modulus ([0-9*])");\r
 \r
             // Picture Settings - Filters\r
             Match decomb = Regex.Match(input, @" --decomb");\r
@@ -196,16 +205,16 @@ namespace Handbrake.Functions
                 #region Picture Tab\r
 \r
                 if (width.Success)\r
-                    thisQuery.Width = int.Parse(width.ToString().Replace("-w ", ""));\r
+                    thisQuery.Width = int.Parse(width.Groups[0].Value.Replace("-w ", ""));\r
 \r
                 if (height.Success)\r
-                    thisQuery.Height = int.Parse(height.ToString().Replace("-l ", ""));\r
+                    thisQuery.Height = int.Parse(height.Groups[0].Value.Replace("-l ", ""));\r
 \r
                 if (maxWidth.Success)\r
-                    thisQuery.MaxWidth = int.Parse(maxWidth.ToString().Replace("-X ", ""));\r
+                    thisQuery.MaxWidth = int.Parse(maxWidth.Groups[0].Value.Replace("-X ", ""));\r
 \r
                 if (maxHeight.Success)\r
-                    thisQuery.MaxHeight = int.Parse(maxHeight.ToString().Replace("-Y ", ""));\r
+                    thisQuery.MaxHeight = int.Parse(maxHeight.Groups[0].Value.Replace("-Y ", ""));\r
 \r
                 if (crop.Success)\r
                 {\r
@@ -217,8 +226,29 @@ namespace Handbrake.Functions
                     thisQuery.CropRight = actCropValues[3];\r
                 }\r
 \r
-                thisQuery.Anamorphic = anamorphic.Success;\r
-                thisQuery.LooseAnamorphic = lanamorphic.Success;\r
+                if (strictAnamorphic.Success)\r
+                    thisQuery.AnamorphicMode = 1;\r
+                else if (looseAnamorphic.Success)\r
+                    thisQuery.AnamorphicMode = 2;\r
+                else if (customAnamorphic.Success)\r
+                    thisQuery.AnamorphicMode = 3;\r
+                else\r
+                    thisQuery.AnamorphicMode = 0;\r
+\r
+                thisQuery.KeepDisplayAsect = keepDisplayAsect.Success;\r
+\r
+                if (displayWidth.Success)\r
+                    thisQuery.DisplayWidthValue = double.Parse(displayWidth.Groups[0].Value.Replace("--display-width ", ""));\r
+\r
+                if (pixelAspect.Success)\r
+                    thisQuery.PixelAspectWidth = int.Parse(pixelAspect.Groups[1].Value.Replace("--pixel-aspect ", ""));\r
+\r
+                if (pixelAspect.Success && pixelAspect.Groups.Count >=3)\r
+                    thisQuery.PixelAspectHeight = int.Parse(pixelAspect.Groups[2].Value.Replace("--pixel-aspect ", ""));\r
+\r
+                if (modulus.Success)\r
+                    thisQuery.AnamorphicModulus = int.Parse(modulus.Groups[0].Value.Replace("--modulus ", ""));\r
+\r
 \r
                 #endregion\r
 \r
@@ -232,7 +262,7 @@ namespace Handbrake.Functions
                         thisQuery.Decomb = decombValue.ToString().Replace("--decomb=", "").Replace("\"", "");\r
                 }\r
 \r
-                thisQuery.DeInterlace = "None";\r
+                thisQuery.DeInterlace = "Off";\r
                 if (deinterlace.Success)\r
                 {\r
                     thisQuery.DeInterlace = deinterlace.ToString().Replace("--deinterlace=", "").Replace("\"", "");\r
@@ -240,7 +270,7 @@ namespace Handbrake.Functions
                     thisQuery.DeInterlace = thisQuery.DeInterlace.Replace("slowest", "Slowest");\r
                 }\r
 \r
-                thisQuery.DeNoise = "None";\r
+                thisQuery.DeNoise = "Off";\r
                 if (denoise.Success)\r
                 {\r
                     thisQuery.DeNoise = denoise.ToString().Replace("--denoise=", "").Replace("\"", "");\r
@@ -299,9 +329,10 @@ namespace Handbrake.Functions
                 if (videoQuality.Success)\r
                 {\r
                     float qConvert = float.Parse(videoQuality.ToString().Replace("-q ", ""), Culture);\r
-                    //qConvert = Math.Ceiling(qConvert);\r
                     thisQuery.VideoQuality = qConvert;\r
-                }\r
+                } \r
+                else\r
+                    thisQuery.VideoQuality = -1;\r
                 #endregion\r
 \r
                 #region Audio Tab\r
@@ -335,7 +366,7 @@ namespace Handbrake.Functions
                     trackDRCvalues = drcValues.ToString().Replace("-D ", "").Split(',');\r
 \r
                 // Create new Audio Track Classes and store them in the ArrayList\r
-                ArrayList AllAudioTrackInfo = new ArrayList();\r
+                ArrayList allAudioTrackInfo = new ArrayList();\r
                 for (int x = 0; x < encoderCount; x++)\r
                 {\r
                     AudioTrack track = new AudioTrack();\r
@@ -345,11 +376,11 @@ namespace Handbrake.Functions
 \r
                     if (trackMixes != null)\r
                         if (trackMixes.Length >= (x + 1))                        // Audio Mix\r
-                            track.MixDown = getMixDown(trackMixes[x].Trim());\r
+                            track.MixDown = GetMixDown(trackMixes[x].Trim());\r
 \r
                     if (trackEncoders != null)\r
                         if (trackEncoders.Length >= (x + 1))                     // Audio Mix\r
-                            track.Encoder = getAudioEncoder(trackEncoders[x].Trim());\r
+                            track.Encoder = GetAudioEncoder(trackEncoders[x].Trim());\r
 \r
                     if (trackBitrates != null)\r
                         if (trackBitrates.Length >= (x + 1))                     // Audio Encoder\r
@@ -363,9 +394,9 @@ namespace Handbrake.Functions
                         if (trackDRCvalues.Length >= (x + 1))                   // Audio DRC Values\r
                             track.DRC = trackDRCvalues[x].Trim();\r
 \r
-                    AllAudioTrackInfo.Add(track);\r
+                    allAudioTrackInfo.Add(track);\r
                 }\r
-                thisQuery.AudioInformation = AllAudioTrackInfo;\r
+                thisQuery.AudioInformation = allAudioTrackInfo;\r
 \r
                 // Subtitle Stuff\r
                 if (subtitles.Success)\r
@@ -402,7 +433,12 @@ namespace Handbrake.Functions
             return thisQuery;\r
         }\r
 \r
-        private static string getMixDown(string mixdown)\r
+        /// <summary>\r
+        /// Get the GUI equiv to a CLI mixdown\r
+        /// </summary>\r
+        /// <param name="mixdown"></param>\r
+        /// <returns></returns>\r
+        private static string GetMixDown(string mixdown)\r
         {\r
             switch (mixdown.Trim())\r
             {\r
@@ -420,40 +456,29 @@ namespace Handbrake.Functions
                     return "Automatic";\r
             }\r
         }\r
-        private static string getAudioEncoder(string audioEnc)\r
+\r
+        /// <summary>\r
+        /// Get the GUI equiv to a CLI audio encoder\r
+        /// </summary>\r
+        /// <param name="audioEnc"></param>\r
+        /// <returns></returns>\r
+        private static string GetAudioEncoder(string audioEnc)\r
         {\r
             switch (audioEnc)\r
             {\r
                 case "faac":\r
-                    return "AAC";\r
+                    return "AAC (faac)";\r
                 case "lame":\r
-                    return "MP3";\r
+                    return "MP3 (lame)";\r
                 case "vorbis":\r
-                    return "Vorbis";\r
+                    return "Vorbis (vorbis)";\r
                 case "ac3":\r
-                    return "AC3";\r
+                    return "AC3 Passthru";\r
+                case "dts":\r
+                    return "DTS Passthru";\r
                 default:\r
-                    return "AAC";\r
+                    return "AAC (faac)";\r
             }\r
         }\r
     }\r
-\r
-    public class AudioTrack\r
-    {\r
-        public AudioTrack()\r
-        {\r
-            // Default Values\r
-            Track = "Automatic";\r
-            MixDown = "Automatic";\r
-            SampleRate = "Auto";\r
-            Bitrate = "Auto";\r
-            DRC = "1";\r
-        }\r
-        public string Track { get; set; }\r
-        public string MixDown { get; set; }\r
-        public string Encoder { get; set; }\r
-        public string Bitrate { get; set; }\r
-        public string SampleRate { get; set; }\r
-        public string DRC { get; set; }\r
-    }\r
 }
\ No newline at end of file