OSDN Git Service

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