2012-08-30 00:20:48 +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;
|
|
|
|
|
using NzbDrone.Common;
|
2014-01-06 06:20:08 +00:00
|
|
|
|
using NzbDrone.Common.Disk;
|
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;
|
2014-04-19 15:09:22 +00:00
|
|
|
|
using NzbDrone.Core.Parser;
|
2013-04-15 01:41:39 +00:00
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
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
|
|
|
|
{
|
2013-04-10 23:41:45 +00:00
|
|
|
|
private readonly IHttpProvider _httpProvider;
|
2012-08-30 00:20:48 +00:00
|
|
|
|
|
2014-05-27 21:04:13 +00:00
|
|
|
|
public Pneumatic(IHttpProvider httpProvider,
|
|
|
|
|
IConfigService configService,
|
2014-07-04 20:27:21 +00:00
|
|
|
|
IDiskProvider diskProvider,
|
2014-04-19 15:09:22 +00:00
|
|
|
|
IParsingService parsingService,
|
|
|
|
|
Logger logger)
|
2014-07-04 20:27:21 +00:00
|
|
|
|
: base(configService, diskProvider, parsingService, logger)
|
2012-08-30 00:20:48 +00:00
|
|
|
|
{
|
|
|
|
|
_httpProvider = httpProvider;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-19 15:09:22 +00:00
|
|
|
|
public override DownloadProtocol Protocol
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return DownloadProtocol.Usenet;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Download(RemoteEpisode remoteEpisode)
|
2012-08-30 00:20:48 +00:00
|
|
|
|
{
|
2013-09-13 23:17:58 +00:00
|
|
|
|
var url = remoteEpisode.Release.DownloadUrl;
|
|
|
|
|
var title = remoteEpisode.Release.Title;
|
2013-07-08 03:15:15 +00:00
|
|
|
|
|
2013-08-17 23:27:18 +00:00
|
|
|
|
if (remoteEpisode.ParsedEpisodeInfo.FullSeason)
|
2012-08-30 00:20:48 +00:00
|
|
|
|
{
|
2014-04-19 15:09:22 +00:00
|
|
|
|
throw new NotSupportedException("Full season releases are not supported with Pneumatic.");
|
2013-08-17 23:27:18 +00:00
|
|
|
|
}
|
2012-11-19 02:17:00 +00:00
|
|
|
|
|
2013-08-17 23:27:18 +00:00
|
|
|
|
title = FileNameBuilder.CleanFilename(title);
|
2012-08-30 00:20:48 +00:00
|
|
|
|
|
2013-08-17 23:27:18 +00:00
|
|
|
|
//Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC)
|
2014-05-25 21:58:41 +00:00
|
|
|
|
var filename = Path.Combine(Settings.NzbFolder, title + ".nzb");
|
2012-08-30 00:20:48 +00:00
|
|
|
|
|
2014-07-04 08:09:48 +00:00
|
|
|
|
_logger.Debug("Downloading NZB from: {0} to: {1}", url, filename);
|
2013-08-17 23:27:18 +00:00
|
|
|
|
_httpProvider.DownloadFile(url, filename);
|
2012-08-30 00:20:48 +00:00
|
|
|
|
|
2014-07-04 08:09:48 +00:00
|
|
|
|
_logger.Debug("NZB Download succeeded, saved to: {0}", filename);
|
2013-04-07 19:01:24 +00:00
|
|
|
|
|
2013-08-17 23:27:18 +00:00
|
|
|
|
var contents = String.Format("plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb={0}&nzbname={1}", filename, title);
|
|
|
|
|
_diskProvider.WriteAllText(Path.Combine(_configService.DownloadedEpisodesFolder, title + ".strm"), contents);
|
2013-10-21 01:30:46 +00:00
|
|
|
|
|
|
|
|
|
return null;
|
2012-08-30 00:20:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-31 05:49:41 +00:00
|
|
|
|
public bool IsConfigured
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-05-25 21:58:41 +00:00
|
|
|
|
return !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-04-19 15:09:22 +00:00
|
|
|
|
return new DownloadClientItem[0];
|
2013-04-15 01:41:39 +00:00
|
|
|
|
}
|
2014-04-19 15:09:22 +00:00
|
|
|
|
|
|
|
|
|
public override void RemoveItem(string id)
|
2013-10-25 05:55:32 +00:00
|
|
|
|
{
|
2014-04-19 15:09:22 +00:00
|
|
|
|
throw new NotSupportedException();
|
2013-10-25 05:55:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-01 20:07:41 +00:00
|
|
|
|
public override void RetryDownload(string id)
|
|
|
|
|
{
|
2014-04-19 15:09:22 +00:00
|
|
|
|
throw new NotSupportedException();
|
2014-04-01 20:07:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 05:55:38 +00:00
|
|
|
|
public override DownloadClientStatus GetStatus()
|
|
|
|
|
{
|
|
|
|
|
var status = new DownloadClientStatus
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
{
|
2014-07-04 08:09:48 +00:00
|
|
|
|
failures.AddIfNotNull(TestWrite(Settings.NzbFolder, "NzbFolder"));
|
2012-08-30 00:20:48 +00:00
|
|
|
|
}
|
2014-02-26 05:40:47 +00:00
|
|
|
|
|
2014-07-04 08:09:48 +00:00
|
|
|
|
private ValidationFailure TestWrite(String folder, String propertyName)
|
2014-02-26 05:40:47 +00:00
|
|
|
|
{
|
2014-07-04 08:09:48 +00:00
|
|
|
|
if (!_diskProvider.FolderExists(folder))
|
|
|
|
|
{
|
|
|
|
|
return new ValidationFailure(propertyName, "Folder does not exist");
|
|
|
|
|
}
|
2014-06-12 21:46:08 +00:00
|
|
|
|
|
2014-07-04 08:09:48 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var testPath = Path.Combine(folder, "drone_test.txt");
|
|
|
|
|
_diskProvider.WriteAllText(testPath, DateTime.Now.ToString());
|
|
|
|
|
_diskProvider.DeleteFile(testPath);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException(ex.Message, ex);
|
|
|
|
|
return new ValidationFailure(propertyName, "Unable to write to folder");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
2014-02-26 05:40:47 +00:00
|
|
|
|
}
|
2012-08-30 00:20:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|