2011-04-04 06:53:22 +00:00
|
|
|
|
using System.ServiceModel.Syndication;
|
2011-04-04 03:50:12 +00:00
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Model;
|
2011-04-04 07:21:07 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-04-19 00:12:06 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using SubSonic.Repository;
|
2011-04-04 03:50:12 +00:00
|
|
|
|
|
2011-04-19 00:12:06 +00:00
|
|
|
|
namespace NzbDrone.Core.Providers.Indexer
|
2011-04-04 03:50:12 +00:00
|
|
|
|
{
|
2011-04-19 00:12:06 +00:00
|
|
|
|
public abstract class IndexerProviderBase
|
2011-04-04 03:50:12 +00:00
|
|
|
|
{
|
2011-04-10 02:44:01 +00:00
|
|
|
|
protected static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2011-04-10 01:34:36 +00:00
|
|
|
|
protected readonly ConfigProvider _configProvider;
|
2011-04-10 02:44:01 +00:00
|
|
|
|
protected readonly EpisodeProvider _episodeProvider;
|
2011-04-07 02:25:52 +00:00
|
|
|
|
private readonly HttpProvider _httpProvider;
|
2011-04-19 00:12:06 +00:00
|
|
|
|
protected readonly IRepository _repository;
|
|
|
|
|
private readonly IndexerProvider _indexerProvider;
|
2011-04-10 02:44:01 +00:00
|
|
|
|
protected readonly SeasonProvider _seasonProvider;
|
|
|
|
|
protected readonly SeriesProvider _seriesProvider;
|
2011-04-04 03:50:12 +00:00
|
|
|
|
|
2011-04-19 00:12:06 +00:00
|
|
|
|
|
|
|
|
|
public IndexerProviderBase(SeriesProvider seriesProvider, SeasonProvider seasonProvider,
|
2011-04-10 02:44:01 +00:00
|
|
|
|
EpisodeProvider episodeProvider, ConfigProvider configProvider,
|
2011-04-19 00:12:06 +00:00
|
|
|
|
HttpProvider httpProvider, IRepository repository, IndexerProvider indexerProvider)
|
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-19 00:12:06 +00:00
|
|
|
|
_repository = repository;
|
|
|
|
|
_indexerProvider = indexerProvider;
|
2011-04-04 06:53:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-04 03:50:12 +00:00
|
|
|
|
/// <summary>
|
2011-04-19 00:12:06 +00:00
|
|
|
|
/// Gets the name for the feed
|
2011-04-04 03:50:12 +00:00
|
|
|
|
/// </summary>
|
2011-04-19 00:12:06 +00:00
|
|
|
|
public abstract string Name { get; }
|
2011-04-04 03:50:12 +00:00
|
|
|
|
|
2011-04-04 06:53:22 +00:00
|
|
|
|
/// <summary>
|
2011-04-21 01:26:13 +00:00
|
|
|
|
/// Gets the source URL for the feed
|
2011-04-04 06:53:22 +00:00
|
|
|
|
/// </summary>
|
2011-04-21 01:26:13 +00:00
|
|
|
|
protected abstract string[] Urls { get; }
|
2011-04-04 06:53:22 +00:00
|
|
|
|
|
|
|
|
|
|
2011-04-21 01:26:13 +00:00
|
|
|
|
protected IndexerSetting Settings
|
2011-04-04 06:53:22 +00:00
|
|
|
|
{
|
2011-04-21 01:26:13 +00:00
|
|
|
|
get
|
2011-04-04 06:53:22 +00:00
|
|
|
|
{
|
2011-04-21 01:26:13 +00:00
|
|
|
|
return _indexerProvider.GetSettings(GetType());
|
2011-04-04 06:53:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2011-04-10 02:44:01 +00:00
|
|
|
|
/// Fetches RSS feed and process each news item.
|
2011-04-04 06:53:22 +00:00
|
|
|
|
/// </summary>
|
2011-04-04 03:50:12 +00:00
|
|
|
|
public void Fetch()
|
|
|
|
|
{
|
2011-04-19 00:12:06 +00:00
|
|
|
|
Logger.Info("Fetching feeds from " + Settings.Name);
|
2011-04-04 03:50:12 +00:00
|
|
|
|
|
2011-04-21 01:26:13 +00:00
|
|
|
|
foreach (var url in Urls)
|
2011-04-04 03:50:12 +00:00
|
|
|
|
{
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-19 00:12:06 +00:00
|
|
|
|
Logger.Info("Finished processing feeds from " + Settings.Name);
|
2011-04-04 03:50:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
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-19 06:37:34 +00:00
|
|
|
|
return;
|
2011-04-05 06:33:24 +00:00
|
|
|
|
}
|
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-19 06:37:34 +00:00
|
|
|
|
return;
|
2011-04-05 06:33:24 +00:00
|
|
|
|
}
|
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-19 06:37:34 +00:00
|
|
|
|
return;
|
2011-04-05 06:33:24 +00:00
|
|
|
|
}
|
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-19 06:37:34 +00:00
|
|
|
|
return;
|
2011-04-05 06:33:24 +00:00
|
|
|
|
}
|
2011-04-19 06:37:34 +00:00
|
|
|
|
|
|
|
|
|
//Should probably queue item to download
|
2011-04-04 06:53:22 +00:00
|
|
|
|
}
|
2011-04-04 03:50:12 +00:00
|
|
|
|
}
|
2011-04-19 00:12:06 +00:00
|
|
|
|
|
2011-04-21 01:26:13 +00:00
|
|
|
|
/// <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-19 00:12:06 +00:00
|
|
|
|
{
|
2011-04-21 01:26:13 +00:00
|
|
|
|
var episodeParseResult = Parser.ParseEpisodeInfo(item.Title.Text);
|
|
|
|
|
if (episodeParseResult == null) return CustomParser(item, null);
|
|
|
|
|
|
|
|
|
|
var seriesInfo = _seriesProvider.FindSeries(episodeParseResult.SeriesTitle);
|
|
|
|
|
|
|
|
|
|
if (seriesInfo != null)
|
2011-04-19 00:12:06 +00:00
|
|
|
|
{
|
2011-04-21 01:26:13 +00:00
|
|
|
|
episodeParseResult.SeriesId = seriesInfo.SeriesId;
|
|
|
|
|
episodeParseResult.SeriesTitle = seriesInfo.Title;
|
|
|
|
|
return CustomParser(item, episodeParseResult);
|
2011-04-19 00:12:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-21 01:26:13 +00:00
|
|
|
|
Logger.Debug("Unable to map {0} to any of series in database", episodeParseResult.SeriesTitle);
|
|
|
|
|
return CustomParser(item, episodeParseResult);
|
|
|
|
|
}
|
2011-04-19 00:12:06 +00:00
|
|
|
|
|
2011-04-21 01:26:13 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This method can be overwritten to provide indexer specific info parsing
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">RSS item that needs to be parsed</param>
|
|
|
|
|
/// <param name="currentResult">Result of the built in parse function.</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected virtual EpisodeParseResult CustomParser(SyndicationItem item, EpisodeParseResult currentResult)
|
|
|
|
|
{
|
|
|
|
|
return currentResult;
|
|
|
|
|
}
|
2011-04-19 00:12:06 +00:00
|
|
|
|
|
2011-04-21 01:26:13 +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);
|
2011-04-04 03:50:12 +00:00
|
|
|
|
}
|
2011-04-10 02:44:01 +00:00
|
|
|
|
}
|