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.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 The number of this Chapter, in regards to it's parent Title
\r
21 public int ChapterNumber { get; private set; }
\r
24 /// Gets The length in time this Chapter spans
\r
26 public TimeSpan Duration { get; private set; }
\r
29 /// Parse a CLI string to a Chapter object
\r
31 /// <param name="output">
\r
35 /// A chapter Object
\r
37 public static Chapter Parse(StringReader output)
\r
39 Match m = Regex.Match(
\r
41 @"^ \+ ([0-9]*): cells ([0-9]*)->([0-9]*), ([0-9]*) blocks, duration ([0-9]{2}:[0-9]{2}:[0-9]{2})");
\r
44 var thisChapter = new Chapter
\r
46 ChapterNumber = int.Parse(m.Groups[1].Value.Trim()),
\r
47 Duration = TimeSpan.Parse(m.Groups[5].Value)
\r
55 /// Prase a list of strings / chatpers
\r
57 /// <param name="output">
\r
61 /// An array of chapter objects
\r
63 public static Chapter[] ParseList(StringReader output)
\r
65 var chapters = new List<Chapter>();
\r
67 // this is to read the " + chapters:" line from the buffer
\r
68 // so we can start reading the chapters themselvs
\r
73 // Start of the chapter list for this Title
\r
74 Chapter thisChapter = Parse(output);
\r
76 if (thisChapter != null)
\r
77 chapters.Add(thisChapter);
\r
81 return chapters.ToArray();
\r
85 /// Override of the ToString method to make this object easier to use in the UI
\r
87 /// <returns>A string formatted as: {chapter #}</returns>
\r
88 public override string ToString()
\r
90 return ChapterNumber.ToString();
\r