2011-05-20 05:52:05 +00:00
|
|
|
|
using System;
|
2011-06-14 01:23:04 +00:00
|
|
|
|
using Ninject;
|
2011-05-20 05:52:05 +00:00
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Model;
|
2012-01-28 23:53:14 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-05-20 05:52:05 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers
|
|
|
|
|
{
|
|
|
|
|
public class DownloadProvider
|
|
|
|
|
{
|
|
|
|
|
private readonly SabProvider _sabProvider;
|
2011-05-24 04:12:54 +00:00
|
|
|
|
private readonly HistoryProvider _historyProvider;
|
|
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
2011-07-28 07:21:49 +00:00
|
|
|
|
private readonly ExternalNotificationProvider _externalNotificationProvider;
|
2012-01-28 23:53:14 +00:00
|
|
|
|
private readonly ConfigProvider _configProvider;
|
|
|
|
|
private readonly BlackholeProvider _blackholeProvider;
|
2011-07-28 07:21:49 +00:00
|
|
|
|
|
2011-05-20 05:52:05 +00:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2011-06-14 01:23:04 +00:00
|
|
|
|
[Inject]
|
2011-07-28 07:21:49 +00:00
|
|
|
|
public DownloadProvider(SabProvider sabProvider, HistoryProvider historyProvider,
|
2012-01-28 23:53:14 +00:00
|
|
|
|
EpisodeProvider episodeProvider, ExternalNotificationProvider externalNotificationProvider,
|
|
|
|
|
ConfigProvider configProvider, BlackholeProvider blackholeProvider)
|
2011-05-20 05:52:05 +00:00
|
|
|
|
{
|
|
|
|
|
_sabProvider = sabProvider;
|
2011-05-24 04:12:54 +00:00
|
|
|
|
_historyProvider = historyProvider;
|
|
|
|
|
_episodeProvider = episodeProvider;
|
2011-07-28 07:21:49 +00:00
|
|
|
|
_externalNotificationProvider = externalNotificationProvider;
|
2012-01-28 23:53:14 +00:00
|
|
|
|
_configProvider = configProvider;
|
|
|
|
|
_blackholeProvider = blackholeProvider;
|
2011-05-20 05:52:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DownloadProvider()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual bool DownloadReport(EpisodeParseResult parseResult)
|
|
|
|
|
{
|
2012-01-28 23:53:14 +00:00
|
|
|
|
var sabTitle = _sabProvider.GetSabTitle(parseResult);
|
|
|
|
|
bool addSuccess = false;
|
|
|
|
|
|
|
|
|
|
if (_configProvider.DownloadClient == DownloadClientType.Blackhole)
|
|
|
|
|
addSuccess = _blackholeProvider.DownloadNzb(parseResult, sabTitle);
|
|
|
|
|
|
|
|
|
|
if (_configProvider.DownloadClient == DownloadClientType.Sabnzbd)
|
2011-05-20 05:52:05 +00:00
|
|
|
|
{
|
2012-01-28 23:53:14 +00:00
|
|
|
|
if(_sabProvider.IsInQueue(parseResult))
|
|
|
|
|
{
|
|
|
|
|
Logger.Warn("Episode {0} is already in sab's queue. skipping.", parseResult);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-05-20 05:52:05 +00:00
|
|
|
|
|
2012-01-28 23:53:14 +00:00
|
|
|
|
addSuccess = _sabProvider.AddByUrl(parseResult.NzbUrl, sabTitle);
|
|
|
|
|
}
|
2011-05-24 04:12:54 +00:00
|
|
|
|
|
|
|
|
|
if (addSuccess)
|
|
|
|
|
{
|
2012-01-22 21:16:25 +00:00
|
|
|
|
Logger.Trace("Download added to Queue: {0}", sabTitle);
|
|
|
|
|
|
2011-06-22 01:12:20 +00:00
|
|
|
|
foreach (var episode in _episodeProvider.GetEpisodesByParseResult(parseResult))
|
2011-05-24 04:12:54 +00:00
|
|
|
|
{
|
|
|
|
|
var history = new History();
|
|
|
|
|
history.Date = DateTime.Now;
|
|
|
|
|
history.Indexer = parseResult.Indexer;
|
2011-05-28 19:23:35 +00:00
|
|
|
|
history.IsProper = parseResult.Quality.Proper;
|
|
|
|
|
history.Quality = parseResult.Quality.QualityType;
|
2012-01-20 06:35:10 +00:00
|
|
|
|
history.NzbTitle = parseResult.OriginalString;
|
2011-05-24 04:12:54 +00:00
|
|
|
|
history.EpisodeId = episode.EpisodeId;
|
2011-06-22 02:15:39 +00:00
|
|
|
|
history.SeriesId = episode.SeriesId;
|
2011-05-24 04:12:54 +00:00
|
|
|
|
|
|
|
|
|
_historyProvider.Add(history);
|
2011-07-03 23:04:57 +00:00
|
|
|
|
_episodeProvider.MarkEpisodeAsFetched(episode.EpisodeId);
|
2011-05-24 04:12:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-28 07:21:49 +00:00
|
|
|
|
_externalNotificationProvider.OnGrab(sabTitle);
|
|
|
|
|
|
2011-05-24 04:12:54 +00:00
|
|
|
|
return addSuccess;
|
2011-05-20 05:52:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|