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
6 namespace HandBrake.ApplicationServices.Parsing
\r
9 using System.Collections.Generic;
\r
11 using System.Text.RegularExpressions;
\r
14 /// An object representing a Chapter aosciated with a Title, in a DVD
\r
16 public class Chapter
\r
19 /// Gets or sets The number of this Chapter, in regards to it's parent Title
\r
21 public int ChapterNumber { get; set; }
\r
24 /// Gets or sets ChapterName.
\r
26 public string ChapterName { get; set; }
\r
29 /// Gets or sets The length in time this Chapter spans
\r
31 public TimeSpan Duration { get; set; }
\r
34 /// Parse a CLI string to a Chapter object
\r
36 /// <param name="output">
\r
40 /// A chapter Object
\r
42 public static Chapter Parse(StringReader output)
\r
44 // TODO add support for reading chapter names to the regex.
\r
45 Match m = Regex.Match(
\r
47 @"^ \+ ([0-9]*): cells ([0-9]*)->([0-9]*), ([0-9]*) blocks, duration ([0-9]{2}:[0-9]{2}:[0-9]{2})");
\r
50 var thisChapter = new Chapter
\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
62 /// Prase a list of strings / chatpers
\r
64 /// <param name="output">
\r
68 /// An array of chapter objects
\r
70 public static Chapter[] ParseList(StringReader output)
\r
72 var chapters = new List<Chapter>();
\r
74 // this is to read the " + chapters:" line from the buffer
\r
75 // so we can start reading the chapters themselvs
\r
80 // Start of the chapter list for this Title
\r
81 Chapter thisChapter = Parse(output);
\r
83 if (thisChapter != null)
\r
84 chapters.Add(thisChapter);
\r
88 return chapters.ToArray();
\r
92 /// Override of the ToString method to make this object easier to use in the UI
\r
94 /// <returns>A string formatted as: {chapter #}</returns>
\r
95 public override string ToString()
\r
97 return ChapterNumber.ToString();
\r