Lidarr/src/NzbDrone.Core/Download/Clients/Blackhole/UsenetBlackhole.cs

106 lines
3.5 KiB
C#
Raw Normal View History

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