OSDN Git Service

import 0.9.3
[handbrake-jp/handbrake-jp.git] / win / C# / Parsing / Chapter.cs
1 /*  Chapter.cs $\r
2         \r
3            This file is part of the HandBrake source code.\r
4            Homepage: <http://handbrake.fr>.\r
5            It may be used under the terms of the GNU General Public License. */\r
6 \r
7 using System;\r
8 using System.Collections.Generic;\r
9 using System.IO;\r
10 using System.Text.RegularExpressions;\r
11 \r
12 namespace Handbrake.Parsing\r
13 {\r
14     /// <summary>\r
15     /// An object representing a Chapter aosciated with a Title, in a DVD\r
16     /// </summary>\r
17     public class Chapter\r
18     {\r
19         private int m_chapterNumber;\r
20         /// <summary>\r
21         /// The number of this Chapter, in regards to it's parent Title\r
22         /// </summary>\r
23         public int ChapterNumber\r
24         {\r
25             get\r
26             {\r
27                 return this.m_chapterNumber;\r
28             }\r
29         }\r
30 \r
31         private TimeSpan m_duration;\r
32         /// <summary>\r
33         /// The length in time this Chapter spans\r
34         /// </summary>\r
35         public TimeSpan Duration\r
36         {\r
37             get\r
38             {\r
39                 return this.m_duration;\r
40             }\r
41         }\r
42 \r
43         /// <summary>\r
44         /// Override of the ToString method to make this object easier to use in the UI\r
45         /// </summary>\r
46         /// <returns>A string formatted as: {chapter #}</returns>\r
47         public override string ToString()\r
48         {\r
49             return this.m_chapterNumber.ToString();\r
50         }\r
51 \r
52         public static Chapter Parse(StringReader output)\r
53         {\r
54             Match m = Regex.Match(output.ReadLine(), @"^    \+ ([0-9]*): cells ([0-9]*)->([0-9]*), ([0-9]*) blocks, duration ([0-9]{2}:[0-9]{2}:[0-9]{2})");\r
55             if (m.Success)\r
56             {\r
57                 Chapter thisChapter = new Chapter();\r
58                 thisChapter.m_chapterNumber = int.Parse(m.Groups[1].Value.Trim().ToString());\r
59                 thisChapter.m_duration = TimeSpan.Parse(m.Groups[5].Value);\r
60                 return thisChapter;\r
61             }\r
62             else\r
63                 return null;\r
64         }\r
65 \r
66         public static Chapter[] ParseList(StringReader output)\r
67         {\r
68             List<Chapter> chapters = new List<Chapter>();\r
69 \r
70             // this is to read the "  + chapters:" line from the buffer\r
71             // so we can start reading the chapters themselvs\r
72             output.ReadLine();\r
73 \r
74             while (true)\r
75             {\r
76                 // Start of the chapter list for this Title\r
77                 Chapter thisChapter = Chapter.Parse(output);\r
78 \r
79                 if (thisChapter != null)\r
80                     chapters.Add(thisChapter);\r
81                 else\r
82                     break;\r
83             }\r
84             return chapters.ToArray();\r
85         }\r
86     }\r
87 }\r