OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Parsing / Chapter.cs
index 0715e0c..1bf38f4 100644 (file)
@@ -1,84 +1,85 @@
+/*  Chapter.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.Text;\r
 using System.IO;\r
+using System.Text.RegularExpressions;\r
 \r
 namespace Handbrake.Parsing\r
 {\r
+    /// <summary>\r
+    /// An object representing a Chapter aosciated with a Title, in a DVD\r
+    /// </summary>\r
     public class Chapter\r
     {\r
         private int m_chapterNumber;\r
+\r
+        private TimeSpan m_duration;\r
+\r
+        /// <summary>\r
+        /// The number of this Chapter, in regards to it's parent Title\r
+        /// </summary>\r
         public int ChapterNumber\r
         {\r
-            get\r
-            {\r
-                return this.m_chapterNumber;\r
-            }\r
+            get { return m_chapterNumber; }\r
         }\r
 \r
-        /*private int[] m_cellRange;\r
-        public int[] CellRange\r
+        /// <summary>\r
+        /// The length in time this Chapter spans\r
+        /// </summary>\r
+        public TimeSpan Duration\r
         {\r
-            get\r
-            {\r
-                return this.m_cellRange;\r
-            }\r
+            get { return m_duration; }\r
         }\r
 \r
-        private int m_blocks;\r
-        public int BlockCount\r
-        {\r
-            get\r
-            {\r
-                return this.m_blocks;\r
-            }\r
-        }*/\r
-\r
-        private TimeSpan m_duration;\r
-        public TimeSpan Duration\r
+        /// <summary>\r
+        /// Override of the ToString method to make this object easier to use in the UI\r
+        /// </summary>\r
+        /// <returns>A string formatted as: {chapter #}</returns>\r
+        public override string ToString()\r
         {\r
-            get\r
-            {\r
-                return this.m_duration;\r
-            }\r
+            return m_chapterNumber.ToString();\r
         }\r
 \r
-        public static Chapter Parse(StreamReader output)\r
+        public static Chapter Parse(StringReader output)\r
         {\r
-            string curLine = output.ReadLine();\r
-            if (!curLine.Contains("  + audio tracks:"))\r
+            Match m = Regex.Match(output.ReadLine(),\r
+                                  @"^    \+ ([0-9]*): cells ([0-9]*)->([0-9]*), ([0-9]*) blocks, duration ([0-9]{2}:[0-9]{2}:[0-9]{2})");\r
+            if (m.Success)\r
             {\r
-                Chapter thisChapter = new Chapter();\r
-                string[] splitter = curLine.Split(new string[] { "    + ", ": cells ", ", ", " blocks, duration ", "->" }, StringSplitOptions.RemoveEmptyEntries);\r
-                thisChapter.m_chapterNumber = int.Parse(splitter[0]);\r
-                //thisChapter.m_cellRange = new int[2] { int.Parse(splitter[1]), int.Parse(splitter[2]) };\r
-                //thisChapter.m_blocks = int.Parse(splitter[3]);\r
-                thisChapter.m_duration = TimeSpan.Parse(splitter[4]);\r
+                var thisChapter = new Chapter\r
+                                      {\r
+                                          m_chapterNumber = int.Parse(m.Groups[1].Value.Trim()),\r
+                                          m_duration = TimeSpan.Parse(m.Groups[5].Value)\r
+                                      };\r
                 return thisChapter;\r
             }\r
-            else\r
-            {\r
-                return null;\r
-            }\r
+            return null;\r
         }\r
 \r
-        public static Chapter[] ParseList(StreamReader output)\r
+        public static Chapter[] ParseList(StringReader output)\r
         {\r
-            List<Chapter> chapters = new List<Chapter>();\r
-            string curLine = output.ReadLine();\r
-            while (!curLine.Contains("  + audio tracks:"))\r
+            var chapters = new List<Chapter>();\r
+\r
+            // this is to read the "  + chapters:" line from the buffer\r
+            // so we can start reading the chapters themselvs\r
+            output.ReadLine();\r
+\r
+            while (true)\r
             {\r
-                Chapter thisChapter = Chapter.Parse(output);\r
+                // Start of the chapter list for this Title\r
+                Chapter thisChapter = Parse(output);\r
+\r
                 if (thisChapter != null)\r
-                {\r
                     chapters.Add(thisChapter);\r
-                }\r
                 else\r
-                {\r
                     break;\r
-                }\r
             }\r
             return chapters.ToArray();\r
         }\r
     }\r
-}\r
+}
\ No newline at end of file