Add to History when SAB receives the NZB and set episode.status to grabbed.

pull/4/head
markus101 14 years ago
parent 88ad555e75
commit c448c17605

@ -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
}
}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
namespace NzbDrone.Core.Model namespace NzbDrone.Core.Model
{ {
@ -15,6 +16,7 @@ namespace NzbDrone.Core.Model
public Uri Link { get; set; } public Uri Link { get; set; }
public string Description { get; set; } public string Description { get; set; }
public bool Proper { get; set; } public bool Proper { get; set; }
public QualityTypes Quality { get; set; }
public bool IsPassworded() public bool IsPassworded()
{ {

@ -103,7 +103,7 @@ namespace NzbDrone.Core.Providers
foreach (RssItem item in _rss.GetFeed(indexer)) foreach (RssItem item in _rss.GetFeed(indexer))
{ {
NzbInfoModel nzb = Parser.ParseNzbInfo(indexer, item); NzbInfoModel nzb = Parser.ParseNzbInfo(indexer, item);
QueueIfWanted(nzb); QueueIfWanted(nzb, i);
} }
} }
_rssSyncNotification.CurrentStatus = "RSS Sync Completed"; _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? //Do we want this item?
try 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.TitleFix = GetTitleFix(episodeParseResults, series.SeriesId); //Get the TitleFix so we can use it later
nzb.Proper = Parser.ParseProper(nzb.Title); 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) //Loop through the list of the episodeParseResults to ensure that all the episodes are needed)
foreach (var episode in episodeParseResults) foreach (var episode in episodeParseResults)
@ -154,7 +155,7 @@ namespace NzbDrone.Core.Providers
episodeModel.Proper = nzb.Proper; episodeModel.Proper = nzb.Proper;
episodeModel.SeriesId = series.SeriesId; episodeModel.SeriesId = series.SeriesId;
episodeModel.SeriesTitle = series.Title; episodeModel.SeriesTitle = series.Title;
episodeModel.Quality = Parser.ParseQuality(nzb.Title); episodeModel.Quality = nzb.Quality;
episodeModel.SeasonNumber = episode.SeasonNumber; episodeModel.SeasonNumber = episode.SeasonNumber;
episodeModel.EpisodeNumber = episode.EpisodeNumber; episodeModel.EpisodeNumber = episode.EpisodeNumber;
@ -174,7 +175,34 @@ namespace NzbDrone.Core.Providers
return; 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) catch (Exception ex)

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Web.Script.Serialization; using System.Web.Script.Serialization;
using NzbDrone.Core.Model;
using SubSonic.SqlGeneration.Schema; using SubSonic.SqlGeneration.Schema;
namespace NzbDrone.Core.Repository namespace NzbDrone.Core.Repository
@ -18,6 +19,7 @@ namespace NzbDrone.Core.Repository
[SubSonicLongString] [SubSonicLongString]
public string Overview { get; set; } public string Overview { get; set; }
public string Language { get; set; } public string Language { get; set; }
public EpisodeStatusType Status { get; set; }
[SubSonicToOneRelation(ThisClassContainsJoinKey = true)] [SubSonicToOneRelation(ThisClassContainsJoinKey = true)]
public virtual Season Season { get; set; } public virtual Season Season { get; set; }

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using NzbDrone.Core.Repository.Quality;
using SubSonic.SqlGeneration.Schema; using SubSonic.SqlGeneration.Schema;
namespace NzbDrone.Core.Repository namespace NzbDrone.Core.Repository
@ -11,14 +12,14 @@ namespace NzbDrone.Core.Repository
public int HistoryId { get; set; } public int HistoryId { get; set; }
public virtual int EpisodeId { get; set; } public virtual int EpisodeId { get; set; }
public virtual string IndexerName { get; set; } public virtual string IndexerName { get; set; }
public int Quality { get; set; } public QualityTypes Quality { get; set; }
public DateTime Date { get; set; } public DateTime Date { get; set; }
public bool IsProper { get; set; } public bool IsProper { get; set; }
[SubSonicToOneRelation(ThisClassContainsJoinKey = true)] [SubSonicToOneRelation(ThisClassContainsJoinKey = true)]
public virtual Episode Episode { get; set; } public virtual Episode Episode { get; private set; }
[SubSonicToOneRelation(ThisClassContainsJoinKey = true)] [SubSonicToOneRelation(ThisClassContainsJoinKey = true)]
public virtual Indexer Indexer { get; set; } public virtual Indexer Indexer { get; private set; }
} }
} }

Loading…
Cancel
Save