2014-04-19 15:09:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2014-09-07 11:37:50 +00:00
|
|
|
|
using System.Collections.Generic;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
using NzbDrone.Common;
|
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
|
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.Indexers;
|
|
|
|
|
using NzbDrone.Core.Organizer;
|
|
|
|
|
using NzbDrone.Core.Parser;
|
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
2014-09-07 11:37:50 +00:00
|
|
|
|
using NLog;
|
|
|
|
|
using Omu.ValueInjecter;
|
|
|
|
|
using FluentValidation.Results;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Download.Clients.UsenetBlackhole
|
|
|
|
|
{
|
2014-07-04 08:09:48 +00:00
|
|
|
|
public class UsenetBlackhole : DownloadClientBase<UsenetBlackholeSettings>
|
2014-04-19 15:09:22 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly IDiskScanService _diskScanService;
|
2014-09-11 23:49:41 +00:00
|
|
|
|
private readonly IHttpClient _httpClient;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
2014-07-04 20:27:21 +00:00
|
|
|
|
public UsenetBlackhole(IDiskScanService diskScanService,
|
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-05-27 21:04:13 +00:00
|
|
|
|
IParsingService parsingService,
|
2014-04-19 15:09:22 +00:00
|
|
|
|
Logger logger)
|
2014-07-04 20:27:21 +00:00
|
|
|
|
: base(configService, diskProvider, parsingService, logger)
|
2014-04-19 15:09:22 +00:00
|
|
|
|
{
|
|
|
|
|
_diskScanService = diskScanService;
|
2014-09-11 23:49:41 +00:00
|
|
|
|
_httpClient = httpClient;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override DownloadProtocol Protocol
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return DownloadProtocol.Usenet;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Download(RemoteEpisode remoteEpisode)
|
|
|
|
|
{
|
|
|
|
|
var url = remoteEpisode.Release.DownloadUrl;
|
|
|
|
|
var title = remoteEpisode.Release.Title;
|
|
|
|
|
|
2014-07-28 21:14:34 +00:00
|
|
|
|
title = FileNameBuilder.CleanFileName(title);
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
|
|
|
|
var filename = Path.Combine(Settings.NzbFolder, title + ".nzb");
|
|
|
|
|
|
|
|
|
|
_logger.Debug("Downloading NZB from: {0} to: {1}", url, filename);
|
2014-09-11 23:49:41 +00:00
|
|
|
|
_httpClient.DownloadFile(url, filename);
|
2014-04-19 15:09:22 +00:00
|
|
|
|
_logger.Debug("NZB Download succeeded, saved to: {0}", filename);
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<DownloadClientItem> GetItems()
|
|
|
|
|
{
|
|
|
|
|
foreach (var folder in _diskProvider.GetDirectories(Settings.WatchFolder))
|
|
|
|
|
{
|
2014-07-28 21:14:34 +00:00
|
|
|
|
var title = FileNameBuilder.CleanFileName(Path.GetFileName(folder));
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
|
|
|
|
var files = _diskProvider.GetFiles(folder, SearchOption.AllDirectories);
|
|
|
|
|
|
|
|
|
|
var historyItem = new DownloadClientItem
|
|
|
|
|
{
|
|
|
|
|
DownloadClient = Definition.Name,
|
|
|
|
|
DownloadClientId = Definition.Name + "_" + Path.GetFileName(folder) + "_" + _diskProvider.FolderGetCreationTimeUtc(folder).Ticks,
|
|
|
|
|
Title = title,
|
|
|
|
|
|
|
|
|
|
TotalSize = files.Select(_diskProvider.GetFileSize).Sum(),
|
|
|
|
|
|
|
|
|
|
OutputPath = folder
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (files.Any(_diskProvider.IsFileLocked))
|
|
|
|
|
{
|
|
|
|
|
historyItem.Status = DownloadItemStatus.Downloading;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
historyItem.Status = DownloadItemStatus.Completed;
|
2014-05-24 10:48:55 +00:00
|
|
|
|
|
|
|
|
|
historyItem.RemainingTime = TimeSpan.Zero;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
historyItem.RemoteEpisode = GetRemoteEpisode(historyItem.Title);
|
|
|
|
|
if (historyItem.RemoteEpisode == null) continue;
|
|
|
|
|
|
|
|
|
|
yield return historyItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var videoFile in _diskScanService.GetVideoFiles(Settings.WatchFolder, false))
|
|
|
|
|
{
|
2014-07-28 21:14:34 +00:00
|
|
|
|
var title = FileNameBuilder.CleanFileName(Path.GetFileName(videoFile));
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
|
|
|
|
var historyItem = new DownloadClientItem
|
|
|
|
|
{
|
|
|
|
|
DownloadClient = Definition.Name,
|
|
|
|
|
DownloadClientId = Definition.Name + "_" + Path.GetFileName(videoFile) + "_" + _diskProvider.FileGetLastWriteUtc(videoFile).Ticks,
|
|
|
|
|
Title = title,
|
|
|
|
|
|
|
|
|
|
TotalSize = _diskProvider.GetFileSize(videoFile),
|
|
|
|
|
|
|
|
|
|
OutputPath = videoFile
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (_diskProvider.IsFileLocked(videoFile))
|
|
|
|
|
{
|
|
|
|
|
historyItem.Status = DownloadItemStatus.Downloading;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
historyItem.Status = DownloadItemStatus.Completed;
|
2014-09-07 11:37:50 +00:00
|
|
|
|
historyItem.RemainingTime = TimeSpan.Zero;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
historyItem.RemoteEpisode = GetRemoteEpisode(historyItem.Title);
|
|
|
|
|
if (historyItem.RemoteEpisode == null) continue;
|
|
|
|
|
|
|
|
|
|
yield return historyItem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-19 17:37:06 +00:00
|
|
|
|
public override void RemoveItem(String id)
|
2014-04-19 15:09:22 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-19 17:37:06 +00:00
|
|
|
|
public override String RetryDownload(String id)
|
2014-04-19 15:09:22 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotSupportedException();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 05:55:38 +00:00
|
|
|
|
public override DownloadClientStatus GetStatus()
|
|
|
|
|
{
|
|
|
|
|
return new DownloadClientStatus
|
|
|
|
|
{
|
|
|
|
|
IsLocalhost = true,
|
|
|
|
|
OutputRootFolders = new List<string> { Settings.WatchFolder }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|