summaryrefslogtreecommitdiffstats
path: root/win/C#/Parsing
diff options
context:
space:
mode:
authorsr55 <[email protected]>2010-06-06 14:14:19 +0000
committersr55 <[email protected]>2010-06-06 14:14:19 +0000
commit833e294b1339e9843a3f82fe1b6779be9f7c7093 (patch)
treef2e8fc2276e26365c16519ba29b62baba1ab908e /win/C#/Parsing
parent62d42d9f7a808d0f5f5432b26f88f977f13269dc (diff)
WinGui:
- Some changes / improvements to the current models / parsing models. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3359 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/Parsing')
-rw-r--r--win/C#/Parsing/AudioTrack.cs73
-rw-r--r--win/C#/Parsing/Chapter.cs17
-rw-r--r--win/C#/Parsing/Subtitle.cs42
-rw-r--r--win/C#/Parsing/Title.cs127
4 files changed, 216 insertions, 43 deletions
diff --git a/win/C#/Parsing/AudioTrack.cs b/win/C#/Parsing/AudioTrack.cs
index 489f360d2..fb00bcf47 100644
--- a/win/C#/Parsing/AudioTrack.cs
+++ b/win/C#/Parsing/AudioTrack.cs
@@ -25,19 +25,24 @@ namespace Handbrake.Parsing
public string Language { get; private set; }
/// <summary>
- /// Gets The primary format of this Audio Track
+ /// Gets or sets LanguageCode.
/// </summary>
- public string Format { get; private set; }
+ public string LanguageCode { get; set; }
+
+ /// <summary>
+ /// Gets or sets Description.
+ /// </summary>
+ public string Description { get; set; }
/// <summary>
- /// Gets Additional format info for this Audio Track
+ /// Gets The primary format of this Audio Track
/// </summary>
- public string SubFormat { get; private set; }
+ public string Format { get; private set; }
/// <summary>
/// Gets The frequency (in MHz) of this Audio Track
/// </summary>
- public int Frequency { get; private set; }
+ public int SampleRate { get; private set; }
/// <summary>
/// Gets The bitrate (in kbps) of this Audio Track
@@ -45,9 +50,48 @@ namespace Handbrake.Parsing
public int Bitrate { get; private set; }
/// <summary>
- /// Gets ISO639_2.
+ /// Create a new Audio Track object
/// </summary>
- public string ISO639_2 { get; private set; }
+ /// <param name="track">
+ /// The track.
+ /// </param>
+ /// <param name="lang">
+ /// The lang.
+ /// </param>
+ /// <param name="langCode">
+ /// The lang code.
+ /// </param>
+ /// <param name="desc">
+ /// The desc.
+ /// </param>
+ /// <param name="format">
+ /// The format.
+ /// </param>
+ /// <param name="samplerate">
+ /// The samplerate.
+ /// </param>
+ /// <param name="bitrate">
+ /// The bitrate.
+ /// </param>
+ /// <returns>
+ /// A new Audio Track
+ /// </returns>
+ public static AudioTrack CreateAudioTrack(int track, string lang, string langCode, string desc, string format, int samplerate, int bitrate)
+ {
+ AudioTrack newTrack = new AudioTrack
+ {
+ TrackNumber = track,
+ Language = lang,
+ LanguageCode = langCode,
+ Description = desc,
+ Format = format,
+ SampleRate = samplerate,
+ Bitrate = bitrate
+ };
+
+ return newTrack;
+
+ }
/// <summary>
/// Parse the CLI input to an Audio Track object
@@ -77,12 +121,11 @@ namespace Handbrake.Parsing
{
TrackNumber = int.Parse(track.Groups[1].Value.Trim()),
Language = track.Groups[2].Value,
- Format = m.Groups[3].Value,
- SubFormat = subformat,
- Frequency = int.Parse(samplerateVal),
- Bitrate = int.Parse(bitrateVal),
- ISO639_2 =
- iso639_2.Value.Replace("iso639-2: ", string.Empty).Replace(")", string.Empty)
+ Format = m.Groups[3].Value,
+ Description = subformat,
+ SampleRate = int.Parse(samplerateVal),
+ Bitrate = int.Parse(bitrateVal),
+ LanguageCode = iso639_2.Value.Replace("iso639-2: ", string.Empty).Replace(")", string.Empty)
};
return thisTrack;
}
@@ -119,10 +162,10 @@ namespace Handbrake.Parsing
/// <returns>A string formatted as: {track #} {language} ({format}) ({sub-format})</returns>
public override string ToString()
{
- if (SubFormat == null)
+ if (Description == null)
return string.Format("{0} {1} ({2})", TrackNumber, Language, Format);
- return string.Format("{0} {1} ({2}) ({3})", TrackNumber, Language, Format, SubFormat);
+ return string.Format("{0} {1} ({2}) ({3})", TrackNumber, Language, Format, Description);
}
}
} \ No newline at end of file
diff --git a/win/C#/Parsing/Chapter.cs b/win/C#/Parsing/Chapter.cs
index 4b3bb2d00..ca8fc3023 100644
--- a/win/C#/Parsing/Chapter.cs
+++ b/win/C#/Parsing/Chapter.cs
@@ -26,6 +26,23 @@ namespace Handbrake.Parsing
public TimeSpan Duration { get; private set; }
/// <summary>
+ /// Create a chapter Object
+ /// </summary>
+ /// <param name="number">
+ /// The number.
+ /// </param>
+ /// <param name="duration">
+ /// The duration.
+ /// </param>
+ /// <returns>
+ /// A new Chapter Object
+ /// </returns>
+ public static Chapter CreateChapterOjbect(int number, TimeSpan duration)
+ {
+ return new Chapter { ChapterNumber = number, Duration = duration };
+ }
+
+ /// <summary>
/// Parse a CLI string to a Chapter object
/// </summary>
/// <param name="output">
diff --git a/win/C#/Parsing/Subtitle.cs b/win/C#/Parsing/Subtitle.cs
index 52a0729db..fd0cdc552 100644
--- a/win/C#/Parsing/Subtitle.cs
+++ b/win/C#/Parsing/Subtitle.cs
@@ -9,6 +9,8 @@ namespace Handbrake.Parsing
using System.IO;
using System.Text.RegularExpressions;
+ using Handbrake.Model;
+
/// <summary>
/// An object that represents a subtitle associated with a Title, in a DVD
/// </summary>
@@ -32,7 +34,41 @@ namespace Handbrake.Parsing
/// <summary>
/// Gets the Subtitle Type
/// </summary>
- public string Type { get; private set; }
+ public SubtitleType SubtitleType { get; private set; }
+
+ /// <summary>
+ /// Gets Subtitle Type
+ /// </summary>
+ public string TypeString
+ {
+ get
+ {
+ return this.SubtitleType == SubtitleType.Picture ? "Bitmap" : "Text";
+ }
+ }
+
+ /// <summary>
+ /// Create a new Subtitle Object
+ /// </summary>
+ /// <param name="track">
+ /// The track.
+ /// </param>
+ /// <param name="lang">
+ /// The lang.
+ /// </param>
+ /// <param name="langCode">
+ /// The lang code.
+ /// </param>
+ /// <param name="type">
+ /// The type.
+ /// </param>
+ /// <returns>
+ /// A Subtitle Object
+ /// </returns>
+ public static Subtitle CreateSubtitleObject(int track, string lang, string langCode, SubtitleType type)
+ {
+ return new Subtitle { TrackNumber = track, Language = lang, LanguageCode = langCode, SubtitleType = type };
+ }
/// <summary>
/// Parse the input strings related to subtitles
@@ -55,7 +91,7 @@ namespace Handbrake.Parsing
TrackNumber = int.Parse(m.Groups[1].Value.Trim()),
Language = m.Groups[2].Value,
LanguageCode = m.Groups[3].Value,
- Type = m.Groups[4].Value
+ SubtitleType = m.Groups[4].Value.Contains("Text") ? SubtitleType.Text : SubtitleType.Picture
};
return thisSubtitle;
}
@@ -92,7 +128,7 @@ namespace Handbrake.Parsing
/// <returns>A string formatted as: {track #} {language}</returns>
public override string ToString()
{
- return string.Format("{0} {1} ({2})", TrackNumber, Language, Type);
+ return string.Format("{0} {1} ({2})", TrackNumber, Language, TypeString);
}
}
} \ No newline at end of file
diff --git a/win/C#/Parsing/Title.cs b/win/C#/Parsing/Title.cs
index ab3a27423..3a3e6ca06 100644
--- a/win/C#/Parsing/Title.cs
+++ b/win/C#/Parsing/Title.cs
@@ -12,6 +12,8 @@ namespace Handbrake.Parsing
using System.IO;
using System.Text.RegularExpressions;
+ using Handbrake.Model;
+
/// <summary>
/// An object that represents a single Title of a DVD
/// </summary>
@@ -24,16 +26,16 @@ namespace Handbrake.Parsing
/// <summary>
/// Initializes a new instance of the <see cref="Title"/> class.
- /// The constructor for this object
/// </summary>
public Title()
{
- Angles = new List<string>();
AudioTracks = new List<AudioTrack>();
Chapters = new List<Chapter>();
Subtitles = new List<Subtitle>();
}
+ #region Properties
+
/// <summary>
/// Gets a Collection of chapters in this Title
/// </summary>
@@ -55,16 +57,6 @@ namespace Handbrake.Parsing
public int TitleNumber { get; private set; }
/// <summary>
- /// Gets a value indicating whether this is a MainTitle.
- /// </summary>
- public bool MainTitle { get; private set; }
-
- /// <summary>
- /// Gets the Source Name
- /// </summary>
- public string SourceName { get; private set; }
-
- /// <summary>
/// Gets the length in time of this Title
/// </summary>
public TimeSpan Duration { get; private set; }
@@ -77,7 +69,12 @@ namespace Handbrake.Parsing
/// <summary>
/// Gets the aspect ratio of this Title
/// </summary>
- public float AspectRatio { get; private set; }
+ public double AspectRatio { get; private set; }
+
+ /// <summary>
+ /// Gets AngleCount.
+ /// </summary>
+ public int AngleCount { get; private set; }
/// <summary>
/// Gets Par Value
@@ -92,17 +89,93 @@ namespace Handbrake.Parsing
/// 2: L
/// 3: R
/// </summary>
- public int[] AutoCropDimensions { get; private set; }
+ public Cropping AutoCropDimensions { get; private set; }
/// <summary>
- /// Gets a Collection of Angles in this Title
+ /// Gets the FPS of the source.
/// </summary>
- public List<string> Angles { get; private set; }
+ public double Fps { get; private set; }
/// <summary>
- /// Gets the FPS of the source.
+ /// Gets a value indicating whether this is a MainTitle.
/// </summary>
- public float Fps { get; private set; }
+ public bool MainTitle { get; private set; }
+
+ /// <summary>
+ /// Gets the Source Name
+ /// </summary>
+ public string SourceName { get; private set; }
+
+ #endregion
+
+ /// <summary>
+ /// Creates a Title
+ /// </summary>
+ /// <param name="angles">
+ /// The angles.
+ /// </param>
+ /// <param name="aspectRatio">
+ /// The aspect Ratio.
+ /// </param>
+ /// <param name="audioTracks">
+ /// The audio Tracks.
+ /// </param>
+ /// <param name="crop">
+ /// The crop.
+ /// </param>
+ /// <param name="chapters">
+ /// The chapters.
+ /// </param>
+ /// <param name="duration">
+ /// The duration.
+ /// </param>
+ /// <param name="fps">
+ /// The fps.
+ /// </param>
+ /// <param name="mainTitle">
+ /// The main Title.
+ /// </param>
+ /// <param name="parVal">
+ /// The par Val.
+ /// </param>
+ /// <param name="resolution">
+ /// The resolution.
+ /// </param>
+ /// <param name="sourceName">
+ /// The source Name.
+ /// </param>
+ /// <param name="subtitles">
+ /// The subtitles.
+ /// </param>
+ /// <param name="titleNumber">
+ /// The title Number.
+ /// </param>
+ /// <returns>
+ /// A Title Object
+ /// </returns>
+ public static Title CreateTitle(int angles, double aspectRatio, List<AudioTrack> audioTracks, Cropping crop, List<Chapter> chapters,
+ TimeSpan duration, float fps, bool mainTitle, Size parVal, Size resolution, string sourceName, List<Subtitle> subtitles,
+ int titleNumber)
+ {
+ Title title = new Title
+ {
+ AngleCount = angles,
+ AspectRatio = aspectRatio,
+ AudioTracks = audioTracks,
+ AutoCropDimensions = crop,
+ Chapters = chapters,
+ Duration = duration,
+ Fps = fps,
+ MainTitle = mainTitle,
+ ParVal = parVal,
+ Resolution = resolution,
+ SourceName = sourceName,
+ Subtitles = subtitles,
+ TitleNumber = titleNumber
+ };
+
+ return title;
+ }
/// <summary>
/// Parse the Title Information
@@ -142,8 +215,7 @@ namespace Handbrake.Parsing
int angleCount;
int.TryParse(angleList, out angleCount);
- for (int i = 1; i <= angleCount; i++)
- thisTitle.Angles.Add(i.ToString());
+ thisTitle.AngleCount = angleCount;
}
}
@@ -165,11 +237,15 @@ namespace Handbrake.Parsing
// Get autocrop region for this title
m = Regex.Match(output.ReadLine(), @"^ \+ autocrop: ([0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)");
if (m.Success)
- thisTitle.AutoCropDimensions = new[]
- {
- int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value),
- int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value)
- };
+ {
+ thisTitle.AutoCropDimensions = new Cropping
+ {
+ Top = int.Parse(m.Groups[1].Value),
+ Bottom = int.Parse(m.Groups[2].Value),
+ Left = int.Parse(m.Groups[3].Value),
+ Right = int.Parse(m.Groups[4].Value)
+ };
+ }
thisTitle.Chapters.AddRange(Chapter.ParseList(output));
@@ -210,5 +286,6 @@ namespace Handbrake.Parsing
{
return string.Format("{0} ({1:00}:{2:00}:{3:00})", TitleNumber, Duration.Hours, Duration.Minutes, Duration.Seconds);
}
+
}
} \ No newline at end of file