/grawler/Grawler.Business/Data/TvShow.cs
http://grawler.googlecode.com/ · C# · 410 lines · 256 code · 50 blank · 104 comment · 7 complexity · 92bd88a6c6467ba9166843a2369c6d36 MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Xml.Serialization;
- using Grawler.Business.Utility;
- using TvdbLib;
- using TvdbLib.Cache;
- using Grawler.Business.Parsing;
-
- namespace Grawler.Business.Data
- {
- [Serializable()]
- public class TvShow
- {
-
- #region Private variables
-
- private string _appVersion;
- private int _id;
- private string _imdbId;
- private int _tvDotComId;
- private string _zap2itId;
- private TvShowDataProvider _provider;
- private DateTime _lastUpdated;
- private string _name;
- private string _network;
- private double _duration;
- private DateTime _firstAired;
- private string _plot;
- private string _contentRating;
- private int _numberOfSeasons;
- private string _status;
- private double _rating;
- private string _fanArtBanner;
- private string _logoBanner;
- private string _coverArtBanner;
- private string _showBanner;
- private List<Actor> _actors;
- private List<string> _genres;
- private List<Season> _seasons;
- private NfoType _nfoType;
-
- #endregion
-
- #region Properties
-
- /// <summary>
- /// The application version used when generating.
- /// </summary>
- public string AppVersion
- {
- get { return _appVersion; }
- set { _appVersion = value; }
- }
-
- /// <summary>
- /// Id for the TV show.
- /// </summary>
- public int Id
- {
- get { return _id; }
- set { _id = value; }
- }
-
- /// <summary>
- /// IMDB Id for the TV show.
- /// </summary>
- public string ImdbId
- {
- get { return _imdbId; }
- set { _imdbId = value; }
- }
-
- /// <summary>
- /// TV.com Id for the TV show.
- /// </summary>
- public int TvDotComId
- {
- get { return _tvDotComId; }
- set { _tvDotComId = value; }
- }
-
- /// <summary>
- /// Zap2it Id for the TV show.
- /// </summary>
- public string Zap2itId
- {
- get { return _zap2itId; }
- set { _zap2itId = value; }
- }
-
- /// <summary>
- /// The provider that supplies the data.
- /// </summary>
- public TvShowDataProvider Provider
- {
- get { return _provider; }
- set { _provider = value; }
- }
-
- /// <summary>
- /// The NFO type.
- /// </summary>
- public NfoType NfoType
- {
- get { return _nfoType; }
- set { _nfoType = value; }
- }
-
- /// <summary>
- /// Indicates when the TV show information was last updated.
- /// </summary>
- public DateTime LastUpdated
- {
- get { return _lastUpdated; }
- set { _lastUpdated = value; }
- }
-
- /// <summary>
- /// The network that broadcasts the TV show.
- /// </summary>
- public string Network
- {
- get { return _network; }
- set { _network = value; }
- }
-
- /// <summary>
- /// The duration of an episode.
- /// </summary>
- public double Duration
- {
- get { return _duration; }
- set { _duration = value; }
- }
-
- /// <summary>
- /// The name of the TV show.
- /// </summary>
- public string Name
- {
- get { return _name; }
- set { _name = value; }
- }
-
- /// <summary>
- /// The date on which the TV show was first aired.
- /// </summary>
- public DateTime FirstAired
- {
- get { return _firstAired; }
- set { _firstAired = value; }
- }
-
- /// <summary>
- /// The overview of the TV show.
- /// </summary>
- public string Plot
- {
- get { return _plot; }
- set { _plot = value; }
- }
-
- /// <summary>
- /// The content rating for the TV show.
- /// </summary>
- public string ContentRating
- {
- get { return _contentRating; }
- set { _contentRating = value; }
- }
-
- /// <summary>
- /// The amount of seasons the TV show has.
- /// </summary>
- public int NumberOfSeasons
- {
- get { return _numberOfSeasons; }
- set { _numberOfSeasons = value; }
- }
-
- /// <summary>
- /// Current status of the TV show.
- /// </summary>
- public string Status
- {
- get { return _status; }
- set { _status = value; }
- }
-
- /// <summary>
- /// The rating for the TV show.
- /// </summary>
- public double Rating
- {
- get { return _rating; }
- set { _rating = value; }
- }
-
- /// <summary>
- /// The path where fanart can be found.
- /// </summary>
- public string FanArtBanner
- {
- get { return _fanArtBanner; }
- set { _fanArtBanner = value; }
- }
-
- /// <summary>
- /// The path where the logo can be found.
- /// </summary>
- public string LogoBanner
- {
- get { return _logoBanner; }
- set { _logoBanner = value; }
- }
-
- /// <summary>
- /// The path where coverart can be found.
- /// </summary>
- public string CoverArtBanner
- {
- get { return _coverArtBanner; }
- set { _coverArtBanner = value; }
- }
-
- /// <summary>
- /// The path where coverart can be found.
- /// </summary>
- public string ShowBanner
- {
- get { return _showBanner; }
- set { _showBanner = value; }
- }
-
- /// <summary>
- /// The genres in which the TV show is categorized.
- /// </summary>
- public List<string> Genres
- {
- get { return _genres; }
- set { _genres = value; }
- }
-
- /// <summary>
- /// A list of actors that perform in the TV show.
- /// </summary>
- public List<Actor> Actors
- {
- get { return _actors; }
- set { _actors = value; }
- }
-
- /// <summary>
- /// A count of the amount of episodes.
- /// </summary>
- public int NumberOfTotalEpisodes
- {
- get
- {
- int count = 0;
-
- foreach (Season season in _seasons)
- count += season.Episodes.Count;
-
- return count;
- }
- }
-
- /// <summary>
- /// A count of the amount of regular episodes, not counting specials.
- /// </summary>
- public int NumberOfRegularEpisodes
- {
- get
- {
- int count = 0;
-
- foreach (Season season in _seasons)
- count += season.Episodes.FindAll((Episode e) => e.SeasonNumber > 0).Count;
-
- return count;
- }
- }
-
- /// <summary>
- /// A simplified version of the TV show's name.
- /// </summary>
- public string Slug
- {
- get { return Common.CreatePersistableName(_name); }
- }
-
- /// <summary>
- /// A list of seasons for the TV show.
- /// </summary>
- public List<Season> Seasons
- {
- get { return _seasons; }
- set { _seasons = value; }
- }
-
- /// <summary>
- /// A list of seasons for the TV show.
- /// </summary>
- [XmlIgnore]
- public List<Season> SeasonsSorted
- {
- get { return _seasons.OrderBy(f => f.SeasonNumber).ToList(); }
- }
-
- #endregion
-
- #region Methods
-
- /// <summary>
- /// Retrieve an episode of the current TV show.
- /// </summary>
- /// <param name="season">The season to search the episode in.</param>
- /// <param name="episode">The episode to search for.</param>
- /// <returns></returns>
- /// <remarks></remarks>
- public Episode GetEpisode(int seasonNr, int episodeNr)
- {
- Season season = this.Seasons.Find((Season s) => s.SeasonNumber == seasonNr);
-
- if (season != null)
- {
- if (season.Episodes != null)
- {
- return season.Episodes.Find((Episode e) => e.EpisodeNumber == episodeNr);
- }
- }
-
- return null;
- }
-
- /// <summary>
- /// Loads a TV show from the data directory.
- /// </summary>
- /// <param name="showName"></param>
- /// <returns></returns>
- public bool LoadFromDataFile(string showName)
- {
- string path = Constants.TVShowsDir + "\\" + Common.CreatePersistableName(showName) + "\\" + Common.CreatePersistableName(showName) + ".xml";
-
- if (File.Exists(path))
- {
- LoadFromFile(path);
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /// <summary>
- /// Loads a TV show from a file.
- /// </summary>
- /// <param name="path"></param>
- public void LoadFromFile(string path)
- {
- XmlSerializer x = new XmlSerializer(this.GetType());
- TvShow tvshow = null;
-
- using (StreamReader reader = new StreamReader(path, System.Text.Encoding.UTF8))
- {
- tvshow = (TvShow)x.Deserialize(reader);
- LoadFromObject(tvshow);
- }
- }
-
- /// <summary>
- /// Loads values into this TV show object from another.
- /// </summary>
- /// <param name="showToLoadFrom"></param>
- public void LoadFromObject(TvShow showToLoadFrom)
- {
- this.Actors = showToLoadFrom.Actors;
- this.ContentRating = showToLoadFrom.ContentRating;
- this.Duration = showToLoadFrom.Duration;
- this.Seasons = showToLoadFrom.Seasons;
- this.FirstAired = showToLoadFrom.FirstAired;
- this.Genres = showToLoadFrom.Genres;
- this.Id = showToLoadFrom.Id;
- this.Provider = showToLoadFrom.Provider;
- this.Name = showToLoadFrom.Name;
- this.Network = showToLoadFrom.Network;
- this.NumberOfSeasons = showToLoadFrom.NumberOfSeasons;
- this.Rating = showToLoadFrom.Rating;
- this.Status = showToLoadFrom.Status;
- this.LastUpdated = showToLoadFrom.LastUpdated;
- this.Plot = showToLoadFrom.Plot;
- this.FanArtBanner = showToLoadFrom.FanArtBanner;
- this.LogoBanner = showToLoadFrom.LogoBanner;
- this.CoverArtBanner = showToLoadFrom.CoverArtBanner;
- this.AppVersion = showToLoadFrom.AppVersion;
- this.ImdbId = showToLoadFrom.ImdbId;
- this.Zap2itId = showToLoadFrom.Zap2itId;
- this.TvDotComId = showToLoadFrom.TvDotComId;
- }
-
- #endregion
-
- }
- }