Lidarr/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs

113 lines
3.5 KiB
C#
Raw Normal View History

2012-08-30 00:20:48 +00:00
using System;
using System.Collections.Generic;
2012-08-30 00:20:48 +00:00
using System.IO;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Http;
2013-08-31 01:42:30 +00:00
using NzbDrone.Common.Instrumentation;
2013-02-24 06:48:52 +00:00
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Organizer;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
2012-08-30 00:20:48 +00:00
namespace NzbDrone.Core.Download.Clients.Pneumatic
2012-08-30 00:20:48 +00:00
{
public class Pneumatic : DownloadClientBase<PneumaticSettings>, IExecute<TestPneumaticCommand>
2012-08-30 00:20:48 +00:00
{
2013-02-24 06:48:52 +00:00
private readonly IConfigService _configService;
2013-04-10 23:41:45 +00:00
private readonly IHttpProvider _httpProvider;
2013-05-10 23:53:50 +00:00
private readonly IDiskProvider _diskProvider;
2012-08-30 00:20:48 +00:00
2013-08-31 01:42:30 +00:00
private static readonly Logger logger = NzbDroneLogger.GetLogger();
2012-08-30 00:20:48 +00:00
public Pneumatic(IConfigService configService,
IHttpProvider httpProvider,
IDiskProvider diskProvider,
IParsingService parsingService,
Logger logger)
: base(parsingService, logger)
2012-08-30 00:20:48 +00:00
{
2013-02-24 06:48:52 +00:00
_configService = configService;
2012-08-30 00:20:48 +00:00
_httpProvider = httpProvider;
_diskProvider = diskProvider;
}
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-08-17 23:27:18 +00:00
if (remoteEpisode.ParsedEpisodeInfo.FullSeason)
2012-08-30 00:20:48 +00:00
{
throw new NotSupportedException("Full season releases are not supported with Pneumatic.");
2013-08-17 23:27:18 +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)
var filename = Path.Combine(Settings.NzbFolder, title + ".nzb");
2012-08-30 00:20:48 +00:00
2014-03-13 20:12:42 +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-03-13 20:12:42 +00:00
logger.Debug("NZB Download succeeded, saved to: {0}", filename);
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);
return null;
2012-08-30 00:20:48 +00:00
}
public bool IsConfigured
{
get
{
return !string.IsNullOrWhiteSpace(Settings.NzbFolder);
}
}
public override IEnumerable<DownloadClientItem> GetItems()
{
return new DownloadClientItem[0];
}
public override void RemoveItem(string id)
{
throw new NotSupportedException();
}
public override void RetryDownload(string id)
{
throw new NotSupportedException();
}
2014-02-26 05:40:47 +00:00
public override void Test()
{
PerformTest(Settings.NzbFolder);
2014-02-26 05:40:47 +00:00
}
private void PerformTest(string folder)
2012-08-30 00:20:48 +00:00
{
2014-02-26 05:40:47 +00:00
var testPath = Path.Combine(folder, "drone_test.txt");
_diskProvider.WriteAllText(testPath, DateTime.Now.ToString());
_diskProvider.DeleteFile(testPath);
2012-08-30 00:20:48 +00:00
}
2014-02-26 05:40:47 +00:00
public void Execute(TestPneumaticCommand message)
{
PerformTest(message.Folder);
}
2012-08-30 00:20:48 +00:00
}
}