From c448c17605a305c73cf644245fc58de3c07444e1 Mon Sep 17 00:00:00 2001 From: markus101 Date: Fri, 18 Feb 2011 08:36:50 -0800 Subject: [PATCH] Add to History when SAB receives the NZB and set episode.status to grabbed. --- NzbDrone.Core/Model/EpisodeStatusType.cs | 14 +++++++++ NzbDrone.Core/Model/NzbInfoModel.cs | 2 ++ NzbDrone.Core/Providers/RssSyncProvider.cs | 36 +++++++++++++++++++--- NzbDrone.Core/Repository/Episode.cs | 2 ++ NzbDrone.Core/Repository/History.cs | 7 +++-- 5 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 NzbDrone.Core/Model/EpisodeStatusType.cs diff --git a/NzbDrone.Core/Model/EpisodeStatusType.cs b/NzbDrone.Core/Model/EpisodeStatusType.cs new file mode 100644 index 000000000..5d5a5d54b --- /dev/null +++ b/NzbDrone.Core/Model/EpisodeStatusType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Core.Model +{ + public enum EpisodeStatusType + { + Missing = 0, + Grabbed = 1, + Downloaded = 2 + } +} diff --git a/NzbDrone.Core/Model/NzbInfoModel.cs b/NzbDrone.Core/Model/NzbInfoModel.cs index 0ed6d31ec..8c92611e3 100644 --- a/NzbDrone.Core/Model/NzbInfoModel.cs +++ b/NzbDrone.Core/Model/NzbInfoModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using NzbDrone.Core.Repository; +using NzbDrone.Core.Repository.Quality; namespace NzbDrone.Core.Model { @@ -15,6 +16,7 @@ namespace NzbDrone.Core.Model public Uri Link { get; set; } public string Description { get; set; } public bool Proper { get; set; } + public QualityTypes Quality { get; set; } public bool IsPassworded() { diff --git a/NzbDrone.Core/Providers/RssSyncProvider.cs b/NzbDrone.Core/Providers/RssSyncProvider.cs index 5e0014dfe..9953c97cf 100644 --- a/NzbDrone.Core/Providers/RssSyncProvider.cs +++ b/NzbDrone.Core/Providers/RssSyncProvider.cs @@ -103,7 +103,7 @@ namespace NzbDrone.Core.Providers foreach (RssItem item in _rss.GetFeed(indexer)) { NzbInfoModel nzb = Parser.ParseNzbInfo(indexer, item); - QueueIfWanted(nzb); + QueueIfWanted(nzb, i); } } _rssSyncNotification.CurrentStatus = "RSS Sync Completed"; @@ -113,7 +113,7 @@ namespace NzbDrone.Core.Providers } } - private void QueueIfWanted(NzbInfoModel nzb) + private void QueueIfWanted(NzbInfoModel nzb, Indexer indexer) { //Do we want this item? try @@ -145,6 +145,7 @@ namespace NzbDrone.Core.Providers nzb.TitleFix = GetTitleFix(episodeParseResults, series.SeriesId); //Get the TitleFix so we can use it later nzb.Proper = Parser.ParseProper(nzb.Title); + nzb.Quality = Parser.ParseQuality(nzb.Title); //Loop through the list of the episodeParseResults to ensure that all the episodes are needed) foreach (var episode in episodeParseResults) @@ -154,7 +155,7 @@ namespace NzbDrone.Core.Providers episodeModel.Proper = nzb.Proper; episodeModel.SeriesId = series.SeriesId; episodeModel.SeriesTitle = series.Title; - episodeModel.Quality = Parser.ParseQuality(nzb.Title); + episodeModel.Quality = nzb.Quality; episodeModel.SeasonNumber = episode.SeasonNumber; episodeModel.EpisodeNumber = episode.EpisodeNumber; @@ -174,7 +175,34 @@ namespace NzbDrone.Core.Providers return; } - var sabResult = _sab.AddByUrl(nzb.Link.ToString(), nzb.TitleFix); + //Only add to history if it was added to properly sent to SABnzbd + if (_sab.AddByUrl(nzb.Link.ToString(), nzb.TitleFix)) + { + //We need to loop through the episodeParseResults so each episode in the NZB is properly handled + foreach (var epr in episodeParseResults) + { + var episode = _episode.GetEpisode(series.SeriesId, epr.SeasonNumber, epr.EpisodeNumber); + + if (episode == null) + { + //Not sure how we got this far, so lets throw an exception + throw new ArgumentOutOfRangeException(); + } + + //Set episode status to grabbed + episode.Status = EpisodeStatusType.Grabbed; + + //Add to History + var history = new History(); + history.Date = DateTime.Now; + history.EpisodeId = episode.EpisodeId; + history.IndexerName = indexer.IndexerName; + history.IsProper = nzb.Proper; + history.Quality = nzb.Quality; + + _history.Insert(history); + } + } } catch (Exception ex) diff --git a/NzbDrone.Core/Repository/Episode.cs b/NzbDrone.Core/Repository/Episode.cs index 6e20c4098..aba423d3b 100644 --- a/NzbDrone.Core/Repository/Episode.cs +++ b/NzbDrone.Core/Repository/Episode.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Web.Script.Serialization; +using NzbDrone.Core.Model; using SubSonic.SqlGeneration.Schema; namespace NzbDrone.Core.Repository @@ -18,6 +19,7 @@ namespace NzbDrone.Core.Repository [SubSonicLongString] public string Overview { get; set; } public string Language { get; set; } + public EpisodeStatusType Status { get; set; } [SubSonicToOneRelation(ThisClassContainsJoinKey = true)] public virtual Season Season { get; set; } diff --git a/NzbDrone.Core/Repository/History.cs b/NzbDrone.Core/Repository/History.cs index b6a4b6b04..7eca99086 100644 --- a/NzbDrone.Core/Repository/History.cs +++ b/NzbDrone.Core/Repository/History.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using NzbDrone.Core.Repository.Quality; using SubSonic.SqlGeneration.Schema; namespace NzbDrone.Core.Repository @@ -11,14 +12,14 @@ namespace NzbDrone.Core.Repository public int HistoryId { get; set; } public virtual int EpisodeId { get; set; } public virtual string IndexerName { get; set; } - public int Quality { get; set; } + public QualityTypes Quality { get; set; } public DateTime Date { get; set; } public bool IsProper { get; set; } [SubSonicToOneRelation(ThisClassContainsJoinKey = true)] - public virtual Episode Episode { get; set; } + public virtual Episode Episode { get; private set; } [SubSonicToOneRelation(ThisClassContainsJoinKey = true)] - public virtual Indexer Indexer { get; set; } + public virtual Indexer Indexer { get; private set; } } }