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