2014-04-19 15:09:22 +00:00
|
|
|
|
using System;
|
2015-03-14 10:13:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
using System.IO;
|
2015-03-14 10:13:35 +00:00
|
|
|
|
using FluentValidation.Results;
|
|
|
|
|
using NLog;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
using NzbDrone.Common.Disk;
|
2014-12-02 06:26:25 +00:00
|
|
|
|
using NzbDrone.Common.Extensions;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
using NzbDrone.Common.Http;
|
2014-05-27 21:04:13 +00:00
|
|
|
|
using NzbDrone.Core.Configuration;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
using NzbDrone.Core.Organizer;
|
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2014-09-11 20:24:00 +00:00
|
|
|
|
using NzbDrone.Core.RemotePathMappings;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
2016-02-14 16:55:32 +00:00
|
|
|
|
namespace NzbDrone.Core.Download.Clients.Blackhole
|
2014-04-19 15:09:22 +00:00
|
|
|
|
{
|
2015-03-14 10:13:35 +00:00
|
|
|
|
public class UsenetBlackhole : UsenetClientBase<UsenetBlackholeSettings>
|
2014-04-19 15:09:22 +00:00
|
|
|
|
{
|
2016-02-14 16:55:32 +00:00
|
|
|
|
private readonly IScanWatchFolder _scanWatchFolder;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
2016-02-14 16:55:32 +00:00
|
|
|
|
public TimeSpan ScanGracePeriod { get; set; }
|
|
|
|
|
|
|
|
|
|
public UsenetBlackhole(IScanWatchFolder scanWatchFolder,
|
2014-09-11 23:49:41 +00:00
|
|
|
|
IHttpClient httpClient,
|
2014-05-27 21:04:13 +00:00
|
|
|
|
IConfigService configService,
|
2014-07-04 20:27:21 +00:00
|
|
|
|
IDiskProvider diskProvider,
|
2014-09-11 20:24:00 +00:00
|
|
|
|
IRemotePathMappingService remotePathMappingService,
|
2014-04-19 15:09:22 +00:00
|
|
|
|
Logger logger)
|
2015-03-14 10:13:35 +00:00
|
|
|
|
: base(httpClient, configService, diskProvider, remotePathMappingService, logger)
|
2014-04-19 15:09:22 +00:00
|
|
|
|
{
|
2016-02-14 16:55:32 +00:00
|
|
|
|
_scanWatchFolder = scanWatchFolder;
|
|
|
|
|
|
|
|
|
|
ScanGracePeriod = TimeSpan.FromSeconds(30);
|
2014-04-19 15:09:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-14 02:58:42 +00:00
|
|
|
|
protected override string AddFromNzbFile(RemoteAlbum remoteAlbum, string filename, byte[] fileContent)
|
2014-04-19 15:09:22 +00:00
|
|
|
|
{
|
2017-08-14 02:58:42 +00:00
|
|
|
|
var title = remoteAlbum.Release.Title;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
2014-07-28 21:14:34 +00:00
|
|
|
|
title = FileNameBuilder.CleanFileName(title);
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
2015-03-14 10:13:35 +00:00
|
|
|
|
var filepath = Path.Combine(Settings.NzbFolder, title + ".nzb");
|
|
|
|
|
|
|
|
|
|
using (var stream = _diskProvider.OpenWriteStream(filepath))
|
|
|
|
|
{
|
|
|
|
|
stream.Write(fileContent, 0, fileContent.Length);
|
|
|
|
|
}
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
2015-03-14 10:13:35 +00:00
|
|
|
|
_logger.Debug("NZB Download succeeded, saved to: {0}", filepath);
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
|
public override string Name => "Usenet Blackhole";
|
2015-04-25 16:22:53 +00:00
|
|
|
|
|
2014-04-19 15:09:22 +00:00
|
|
|
|
public override IEnumerable<DownloadClientItem> GetItems()
|
|
|
|
|
{
|
2016-02-14 16:55:32 +00:00
|
|
|
|
foreach (var item in _scanWatchFolder.GetItems(Settings.WatchFolder, ScanGracePeriod))
|
2014-04-19 15:09:22 +00:00
|
|
|
|
{
|
2016-02-14 16:55:32 +00:00
|
|
|
|
yield return new DownloadClientItem
|
2014-04-19 15:09:22 +00:00
|
|
|
|
{
|
|
|
|
|
DownloadClient = Definition.Name,
|
2016-02-14 16:55:32 +00:00
|
|
|
|
DownloadId = Definition.Name + "_" + item.DownloadId,
|
2017-03-30 03:49:38 +00:00
|
|
|
|
Category = "Lidarr",
|
2016-02-14 16:55:32 +00:00
|
|
|
|
Title = item.Title,
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
2016-02-14 16:55:32 +00:00
|
|
|
|
TotalSize = item.TotalSize,
|
|
|
|
|
RemainingTime = item.RemainingTime,
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
2016-02-14 16:55:32 +00:00
|
|
|
|
OutputPath = item.OutputPath,
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
2016-02-14 16:55:32 +00:00
|
|
|
|
Status = item.Status
|
2014-04-19 15:09:22 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-23 01:17:48 +00:00
|
|
|
|
public override void RemoveItem(string downloadId, bool deleteData)
|
2014-04-19 15:09:22 +00:00
|
|
|
|
{
|
2015-01-19 22:25:04 +00:00
|
|
|
|
if (!deleteData)
|
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException("Blackhole cannot remove DownloadItem without deleting the data as well, ignoring.");
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-01 22:19:15 +00:00
|
|
|
|
DeleteItemData(downloadId);
|
2014-04-19 15:09:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 05:55:38 +00:00
|
|
|
|
public override DownloadClientStatus GetStatus()
|
|
|
|
|
{
|
|
|
|
|
return new DownloadClientStatus
|
|
|
|
|
{
|
|
|
|
|
IsLocalhost = true,
|
2014-10-12 22:00:03 +00:00
|
|
|
|
OutputRootFolders = new List<OsPath> { new OsPath(Settings.WatchFolder) }
|
2014-06-06 05:55:38 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-09 22:11:57 +00:00
|
|
|
|
protected override void Test(List<ValidationFailure> failures)
|
2014-06-12 21:46:08 +00:00
|
|
|
|
{
|
2014-07-04 20:27:21 +00:00
|
|
|
|
failures.AddIfNotNull(TestFolder(Settings.NzbFolder, "NzbFolder"));
|
|
|
|
|
failures.AddIfNotNull(TestFolder(Settings.WatchFolder, "WatchFolder"));
|
2014-04-19 15:09:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|