2011-04-04 06:53:22 +00:00
|
|
|
|
using System.ServiceModel.Syndication;
|
2011-04-04 03:50:12 +00:00
|
|
|
|
using System.Xml;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Model;
|
2011-04-04 07:21:07 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-04-04 03:50:12 +00:00
|
|
|
|
|
2011-04-04 07:21:07 +00:00
|
|
|
|
namespace NzbDrone.Core.Providers.Feed
|
2011-04-04 03:50:12 +00:00
|
|
|
|
{
|
2011-04-05 06:33:24 +00:00
|
|
|
|
public abstract class FeedProviderBase
|
2011-04-04 03:50:12 +00:00
|
|
|
|
{
|
2011-04-04 07:21:07 +00:00
|
|
|
|
protected readonly ISeriesProvider _seriesProvider;
|
|
|
|
|
protected readonly ISeasonProvider _seasonProvider;
|
|
|
|
|
protected readonly IEpisodeProvider _episodeProvider;
|
|
|
|
|
protected readonly IConfigProvider _configProvider;
|
2011-04-05 05:30:13 +00:00
|
|
|
|
private readonly IHttpProvider _httpProvider;
|
2011-04-04 07:21:07 +00:00
|
|
|
|
protected static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2011-04-04 03:50:12 +00:00
|
|
|
|
|
2011-04-05 06:33:24 +00:00
|
|
|
|
public FeedProviderBase(ISeriesProvider seriesProvider, ISeasonProvider seasonProvider,
|
2011-04-05 05:30:13 +00:00
|
|
|
|
IEpisodeProvider episodeProvider, IConfigProvider configProvider, IHttpProvider httpProvider)
|
2011-04-04 06:53:22 +00:00
|
|
|
|
{
|
|
|
|
|
_seriesProvider = seriesProvider;
|
|
|
|
|
_seasonProvider = seasonProvider;
|
|
|
|
|
_episodeProvider = episodeProvider;
|
2011-04-04 07:21:07 +00:00
|
|
|
|
_configProvider = configProvider;
|
2011-04-05 05:30:13 +00:00
|
|
|
|
_httpProvider = httpProvider;
|
2011-04-04 06:53:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-04-04 03:50:12 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the source URL for the feed
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected abstract string[] URL { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the name for this feed
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected abstract string Name { get; }
|
|
|
|
|
|
|
|
|
|
|
2011-04-04 06:53:22 +00:00
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2011-04-05 06:33:24 +00:00
|
|
|
|
var episodeParseResult = Parser.ParseEpisodeInfo(item.Title.Text);
|
|
|
|
|
if (episodeParseResult == null) return null;
|
|
|
|
|
|
2011-04-04 06:53:22 +00:00
|
|
|
|
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>
|
2011-04-04 03:50:12 +00:00
|
|
|
|
public void Fetch()
|
|
|
|
|
{
|
|
|
|
|
Logger.Info("Fetching feeds from " + Name);
|
|
|
|
|
|
|
|
|
|
foreach (var url in URL)
|
|
|
|
|
{
|
2011-04-04 07:21:07 +00:00
|
|
|
|
Logger.Debug("Downloading RSS " + url);
|
2011-04-05 05:30:13 +00:00
|
|
|
|
var feed = SyndicationFeed.Load(_httpProvider.DownloadXml(url)).Items;
|
2011-04-04 03:50:12 +00:00
|
|
|
|
|
|
|
|
|
foreach (var item in feed)
|
|
|
|
|
{
|
|
|
|
|
ProcessItem(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Info("Finished processing feeds from " + Name);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-04 06:53:22 +00:00
|
|
|
|
private void ProcessItem(SyndicationItem feedItem)
|
2011-04-04 03:50:12 +00:00
|
|
|
|
{
|
2011-04-05 06:33:24 +00:00
|
|
|
|
Logger.Info("Processing RSS feed item " + feedItem.Title.Text);
|
2011-04-04 07:21:07 +00:00
|
|
|
|
|
2011-04-04 06:53:22 +00:00
|
|
|
|
var parseResult = ParseFeed(feedItem);
|
2011-04-04 03:50:12 +00:00
|
|
|
|
|
2011-04-05 06:33:24 +00:00
|
|
|
|
if (parseResult != null)
|
2011-04-04 03:50:12 +00:00
|
|
|
|
{
|
2011-04-05 06:33:24 +00:00
|
|
|
|
if (!_seriesProvider.IsMonitored(parseResult.SeriesId))
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("{0} is present in the DB but not tracked. skipping.", parseResult.SeriesTitle);
|
|
|
|
|
}
|
2011-04-04 03:50:12 +00:00
|
|
|
|
|
2011-04-05 06:33:24 +00:00
|
|
|
|
if (!_seriesProvider.QualityWanted(parseResult.SeriesId, parseResult.Quality))
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Post doesn't meet the quality requirements [{0}]. skipping.", parseResult.Quality);
|
|
|
|
|
}
|
2011-04-04 03:50:12 +00:00
|
|
|
|
|
2011-04-05 06:33:24 +00:00
|
|
|
|
if (_seasonProvider.IsIgnored(parseResult.SeriesId, parseResult.SeasonNumber))
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Season {0} is currently set to ignore. skipping.", parseResult.SeasonNumber);
|
|
|
|
|
}
|
2011-04-04 03:50:12 +00:00
|
|
|
|
|
2011-04-05 06:33:24 +00:00
|
|
|
|
if (!_episodeProvider.IsNeeded(parseResult))
|
|
|
|
|
{
|
|
|
|
|
Logger.Debug("Episode {0} is not needed. skipping.", parseResult);
|
|
|
|
|
}
|
2011-04-04 06:53:22 +00:00
|
|
|
|
}
|
2011-04-04 03:50:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|