Added more code to FeedProviderBase

This commit is contained in:
kay.one 2011-04-03 23:53:22 -07:00
parent 7e4c38ec3f
commit 375a0c333e
2 changed files with 61 additions and 32 deletions

View File

@ -1,16 +1,25 @@
using System; using System.ServiceModel.Syndication;
using System.ServiceModel.Syndication;
using System.Xml; using System.Xml;
using NLog; using NLog;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Providers namespace NzbDrone.Core.Providers
{ {
abstract class FeedProviderBase abstract class FeedProviderBase
{ {
private readonly ISeriesProvider _seriesProvider;
private readonly ISeasonProvider _seasonProvider;
private readonly IEpisodeProvider _episodeProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
protected FeedProviderBase(ISeriesProvider seriesProvider, ISeasonProvider seasonProvider, IEpisodeProvider episodeProvider)
{
_seriesProvider = seriesProvider;
_seasonProvider = seasonProvider;
_episodeProvider = episodeProvider;
}
/// <summary> /// <summary>
/// Gets the source URL for the feed /// Gets the source URL for the feed
/// </summary> /// </summary>
@ -22,6 +31,41 @@ namespace NzbDrone.Core.Providers
protected abstract string Name { get; } protected abstract string Name { get; }
/// <summary>
/// Generates direct link to download an NZB
/// </summary>
/// <param name="item">RSS Feed item to generate the link for</param>
/// <returns>Download link URL</returns>
protected abstract string NzbDownloadUrl(SyndicationItem item);
/// <summary>
/// Parses the RSS feed item and.
/// </summary>
/// <param name="item">RSS feed item to parse</param>
/// <returns>Detailed episode info</returns>
protected EpisodeParseResult ParseFeed(SyndicationItem item)
{
var episodeParseResult = Parser.ParseEpisodeInfo(item.Title.ToString());
var seriesInfo = _seriesProvider.FindSeries(episodeParseResult.SeriesTitle);
if (seriesInfo != null)
{
episodeParseResult.SeriesId = seriesInfo.SeriesId;
episodeParseResult.SeriesTitle = seriesInfo.Title;
return episodeParseResult;
}
Logger.Debug("Unable to map {0} to any of series in database", episodeParseResult.SeriesTitle);
return null;
}
/// <summary>
/// Fetches RSS feed and process each news item.
/// </summary>
public void Fetch() public void Fetch()
{ {
Logger.Info("Fetching feeds from " + Name); Logger.Info("Fetching feeds from " + Name);
@ -36,49 +80,34 @@ namespace NzbDrone.Core.Providers
} }
} }
Logger.Info("Finished processing feeds from " + Name); Logger.Info("Finished processing feeds from " + Name);
} }
private void ProcessItem(SyndicationItem item) private void ProcessItem(SyndicationItem feedItem)
{ {
var parseResult = ParseFeed(item); var parseResult = ParseFeed(feedItem);
}
if (!_seriesProvider.IsMonitored(parseResult.SeriesId))
public void DownloadIfWanted(NzbInfoModel nzb, Indexer indexer)
{
if (nzb.IsPassworded())
{ {
Logger.Debug("Skipping Passworded Report {0}", nzb.Title); Logger.Debug("{0} is present in the DB but not tracked. skipping.", parseResult.SeriesTitle);
return;
} }
var episodeParseResults = Parser.ParseEpisodeInfo(nzb.Title); if (!_seriesProvider.QualityWanted(parseResult.SeriesId, parseResult.Quality))
if (episodeParseResults.Episodes.Count > 0)
{ {
//ProcessStandardItem(nzb, indexer, episodeParseResults); Logger.Debug("Post doesn't meet the quality requirements [{0}]. skipping.", parseResult.Quality);
return;
} }
//Handles Full Season NZBs if (_seasonProvider.IsIgnored(parseResult.SeriesId, parseResult.SeasonNumber))
var seasonParseResult = Parser.ParseSeasonInfo(nzb.Title);
if (seasonParseResult != null)
{ {
//ProcessFullSeasonItem(nzb, indexer, seasonParseResult); Logger.Debug("Season {0} is currently set to ignore. skipping.", parseResult.SeasonNumber);
return;
} }
Logger.Debug("Unsupported Title: {0}", nzb.Title); if (!_episodeProvider.IsNeeded(parseResult))
{
} Logger.Debug("Episode {0} is not needed. skipping.", parseResult);
}
protected EpisodeParseResult ParseFeed(SyndicationItem item)
{
return Parser.ParseEpisodeInfo(item.Title.ToString());
} }
} }

View File

@ -111,9 +111,9 @@ namespace NzbDrone.Core.Providers
_sonioRepo.Add(repoSeries); _sonioRepo.Add(repoSeries);
} }
public Series FindSeries(string cleanTitle) public Series FindSeries(string title)
{ {
return _sonioRepo.Single<Series>(s => s.CleanTitle == cleanTitle); return _sonioRepo.Single<Series>(s => s.CleanTitle == Parser.NormalizeTitle(title));
} }
public void UpdateSeries(Series series) public void UpdateSeries(Series series)