OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Parsing / Title.cs
index e79dd72..0494f5b 100644 (file)
 /*  Title.cs $\r
-       \r
-          This file is part of the HandBrake source code.\r
-          Homepage: <http://handbrake.fr>.\r
-          It may be used under the terms of the GNU General Public License. */\r
-\r
-using System;\r
-using System.Collections.Generic;\r
-using System.Drawing;\r
-using System.Globalization;\r
-using System.IO;\r
-using System.Text.RegularExpressions;\r
+    This file is part of the HandBrake source code.\r
+    Homepage: <http://handbrake.fr>.\r
+    It may be used under the terms of the GNU General Public License. */\r
 \r
 namespace Handbrake.Parsing\r
 {\r
+    using System;\r
+    using System.Collections.Generic;\r
+    using System.Drawing;\r
+    using System.Globalization;\r
+    using System.IO;\r
+    using System.Text.RegularExpressions;\r
+\r
     /// <summary>\r
     /// An object that represents a single Title of a DVD\r
     /// </summary>\r
     public class Title\r
     {\r
+        /// <summary>\r
+        /// The Culture Info\r
+        /// </summary>\r
         private static readonly CultureInfo Culture = new CultureInfo("en-US", false);\r
-        private readonly List<AudioTrack> m_audioTracks;\r
-        private readonly List<Chapter> m_chapters;\r
-        private readonly List<Subtitle> m_subtitles;\r
-        private List<String> m_angles = new List<string>();\r
-        private float m_aspectRatio;\r
-        private int[] m_autoCrop;\r
-        private TimeSpan m_duration;\r
-        private Size m_resolution;\r
-        private int m_titleNumber;\r
-        private Size m_parVal;\r
-        \r
+\r
+        /// <summary>\r
+        /// A collection of Audio Tracks\r
+        /// </summary>\r
+        private readonly List<AudioTrack> audioTracks;\r
+\r
+        /// <summary>\r
+        /// A Collection of Chapters\r
+        /// </summary>\r
+        private readonly List<Chapter> chapters;\r
+\r
+        /// <summary>\r
+        /// A Collection of Subtitles\r
+        /// </summary>\r
+        private readonly List<Subtitle> subtitles;\r
+\r
+        /// <summary>\r
+        /// A collection of angles \r
+        /// </summary>\r
+        private List<string> angles = new List<string>();\r
+\r
+        /// <summary>\r
+        /// The source aspect ratio\r
+        /// </summary>\r
+        private float aspectRatio;\r
+\r
+        /// <summary>\r
+        /// The source framerate\r
+        /// </summary>\r
+        private float fps;\r
+\r
+        /// <summary>\r
+        /// Source autocrop values\r
+        /// </summary>\r
+        private int[] autoCrop;\r
+\r
+        /// <summary>\r
+        /// Source name\r
+        /// </summary>\r
+        private string source;\r
+\r
+        /// <summary>\r
+        /// The duration of the source\r
+        /// </summary>\r
+        private TimeSpan duration;\r
+\r
         /// <summary>\r
+        /// The source resolution\r
+        /// </summary>\r
+        private Size resolution;\r
+\r
+        /// <summary>\r
+        /// The Title number\r
+        /// </summary>\r
+        private int titleNumber;\r
+\r
+        /// <summary>\r
+        /// The par values for this title.\r
+        /// </summary>\r
+        private Size parVal;\r
+\r
+        /// <summary>\r
+        /// Initializes a new instance of the <see cref="Title"/> class. \r
         /// The constructor for this object\r
         /// </summary>\r
         public Title()\r
         {\r
-            m_audioTracks = new List<AudioTrack>();\r
-            m_chapters = new List<Chapter>();\r
-            m_subtitles = new List<Subtitle>();\r
+            audioTracks = new List<AudioTrack>();\r
+            chapters = new List<Chapter>();\r
+            subtitles = new List<Subtitle>();\r
         }\r
 \r
         /// <summary>\r
-        /// Collection of chapters in this Title\r
+        /// Gets a Collection of chapters in this Title\r
         /// </summary>\r
         public List<Chapter> Chapters\r
         {\r
-            get { return m_chapters; }\r
+            get { return chapters; }\r
         }\r
 \r
         /// <summary>\r
-        /// Collection of audio tracks associated with this Title\r
+        /// Gets a Collection of audio tracks associated with this Title\r
         /// </summary>\r
         public List<AudioTrack> AudioTracks\r
         {\r
-            get { return m_audioTracks; }\r
+            get { return audioTracks; }\r
         }\r
 \r
         /// <summary>\r
-        /// Collection of subtitles associated with this Title\r
+        /// Gets aCollection of subtitles associated with this Title\r
         /// </summary>\r
         public List<Subtitle> Subtitles\r
         {\r
-            get { return m_subtitles; }\r
+            get { return subtitles; }\r
         }\r
 \r
         /// <summary>\r
@@ -69,43 +122,51 @@ namespace Handbrake.Parsing
         /// </summary>\r
         public int TitleNumber\r
         {\r
-            get { return m_titleNumber; }\r
+            get { return titleNumber; }\r
         }\r
 \r
         /// <summary>\r
-        /// The length in time of this Title\r
+        /// Gets the Source Name\r
+        /// </summary>\r
+        public string SourceName\r
+        {\r
+            get { return source; }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets the length in time of this Title\r
         /// </summary>\r
         public TimeSpan Duration\r
         {\r
-            get { return m_duration; }\r
+            get { return duration; }\r
         }\r
 \r
         /// <summary>\r
-        /// The resolution (width/height) of this Title\r
+        /// Gets the resolution (width/height) of this Title\r
         /// </summary>\r
         public Size Resolution\r
         {\r
-            get { return m_resolution; }\r
+            get { return resolution; }\r
         }\r
 \r
         /// <summary>\r
-        /// The aspect ratio of this Title\r
+        /// Gets the aspect ratio of this Title\r
         /// </summary>\r
         public float AspectRatio\r
         {\r
-            get { return m_aspectRatio; }\r
+            get { return aspectRatio; }\r
         }\r
 \r
         /// <summary>\r
-        /// Par Value\r
+        /// Gets Par Value\r
         /// </summary>\r
         public Size ParVal\r
         {\r
-            get { return m_parVal; }\r
+            get { return parVal; }\r
         }\r
 \r
         /// <summary>\r
-        /// The automatically detected crop region for this Title.\r
+        /// Gets the automatically detected crop region for this Title.\r
         /// This is an int array with 4 items in it as so:\r
         /// 0: \r
         /// 1: \r
@@ -114,27 +175,40 @@ namespace Handbrake.Parsing
         /// </summary>\r
         public int[] AutoCropDimensions\r
         {\r
-            get { return m_autoCrop; }\r
+            get { return autoCrop; }\r
         }\r
 \r
         /// <summary>\r
-        /// Collection of Angles in this Title\r
+        /// Gets a Collection of Angles in this Title\r
         /// </summary>\r
         public List<string> Angles\r
         {\r
-            get { return m_angles; }\r
+            get { return angles; }\r
+        }\r
+\r
+\r
+        /// <summary>\r
+        /// Gets the FPS of the source.\r
+        /// </summary>\r
+        public float Fps\r
+        {\r
+            get { return fps; }\r
         }\r
-  \r
+\r
         /// <summary>\r
         /// Override of the ToString method to provide an easy way to use this object in the UI\r
         /// </summary>\r
         /// <returns>A string representing this track in the format: {title #} (00:00:00)</returns>\r
         public override string ToString()\r
         {\r
-            return string.Format("{0} ({1:00}:{2:00}:{3:00})", m_titleNumber, m_duration.Hours,\r
-                                 m_duration.Minutes, m_duration.Seconds);\r
+            return string.Format("{0} ({1:00}:{2:00}:{3:00})", titleNumber, duration.Hours, duration.Minutes, duration.Seconds);\r
         }\r
 \r
+        /// <summary>\r
+        /// Parse the Title Information\r
+        /// </summary>\r
+        /// <param name="output">A stingreader of output data</param>\r
+        /// <returns>A Title</returns>\r
         public static Title Parse(StringReader output)\r
         {\r
             var thisTitle = new Title();\r
@@ -142,66 +216,67 @@ namespace Handbrake.Parsing
             Match m = Regex.Match(output.ReadLine(), @"^\+ title ([0-9]*):");\r
             // Match track number for this title\r
             if (m.Success)\r
-                thisTitle.m_titleNumber = int.Parse(m.Groups[1].Value.Trim());\r
+                thisTitle.titleNumber = int.Parse(m.Groups[1].Value.Trim());\r
 \r
-            output.ReadLine();\r
+            // If we are scanning a groupd of files, we'll want to get the source name.\r
+            string path = output.ReadLine();\r
+            m = Regex.Match(path, @"^  \+ stream:");\r
+            if (m.Success)\r
+                thisTitle.source = path.Replace("+ stream:", string.Empty).Trim();\r
 \r
-            if (Properties.Settings.Default.dvdnav == "Checked")\r
+            if (!Properties.Settings.Default.noDvdNav)\r
             {\r
                 // Get the Angles for the title.\r
-                m = Regex.Match(output.ReadLine(), @"  \+ angle\(s\) ([0-9,])");\r
+                m = Regex.Match(output.ReadLine(), @"  \+ angle\(s\) ([0-9])");\r
                 if (m.Success)\r
                 {\r
-                    String angleList = m.Value.Replace("+ angle(s) ", "").Trim();\r
-\r
-                    if (angleList.Contains(","))\r
-                    {\r
-                        string[] angles = angleList.Split(',');\r
-                        foreach (string s in angles)\r
-                            thisTitle.m_angles.Add(s);\r
-                    }\r
-                    else\r
-                        thisTitle.m_angles.Add(m.Value.Replace("+ angle(s) ", "").Trim());\r
+                    string angleList = m.Value.Replace("+ angle(s) ", string.Empty).Trim();\r
+                    int angleCount;\r
+                    int.TryParse(angleList, out angleCount);\r
+\r
+                    for (int i = 1; i <= angleCount; i++)\r
+                        thisTitle.angles.Add(i.ToString());\r
                 }\r
             }\r
 \r
             // Get duration for this title\r
             m = Regex.Match(output.ReadLine(), @"^  \+ duration: ([0-9]{2}:[0-9]{2}:[0-9]{2})");\r
             if (m.Success)\r
-                thisTitle.m_duration = TimeSpan.Parse(m.Groups[1].Value);\r
+                thisTitle.duration = TimeSpan.Parse(m.Groups[1].Value);\r
 \r
             // Get resolution, aspect ratio and FPS for this title\r
-            m = Regex.Match(output.ReadLine(),\r
-                            @"^  \+ size: ([0-9]*)x([0-9]*), pixel aspect: ([0-9]*)/([0-9]*), display aspect: ([0-9]*\.[0-9]*), ([0-9]*\.[0-9]*) fps");\r
-            //size: 720x576, pixel aspect: 16/15, display aspect: 1.33, 25.000 fps\r
-\r
-\r
-\r
+            m = Regex.Match(output.ReadLine(), @"^  \+ size: ([0-9]*)x([0-9]*), pixel aspect: ([0-9]*)/([0-9]*), display aspect: ([0-9]*\.[0-9]*), ([0-9]*\.[0-9]*) fps");\r
             if (m.Success)\r
             {\r
-                thisTitle.m_resolution = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));\r
-                thisTitle.m_parVal = new Size(int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value));\r
-                thisTitle.m_aspectRatio = float.Parse(m.Groups[5].Value, Culture);\r
+                thisTitle.resolution = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));\r
+                thisTitle.parVal = new Size(int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value));\r
+                thisTitle.aspectRatio = float.Parse(m.Groups[5].Value, Culture);\r
+                thisTitle.fps = float.Parse(m.Groups[6].Value, Culture);\r
             }\r
 \r
             // Get autocrop region for this title\r
             m = Regex.Match(output.ReadLine(), @"^  \+ autocrop: ([0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)");\r
             if (m.Success)\r
-                thisTitle.m_autoCrop = new int[]\r
+                thisTitle.autoCrop = new[]\r
                                            {\r
-                                               int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value),\r
+                                               int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value), \r
                                                int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value)\r
                                            };\r
 \r
-            thisTitle.m_chapters.AddRange(Chapter.ParseList(output));\r
+            thisTitle.chapters.AddRange(Chapter.ParseList(output));\r
 \r
-            thisTitle.m_audioTracks.AddRange(AudioTrack.ParseList(output));\r
+            thisTitle.audioTracks.AddRange(AudioTrack.ParseList(output));\r
 \r
-            thisTitle.m_subtitles.AddRange(Subtitle.ParseList(output));\r
+            thisTitle.subtitles.AddRange(Subtitle.ParseList(output));\r
 \r
             return thisTitle;\r
         }\r
 \r
+        /// <summary>\r
+        /// Return a list of parsed titles\r
+        /// </summary>\r
+        /// <param name="output">The Output</param>\r
+        /// <returns>A List of titles</returns>\r
         public static Title[] ParseList(string output)\r
         {\r
             var titles = new List<Title>();\r