OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Parsing / Chapter.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Text;\r
4 using System.IO;\r
5 \r
6 namespace Handbrake.Parsing\r
7 {\r
8     /// <summary>\r
9     /// An object representing a Chapter aosciated with a Title, in a DVD\r
10     /// </summary>\r
11     public class Chapter\r
12     {\r
13         private int m_chapterNumber;\r
14         /// <summary>\r
15         /// The number of this Chapter, in regards to it's parent Title\r
16         /// </summary>\r
17         public int ChapterNumber\r
18         {\r
19             get\r
20             {\r
21                 return this.m_chapterNumber;\r
22             }\r
23         }\r
24 \r
25         private TimeSpan m_duration;\r
26         /// <summary>\r
27         /// The length in time this Chapter spans\r
28         /// </summary>\r
29         public TimeSpan Duration\r
30         {\r
31             get\r
32             {\r
33                 return this.m_duration;\r
34             }\r
35         }\r
36 \r
37         /// <summary>\r
38         /// Override of the ToString method to make this object easier to use in the UI\r
39         /// </summary>\r
40         /// <returns>A string formatted as: {chapter #}</returns>\r
41         public override string ToString()\r
42         {\r
43             return this.m_chapterNumber.ToString();\r
44         }\r
45 \r
46         public static Chapter Parse(StreamReader output)\r
47         {\r
48             string curLine = output.ReadLine();\r
49             if (!curLine.Contains("  + audio tracks:"))\r
50             {\r
51                 Chapter thisChapter = new Chapter();\r
52                 string[] splitter = curLine.Split(new string[] { "    + ", ": cells ", ", ", " blocks, duration ", "->" }, StringSplitOptions.RemoveEmptyEntries);\r
53                 thisChapter.m_chapterNumber = int.Parse(splitter[0]);\r
54                 thisChapter.m_duration = TimeSpan.Parse(splitter[4]);\r
55                 return thisChapter;\r
56             }\r
57             else\r
58             {\r
59                 return null;\r
60             }\r
61         }\r
62 \r
63         public static Chapter[] ParseList(StreamReader output)\r
64         {\r
65             List<Chapter> chapters = new List<Chapter>();\r
66             string curLine = output.ReadLine();\r
67             while (!curLine.Contains("  + audio tracks:"))\r
68             {\r
69                 Chapter thisChapter = Chapter.Parse(output);\r
70            \r
71                 if (thisChapter != null)\r
72                 {\r
73                     chapters.Add(thisChapter);\r
74                 }\r
75                 else\r
76                 {\r
77                     break;\r
78                 }\r
79             }\r
80             return chapters.ToArray();\r
81         }\r
82     }\r
83 }\r