// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// An object that represents a single Title of a DVD
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Services.Scan.Model
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using HandBrake.Interop.Interop.Model;
using HandBrakeWPF.Model;
using HandBrakeWPF.Utilities;
///
/// An object that represents a single Title of a DVD
///
public class Title
{
///
/// Initializes a new instance of the class.
///
public Title()
{
this.AudioTracks = new List();
this.Chapters = new List();
this.Subtitles = new List();
}
#region Properties
///
/// Gets or sets a Collection of chapters in this Title
///
public List Chapters { get; set; }
///
/// Gets or sets a Collection of audio tracks associated with this Title
///
public List AudioTracks { get; set; }
///
/// Gets or sets a Collection of subtitles associated with this Title
///
public List Subtitles { get; set; }
///
/// Gets or sets The track number of this Title
///
public int TitleNumber { get; set; }
///
/// Gets or sets the type.
/// HB_DVD_TYPE, HB_BD_TYPE, HB_STREAM_TYPE, HB_FF_STREAM_TYPE
///
public int Type { get; set; }
///
/// Gets or sets Playlist.
///
public string Playlist { get; set; }
///
/// Gets or sets the length in time of this Title
///
public TimeSpan Duration { get; set; }
///
/// Gets or sets the resolution (width/height) of this Title
///
public Size Resolution { get; set; }
///
/// Gets or sets the aspect ratio of this Title
///
public decimal AspectRatio { get; set; }
///
/// Gets or sets AngleCount.
///
public int AngleCount { get; set; }
///
/// Gets or sets Par Value
///
public Size ParVal { get; set; }
///
/// Gets or sets the automatically detected crop region for this Title.
/// This is an int array with 4 items in it as so:
/// 0: T
/// 1: B
/// 2: L
/// 3: R
///
public Cropping AutoCropDimensions { get; set; }
///
/// Gets or sets the FPS of the source.
///
public double Fps { get; set; }
///
/// Gets or sets the video frame rate numerator.
///
public int FramerateNumerator { get; set; }
///
/// Gets or sets the video frame rate denominator.
///
public int FramerateDenominator { get; set; }
///
/// Gets or sets a value indicating whether this is a MainTitle.
///
public bool MainTitle { get; set; }
///
/// Gets or sets the Source Name
///
public string SourceName { get; set; }
public string SourceDisplayName
{
get
{
switch (this.Type)
{
case 0: // HB_DVD_TYPE
case 1: // HB_BD_TYPE
default:
return string.Empty;
case 2: // HB_STREAM_TYPE
case 3: // HB_FF_STREAM_TYPE
return Path.GetFileNameWithoutExtension(this.SourceName);
}
}
}
public string ItemDisplayText
{
get
{
return string.Format(
"{0}{1} ({2:00}:{3:00}:{4:00}) {5}",
this.TitleNumber,
this.Playlist,
this.Duration.Hours,
this.Duration.Minutes,
this.Duration.Seconds,
this.SourceDisplayName);
}
}
public string ItemDisplayTextClosed
{
get
{
return string.Format(
"{0}{1} ({2:00}:{3:00}:{4:00})",
this.TitleNumber,
this.Playlist,
this.Duration.Hours,
this.Duration.Minutes,
this.Duration.Seconds);
}
}
#endregion
///
/// Calcuate the Duration
///
/// The Start Point (Chapters)
/// The End Point (Chapters)
/// A Timespan
public TimeSpan CalculateDuration(int startPoint, int endPoint)
{
IEnumerable chapers =
this.Chapters.Where(c => c.ChapterNumber >= startPoint && c.ChapterNumber <= endPoint);
TimeSpan duration = TimeSpan.FromSeconds(0.0);
duration = chapers.Aggregate(duration, (current, chapter) => current + chapter.Duration);
return duration;
}
///
/// Override of the ToString method to provide an easy way to use this object in the UI
///
/// A string representing this track in the format: {title #} (00:00:00)
public override string ToString()
{
if (!string.IsNullOrEmpty(this.Playlist) && !this.Playlist.StartsWith(" "))
{
this.Playlist = string.Format(" {0}", this.Playlist);
}
return string.Format("{0}{1} ({2:00}:{3:00}:{4:00})", this.TitleNumber, this.Playlist, this.Duration.Hours, this.Duration.Minutes, this.Duration.Seconds);
}
}
}