1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00
Sonarr/NzbDrone.Core/Providers/DownloadProvider.cs

68 lines
2.4 KiB
C#
Raw Normal View History

2011-05-20 08:52:05 +03:00
using System;
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;
private readonly HistoryProvider _historyProvider;
private readonly EpisodeProvider _episodeProvider;
private readonly ExternalNotificationProvider _externalNotificationProvider;
2011-05-20 08:52:05 +03:00
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
[Inject]
public DownloadProvider(SabProvider sabProvider, HistoryProvider historyProvider,
EpisodeProvider episodeProvider, ExternalNotificationProvider externalNotificationProvider)
2011-05-20 08:52:05 +03:00
{
_sabProvider = sabProvider;
_historyProvider = historyProvider;
_episodeProvider = episodeProvider;
_externalNotificationProvider = externalNotificationProvider;
2011-05-20 08:52:05 +03:00
}
public DownloadProvider()
{
}
public virtual bool DownloadReport(EpisodeParseResult parseResult)
{
if (_sabProvider.IsInQueue(parseResult))
2011-05-20 08:52:05 +03:00
{
Logger.Warn("Episode {0} is already in sab's queue. skipping.", parseResult);
return false;
}
var sabTitle = _sabProvider.GetSabTitle(parseResult);
var addSuccess = _sabProvider.AddByUrl(parseResult.NzbUrl, sabTitle);
if (addSuccess)
{
Logger.Trace("Download added to Queue: {0}", sabTitle);
2011-06-22 04:12:20 +03:00
foreach (var episode in _episodeProvider.GetEpisodesByParseResult(parseResult))
{
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;
2012-01-20 09:35:10 +03:00
history.NzbTitle = parseResult.OriginalString;
history.EpisodeId = episode.EpisodeId;
history.SeriesId = episode.SeriesId;
_historyProvider.Add(history);
_episodeProvider.MarkEpisodeAsFetched(episode.EpisodeId);
}
}
_externalNotificationProvider.OnGrab(sabTitle);
return addSuccess;
2011-05-20 08:52:05 +03:00
}
}
}