2018-03-14 20:41:36 +00:00
|
|
|
using System;
|
2013-04-15 01:41:39 +00:00
|
|
|
using System.Collections.Generic;
|
2012-08-30 00:20:48 +00:00
|
|
|
using System.IO;
|
2014-07-04 08:09:48 +00:00
|
|
|
using FluentValidation.Results;
|
2012-08-30 00:20:48 +00:00
|
|
|
using NLog;
|
2014-01-06 06:20:08 +00:00
|
|
|
using NzbDrone.Common.Disk;
|
2014-12-02 06:26:25 +00:00
|
|
|
using NzbDrone.Common.Extensions;
|
2014-05-11 04:37:07 +00:00
|
|
|
using NzbDrone.Common.Http;
|
2013-02-24 06:48:52 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
2014-04-19 15:09:22 +00:00
|
|
|
using NzbDrone.Core.Indexers;
|
2013-03-06 21:20:33 +00:00
|
|
|
using NzbDrone.Core.Organizer;
|
2013-04-15 01:41:39 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Core.RemotePathMappings;
|
2012-08-30 00:20:48 +00:00
|
|
|
|
2014-02-14 05:31:49 +00:00
|
|
|
namespace NzbDrone.Core.Download.Clients.Pneumatic
|
2012-08-30 00:20:48 +00:00
|
|
|
{
|
2014-07-04 08:09:48 +00:00
|
|
|
public class Pneumatic : DownloadClientBase<PneumaticSettings>
|
2012-08-30 00:20:48 +00:00
|
|
|
{
|
2014-09-11 23:49:41 +00:00
|
|
|
private readonly IHttpClient _httpClient;
|
2012-08-30 00:20:48 +00:00
|
|
|
|
2014-09-11 23:49:41 +00:00
|
|
|
public Pneumatic(IHttpClient httpClient,
|
2014-05-27 21:04:13 +00:00
|
|
|
IConfigService configService,
|
2018-04-16 22:22:54 +00:00
|
|
|
INamingConfigService namingConfigService,
|
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)
|
2018-04-16 22:22:54 +00:00
|
|
|
: base(configService, namingConfigService, diskProvider, remotePathMappingService, logger)
|
2012-08-30 00:20:48 +00:00
|
|
|
{
|
2014-09-11 23:49:41 +00:00
|
|
|
_httpClient = httpClient;
|
2012-08-30 00:20:48 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public override string Name => "Pneumatic";
|
2015-04-25 16:22:53 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public override DownloadProtocol Protocol => DownloadProtocol.Usenet;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
2017-02-13 01:07:57 +00:00
|
|
|
public override string Download(RemoteMovie remoteMovie)
|
2017-01-02 18:20:32 +00:00
|
|
|
{
|
2017-02-13 01:07:57 +00:00
|
|
|
var url = remoteMovie.Release.DownloadUrl;
|
|
|
|
var title = remoteMovie.Release.Title;
|
2017-01-02 18:20:32 +00:00
|
|
|
|
2018-03-14 20:41:36 +00:00
|
|
|
// We don't have full seasons in movies.
|
|
|
|
//if (remoteMovie.ParsedEpisodeInfo.FullSeason)
|
|
|
|
//{
|
|
|
|
// throw new NotSupportedException("Full season releases are not supported with Pneumatic.");
|
|
|
|
//}
|
2018-08-05 14:28:05 +00:00
|
|
|
title = FileNameBuilder.CleanFileName(title);
|
2017-01-02 18:20:32 +00:00
|
|
|
|
|
|
|
//Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC)
|
|
|
|
var nzbFile = Path.Combine(Settings.NzbFolder, title + ".nzb");
|
|
|
|
|
|
|
|
_logger.Debug("Downloading NZB from: {0} to: {1}", url, nzbFile);
|
|
|
|
_httpClient.DownloadFile(url, nzbFile);
|
|
|
|
|
|
|
|
_logger.Debug("NZB Download succeeded, saved to: {0}", nzbFile);
|
2013-04-07 19:01:24 +00:00
|
|
|
|
2014-09-01 18:14:54 +00:00
|
|
|
var strmFile = WriteStrmFile(title, nzbFile);
|
2013-10-21 01:30:46 +00:00
|
|
|
|
2015-06-15 04:08:30 +00:00
|
|
|
return GetDownloadClientId(strmFile);
|
2012-08-30 00:20:48 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
public bool IsConfigured => !string.IsNullOrWhiteSpace(Settings.NzbFolder);
|
2013-07-31 05:49:41 +00:00
|
|
|
|
2014-04-19 15:09:22 +00:00
|
|
|
public override IEnumerable<DownloadClientItem> GetItems()
|
2013-04-15 01:41:39 +00:00
|
|
|
{
|
2014-09-01 18:14:54 +00:00
|
|
|
foreach (var file in _diskProvider.GetFiles(Settings.StrmFolder, SearchOption.TopDirectoryOnly))
|
2014-09-01 16:24:17 +00:00
|
|
|
{
|
2014-09-01 18:14:54 +00:00
|
|
|
if (Path.GetExtension(file) != ".strm")
|
2014-09-01 16:24:17 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
var title = FileNameBuilder.CleanFileName(Path.GetFileName(file));
|
2014-09-01 16:24:17 +00:00
|
|
|
|
|
|
|
var historyItem = new DownloadClientItem
|
|
|
|
{
|
2020-03-29 20:05:48 +00:00
|
|
|
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this),
|
2014-12-19 00:26:42 +00:00
|
|
|
DownloadId = GetDownloadClientId(file),
|
2014-09-01 16:24:17 +00:00
|
|
|
Title = title,
|
|
|
|
|
2018-04-05 19:24:21 +00:00
|
|
|
CanBeRemoved = true,
|
|
|
|
CanMoveFiles = true,
|
|
|
|
|
2014-09-01 18:14:54 +00:00
|
|
|
TotalSize = _diskProvider.GetFileSize(file),
|
2014-09-01 16:24:17 +00:00
|
|
|
|
2014-10-12 22:00:03 +00:00
|
|
|
OutputPath = new OsPath(file)
|
2014-09-01 16:24:17 +00:00
|
|
|
};
|
|
|
|
|
2014-09-01 18:14:54 +00:00
|
|
|
if (_diskProvider.IsFileLocked(file))
|
2014-09-01 16:24:17 +00:00
|
|
|
{
|
|
|
|
historyItem.Status = DownloadItemStatus.Downloading;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
historyItem.Status = DownloadItemStatus.Completed;
|
|
|
|
}
|
|
|
|
|
|
|
|
yield return historyItem;
|
|
|
|
}
|
2013-04-15 01:41:39 +00:00
|
|
|
}
|
2014-07-19 17:37:06 +00:00
|
|
|
|
2021-04-20 05:00:33 +00:00
|
|
|
public override void RemoveItem(DownloadClientItem item, bool deleteData)
|
2014-04-01 20:07:41 +00:00
|
|
|
{
|
2014-04-19 15:09:22 +00:00
|
|
|
throw new NotSupportedException();
|
2014-04-01 20:07:41 +00:00
|
|
|
}
|
|
|
|
|
2019-06-14 03:54:25 +00:00
|
|
|
public override DownloadClientInfo GetStatus()
|
2014-06-06 05:55:38 +00:00
|
|
|
{
|
2019-06-14 03:54:25 +00:00
|
|
|
var status = new DownloadClientInfo
|
2014-06-06 05:55:38 +00:00
|
|
|
{
|
|
|
|
IsLocalhost = true
|
|
|
|
};
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-07-09 22:11:57 +00:00
|
|
|
protected override void Test(List<ValidationFailure> failures)
|
2014-02-26 05:40:47 +00:00
|
|
|
{
|
2015-01-21 19:59:03 +00:00
|
|
|
failures.AddIfNotNull(TestFolder(Settings.NzbFolder, "NzbFolder"));
|
|
|
|
failures.AddIfNotNull(TestFolder(Settings.StrmFolder, "StrmFolder"));
|
2014-02-26 05:40:47 +00:00
|
|
|
}
|
2014-09-01 16:24:17 +00:00
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
private string WriteStrmFile(string title, string nzbFile)
|
2014-09-01 16:24:17 +00:00
|
|
|
{
|
|
|
|
if (Settings.StrmFolder.IsNullOrWhiteSpace())
|
|
|
|
{
|
2018-11-23 07:03:32 +00:00
|
|
|
throw new DownloadClientException("Strm Folder needs to be set for Pneumatic Downloader");
|
2014-09-01 16:24:17 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
var contents = string.Format("plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb={0}&nzbname={1}", nzbFile, title);
|
2018-11-23 07:03:32 +00:00
|
|
|
var filename = Path.Combine(Settings.StrmFolder, title + ".strm");
|
2014-09-01 18:14:54 +00:00
|
|
|
|
|
|
|
_diskProvider.WriteAllText(filename, contents);
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
private string GetDownloadClientId(string filename)
|
2014-09-01 18:14:54 +00:00
|
|
|
{
|
2014-10-14 21:31:35 +00:00
|
|
|
return Definition.Name + "_" + Path.GetFileName(filename) + "_" + _diskProvider.FileGetLastWrite(filename).Ticks;
|
2014-09-01 16:24:17 +00:00
|
|
|
}
|
2012-08-30 00:20:48 +00:00
|
|
|
}
|
|
|
|
}
|