2011-05-20 05:52:05 +00:00
|
|
|
|
using System;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
using System.Collections.Generic;
|
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;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
using NzbDrone.Core.Providers.DownloadClients;
|
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;
|
2012-02-12 09:52:51 +00:00
|
|
|
|
private readonly SignalRProvider _signalRProvider;
|
2011-07-28 07:21:49 +00:00
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
2011-05-20 05:52:05 +00:00
|
|
|
|
|
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,
|
2012-02-12 09:52:51 +00:00
|
|
|
|
ConfigProvider configProvider, BlackholeProvider blackholeProvider,
|
|
|
|
|
SignalRProvider signalRProvider)
|
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;
|
2012-02-12 09:52:51 +00:00
|
|
|
|
_signalRProvider = signalRProvider;
|
2011-05-20 05:52:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DownloadProvider()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual bool DownloadReport(EpisodeParseResult parseResult)
|
|
|
|
|
{
|
2012-02-07 05:08:07 +00:00
|
|
|
|
var downloadTitle = GetDownloadTitle(parseResult);
|
2012-01-28 23:53:14 +00:00
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
|
var provider = GetActiveDownloadClient();
|
2012-01-28 23:53:14 +00:00
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
|
bool success = provider.DownloadNzb(parseResult.NzbUrl, GetDownloadTitle(parseResult));
|
2011-05-24 04:12:54 +00:00
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
|
if (success)
|
2011-05-24 04:12:54 +00:00
|
|
|
|
{
|
2012-02-07 05:08:07 +00:00
|
|
|
|
logger.Trace("Download added to Queue: {0}", downloadTitle);
|
|
|
|
|
|
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;
|
2012-05-02 15:37:09 +00:00
|
|
|
|
history.NzbInfoUrl = parseResult.NzbInfoUrl;
|
2012-08-06 06:33:07 +00:00
|
|
|
|
history.ReleaseGroup = parseResult.ReleaseGroup;
|
2011-05-24 04:12:54 +00:00
|
|
|
|
|
|
|
|
|
_historyProvider.Add(history);
|
2011-07-03 23:04:57 +00:00
|
|
|
|
_episodeProvider.MarkEpisodeAsFetched(episode.EpisodeId);
|
2012-02-12 09:52:51 +00:00
|
|
|
|
|
2012-02-28 05:52:03 +00:00
|
|
|
|
_signalRProvider.UpdateEpisodeStatus(episode.EpisodeId, EpisodeStatusType.Downloading, null);
|
2011-05-24 04:12:54 +00:00
|
|
|
|
}
|
2012-02-07 05:08:07 +00:00
|
|
|
|
|
|
|
|
|
_externalNotificationProvider.OnGrab(downloadTitle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual IDownloadClient GetActiveDownloadClient()
|
|
|
|
|
{
|
|
|
|
|
switch (_configProvider.DownloadClient)
|
|
|
|
|
{
|
|
|
|
|
case DownloadClientType.Blackhole:
|
|
|
|
|
return _blackholeProvider;
|
|
|
|
|
default:
|
|
|
|
|
return _sabProvider;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual String GetDownloadTitle(EpisodeParseResult parseResult)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var seriesTitle = MediaFileProvider.CleanFilename(parseResult.Series.Title);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Handle Full Naming
|
|
|
|
|
if (parseResult.FullSeason)
|
|
|
|
|
{
|
|
|
|
|
var seasonResult = String.Format("{0} - Season {1} [{2}]", seriesTitle,
|
|
|
|
|
parseResult.SeasonNumber, parseResult.Quality.QualityType);
|
|
|
|
|
|
|
|
|
|
if (parseResult.Quality.Proper)
|
|
|
|
|
seasonResult += " [Proper]";
|
|
|
|
|
|
|
|
|
|
return seasonResult;
|
2011-05-24 04:12:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
|
if (parseResult.Series.IsDaily)
|
|
|
|
|
{
|
|
|
|
|
var dailyResult = String.Format("{0} - {1:yyyy-MM-dd} - {2} [{3}]", seriesTitle,
|
|
|
|
|
parseResult.AirDate, parseResult.EpisodeTitle, parseResult.Quality.QualityType);
|
|
|
|
|
|
|
|
|
|
if (parseResult.Quality.Proper)
|
|
|
|
|
dailyResult += " [Proper]";
|
|
|
|
|
|
|
|
|
|
return dailyResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Show Name - 1x01-1x02 - Episode Name
|
|
|
|
|
//Show Name - 1x01 - Episode Name
|
|
|
|
|
var episodeString = new List<String>();
|
|
|
|
|
|
|
|
|
|
foreach (var episode in parseResult.EpisodeNumbers)
|
|
|
|
|
{
|
2012-04-23 06:47:30 +00:00
|
|
|
|
episodeString.Add(String.Format("{0}x{1:00}", parseResult.SeasonNumber, episode));
|
2012-02-07 05:08:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var epNumberString = String.Join("-", episodeString);
|
|
|
|
|
|
|
|
|
|
var result = String.Format("{0} - {1} - {2} [{3}]", seriesTitle, epNumberString, parseResult.EpisodeTitle, parseResult.Quality.QualityType);
|
|
|
|
|
|
|
|
|
|
if (parseResult.Quality.Proper)
|
|
|
|
|
{
|
|
|
|
|
result += " [Proper]";
|
|
|
|
|
}
|
2011-07-28 07:21:49 +00:00
|
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
|
return result;
|
2011-05-20 05:52:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|