mirror of https://github.com/lidarr/Lidarr
New: Blackhole implemented, allowing clients other than SABnzbd to be used.
This commit is contained in:
parent
af0532d959
commit
fdd4a6c632
|
@ -5,6 +5,7 @@ using Moq;
|
|||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
@ -62,6 +63,60 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|||
Mocker.GetMock<ExternalNotificationProvider>()
|
||||
.Setup(c => c.OnGrab(It.IsAny<string>()));
|
||||
|
||||
Mocker.GetMock<ConfigProvider>()
|
||||
.Setup(c => c.DownloadClient)
|
||||
.Returns(DownloadClientType.Sabnzbd);
|
||||
|
||||
Mocker.Resolve<DownloadProvider>().DownloadReport(parseResult);
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_report_should_download_nzb_add_to_history_mark_as_grabbed()
|
||||
{
|
||||
WithStrictMocker();
|
||||
var parseResult = Builder<EpisodeParseResult>.CreateNew()
|
||||
.With(c => c.Quality = new Quality(QualityTypes.DVD, false))
|
||||
.Build();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.TheFirst(1).With(s => s.EpisodeId = 12)
|
||||
.TheNext(1).With(s => s.EpisodeId = 99)
|
||||
.All().With(s => s.SeriesId = 5)
|
||||
.Build();
|
||||
|
||||
|
||||
const string sabTitle = "My fake sab title";
|
||||
Mocker.GetMock<BlackholeProvider>()
|
||||
.Setup(s => s.DownloadNzb(It.IsAny<EpisodeParseResult>(), sabTitle))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.GetMock<SabProvider>()
|
||||
.Setup(s => s.GetSabTitle(parseResult))
|
||||
.Returns(sabTitle);
|
||||
|
||||
Mocker.GetMock<HistoryProvider>()
|
||||
.Setup(s => s.Add(It.Is<History>(h => h.EpisodeId == 12 && h.SeriesId == 5)));
|
||||
Mocker.GetMock<HistoryProvider>()
|
||||
.Setup(s => s.Add(It.Is<History>(h => h.EpisodeId == 99 && h.SeriesId == 5)));
|
||||
|
||||
Mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>(), false)).Returns(episodes);
|
||||
|
||||
Mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(c => c.MarkEpisodeAsFetched(12));
|
||||
|
||||
Mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(c => c.MarkEpisodeAsFetched(99));
|
||||
|
||||
Mocker.GetMock<ExternalNotificationProvider>()
|
||||
.Setup(c => c.OnGrab(It.IsAny<string>()));
|
||||
|
||||
Mocker.GetMock<ConfigProvider>()
|
||||
.Setup(c => c.DownloadClient)
|
||||
.Returns(DownloadClientType.Blackhole);
|
||||
|
||||
Mocker.Resolve<DownloadProvider>().DownloadReport(parseResult);
|
||||
|
||||
Mocker.VerifyAllMocks();
|
||||
|
|
|
@ -258,6 +258,7 @@
|
|||
<Compile Include="Model\Xbmc\ErrorResult.cs" />
|
||||
<Compile Include="Model\Xbmc\IconType.cs" />
|
||||
<Compile Include="Providers\BackupProvider.cs" />
|
||||
<Compile Include="Providers\BlackholeProvider.cs" />
|
||||
<Compile Include="Providers\Converting\AtomicParsleyProvider.cs" />
|
||||
<Compile Include="Providers\Converting\HandbrakeProvider.cs" />
|
||||
<Compile Include="Providers\Indexer\Newznab.cs" />
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NLog;
|
||||
using Ninject;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
|
||||
namespace NzbDrone.Core.Providers
|
||||
{
|
||||
public class BlackholeProvider
|
||||
{
|
||||
private readonly ConfigProvider _configProvider;
|
||||
private readonly HttpProvider _httpProvider;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
[Inject]
|
||||
public BlackholeProvider(ConfigProvider configProvider, HttpProvider httpProvider,
|
||||
DiskProvider diskProvider)
|
||||
{
|
||||
_configProvider = configProvider;
|
||||
_httpProvider = httpProvider;
|
||||
_diskProvider = diskProvider;
|
||||
}
|
||||
|
||||
public BlackholeProvider()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual bool DownloadNzb(EpisodeParseResult parseResult, string title)
|
||||
{
|
||||
try
|
||||
{
|
||||
var filename = Path.Combine(_configProvider.BlackholeDirectory, title, ".nzb");
|
||||
|
||||
if(_diskProvider.FileExists(filename))
|
||||
{
|
||||
//Return true so a lesser quality is not returned.
|
||||
Logger.Info("NZB already exists on disk: {0)", filename);
|
||||
return true;
|
||||
}
|
||||
|
||||
Logger.Trace("Downloading NZB from: {0} to: {1}", parseResult.NzbUrl, filename);
|
||||
_httpProvider.DownloadFile(parseResult.NzbUrl, filename);
|
||||
|
||||
Logger.Trace("NZB Download succeeded, saved to: {0}", filename);
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Logger.WarnException("Failed to download NZB: " + parseResult.NzbUrl, ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -416,6 +416,12 @@ namespace NzbDrone.Core.Providers.Core
|
|||
set { SetValue("DownloadClient", (int)value); }
|
||||
}
|
||||
|
||||
public virtual string BlackholeDirectory
|
||||
{
|
||||
get { return GetValue("BlackholeDirectory", String.Empty); }
|
||||
set { SetValue("BlackholeDirectory", value); }
|
||||
}
|
||||
|
||||
public string UGuid
|
||||
{
|
||||
get { return GetValue("UGuid", Guid.NewGuid().ToString(), persist: true); }
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using Ninject;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Providers
|
||||
|
@ -12,17 +13,22 @@ namespace NzbDrone.Core.Providers
|
|||
private readonly HistoryProvider _historyProvider;
|
||||
private readonly EpisodeProvider _episodeProvider;
|
||||
private readonly ExternalNotificationProvider _externalNotificationProvider;
|
||||
private readonly ConfigProvider _configProvider;
|
||||
private readonly BlackholeProvider _blackholeProvider;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
[Inject]
|
||||
public DownloadProvider(SabProvider sabProvider, HistoryProvider historyProvider,
|
||||
EpisodeProvider episodeProvider, ExternalNotificationProvider externalNotificationProvider)
|
||||
EpisodeProvider episodeProvider, ExternalNotificationProvider externalNotificationProvider,
|
||||
ConfigProvider configProvider, BlackholeProvider blackholeProvider)
|
||||
{
|
||||
_sabProvider = sabProvider;
|
||||
_historyProvider = historyProvider;
|
||||
_episodeProvider = episodeProvider;
|
||||
_externalNotificationProvider = externalNotificationProvider;
|
||||
_configProvider = configProvider;
|
||||
_blackholeProvider = blackholeProvider;
|
||||
}
|
||||
|
||||
public DownloadProvider()
|
||||
|
@ -31,14 +37,22 @@ namespace NzbDrone.Core.Providers
|
|||
|
||||
public virtual bool DownloadReport(EpisodeParseResult parseResult)
|
||||
{
|
||||
if (_sabProvider.IsInQueue(parseResult))
|
||||
var sabTitle = _sabProvider.GetSabTitle(parseResult);
|
||||
bool addSuccess = false;
|
||||
|
||||
if (_configProvider.DownloadClient == DownloadClientType.Blackhole)
|
||||
addSuccess = _blackholeProvider.DownloadNzb(parseResult, sabTitle);
|
||||
|
||||
if (_configProvider.DownloadClient == DownloadClientType.Sabnzbd)
|
||||
{
|
||||
if(_sabProvider.IsInQueue(parseResult))
|
||||
{
|
||||
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);
|
||||
addSuccess = _sabProvider.AddByUrl(parseResult.NzbUrl, sabTitle);
|
||||
}
|
||||
|
||||
if (addSuccess)
|
||||
{
|
||||
|
|
|
@ -113,6 +113,7 @@ namespace NzbDrone.Web.Controllers
|
|||
DownloadClientDropDirectory = _configProvider.SabDropDirectory,
|
||||
SabTvCategorySelectList = tvCategorySelectList,
|
||||
DownloadClient = (int)_configProvider.DownloadClient,
|
||||
BlackholeDirectory = _configProvider.BlackholeDirectory,
|
||||
DownloadClientSelectList = new SelectList(downloadClientTypes, "Key", "Value")
|
||||
};
|
||||
|
||||
|
@ -393,6 +394,7 @@ namespace NzbDrone.Web.Controllers
|
|||
_configProvider.SabUsername = data.SabUsername;
|
||||
_configProvider.SabTvPriority = data.SabTvPriority;
|
||||
_configProvider.SabDropDirectory = data.DownloadClientDropDirectory;
|
||||
_configProvider.BlackholeDirectory = data.BlackholeDirectory;
|
||||
_configProvider.DownloadClient = (DownloadClientType)data.DownloadClient;
|
||||
|
||||
return GetSuccessResult();
|
||||
|
|
Loading…
Reference in New Issue