Post Processor Done.

Will send from SAB to NzbDrone.
Changed SabCategory to SabTvCategory (Support for movies later?)
pull/7/merge
markus101 14 years ago
parent e166cb1b2d
commit 70fd11231d

@ -34,7 +34,7 @@ namespace NzbDrone.Core.Test
config.Setup(c => c.GetValue("SabUsername", String.Empty, false)).Returns(username);
config.Setup(c => c.GetValue("SabPassword", String.Empty, false)).Returns(password);
config.Setup(c => c.GetValue("SabPriority", String.Empty, false)).Returns(priority);
config.Setup(c => c.GetValue("SabCategory", String.Empty, false)).Returns(category);
config.Setup(c => c.GetValue("SabTvCategory", String.Empty, false)).Returns(category);
var http = new Mock<IHttpProvider>();
http.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=addurl&name=http://www.nzbclub.com/nzb_download.aspx?mid=1950232&priority=0&cat=tv&nzbname=This+is+an+Nzb&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")).Returns("ok");
@ -67,7 +67,7 @@ namespace NzbDrone.Core.Test
config.Setup(c => c.GetValue("SabUsername", String.Empty, false)).Returns(username);
config.Setup(c => c.GetValue("SabPassword", String.Empty, false)).Returns(password);
config.Setup(c => c.GetValue("SabPriority", String.Empty, false)).Returns(priority);
config.Setup(c => c.GetValue("SabCategory", String.Empty, false)).Returns(category);
config.Setup(c => c.GetValue("SabTvCategory", String.Empty, false)).Returns(category);
var http = new Mock<IHttpProvider>();
http.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=addurl&name=http://www.nzbclub.com/nzb_download.aspx?mid=1950232&priority=0&cat=tv&nzbname=This+is+an+Nzb&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass")).Returns("error");

@ -24,7 +24,7 @@ namespace NzbDrone.Core.Providers
public bool AddByUrl(string url, string title)
{
const string mode = "addurl";
//string cat = _config.GetValue("SabCategory", String.Empty, true);
//string cat = _config.GetValue("SabTvCategory", String.Empty, true);
string cat = "tv";
string priority = _config.GetValue("SabPriority", String.Empty, false);
string name = url.Replace("&", "%26");

@ -10,8 +10,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NzbDrone.PostProcessor</RootNamespace>
<AssemblyName>NzbDrone.PostProcessor</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
@ -36,11 +37,15 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="PostProcessor.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<Host>localhost</Host>
<Port>8989</Port>
<ApiKey>Not-An-API-KEY</ApiKey>
</Configuration>

@ -1,13 +1,84 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace NzbDrone.PostProcessor
{
class Program
{
private static string _host = "localhost";
private static int _port = 8989;
private static string _apiKey = String.Empty;
static void Main(string[] args)
{
try
{
if (args.Count() < 5)
{
Console.WriteLine("Did this come from SAB? Missing Arguments..");
return;
}
//Load the ConfigFile
if (!LoadConfig())
return;
string dir = args[0]; //Get dir from first CMD Line Argument
string nzbName = args[2]; //Get nzbName from third CMD Line Argument
string category = args[4]; //Get category from third CMD Line Argument
var hostString = _host + ":" + _port;
var url = String.Format("http://{0}/?apiKey={1}&dir={2}&nzbName={3}&category={4}", hostString, _apiKey, dir, nzbName, category);
var webClient = new WebClient();
webClient.DownloadString(url);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
static bool LoadConfig()
{
var configFile = "PostProcessor.xml";
if (!File.Exists(configFile))
{
Console.WriteLine("Configuration File does not exist, please create");
return false;
}
var xDoc = XDocument.Load(configFile);
var config = (from c in xDoc.Descendants("Configuration") select c).FirstOrDefault();
if (config == null)
{
Console.WriteLine("Invalid Configuration File");
return false;
}
var hostNode = config.Descendants("Host").FirstOrDefault();
var portNode = config.Descendants("Port").FirstOrDefault(); ;
var apiKeyNode = config.Descendants("ApiKey").FirstOrDefault(); ;
if (hostNode == null || portNode == null || apiKeyNode == null)
{
Console.WriteLine("Invalid Configuration File");
return false;
}
_host = hostNode.Value;
Int32.TryParse(portNode.Value, out _port);
_apiKey = apiKeyNode.Value;
return true;
}
}
}

@ -4,6 +4,7 @@ using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Xml.Linq;
using NLog;
using NzbDrone.Core;
using NzbDrone.Core.Providers;
@ -12,16 +13,31 @@ namespace NzbDrone.Web.Controllers
public class ApiController : Controller
{
private readonly IPostProcessingProvider _postProcessingProvider;
private readonly IConfigProvider _configProvider;
public ApiController(IPostProcessingProvider postProcessingProvider)
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public ApiController(IPostProcessingProvider postProcessingProvider, IConfigProvider configProvider)
{
_postProcessingProvider = postProcessingProvider;
_configProvider = configProvider;
}
public ActionResult ProcessEpisode(string dir, string nzbName)
public ActionResult ProcessEpisode(string apiKey, string dir, string nzbName, string category)
{
_postProcessingProvider.ProcessEpisode(dir, nzbName);
return Content("ok");
if (apiKey != _configProvider.GetValue("ApiKey", String.Empty, true))
{
Logger.Warn("API Key from Post Processing Script is Invalid");
return Content("Invalid API Key");
}
if (_configProvider.GetValue("SabTvCategory", String.Empty, true) == category)
{
_postProcessingProvider.ProcessEpisode(dir, nzbName);
return Content("ok");
}
return Content("Category doesn't match what was configured for SAB TV Category...");
}
}
}

@ -60,12 +60,12 @@ namespace NzbDrone.Web.Controllers
ViewData["viewName"] = "Indexers";
return View("Index", new IndexerSettingsModel
{
NzbMatrixUsername = _configProvider.GetValue("NzbMatrixUsername", String.Empty, false),
NzbMatrixApiKey = _configProvider.GetValue("NzbMatrixApiKey", String.Empty, false),
NzbsOrgUId = _configProvider.GetValue("NzbsOrgUId", String.Empty, false),
NzbsOrgHash = _configProvider.GetValue("NzbsOrgHash", String.Empty, false),
NzbsrusUId = _configProvider.GetValue("NzbsrusUId", String.Empty, false),
NzbsrusHash = _configProvider.GetValue("NzbsrusHash", String.Empty, false),
NzbMatrixUsername = _configProvider.GetValue("NzbMatrixUsername", String.Empty, true),
NzbMatrixApiKey = _configProvider.GetValue("NzbMatrixApiKey", String.Empty, true),
NzbsOrgUId = _configProvider.GetValue("NzbsOrgUId", String.Empty, true),
NzbsOrgHash = _configProvider.GetValue("NzbsOrgHash", String.Empty, true),
NzbsrusUId = _configProvider.GetValue("NzbsrusUId", String.Empty, true),
NzbsrusHash = _configProvider.GetValue("NzbsrusHash", String.Empty, true),
Indexers = _indexerProvider.AllIndexers()
});
}
@ -79,12 +79,12 @@ namespace NzbDrone.Web.Controllers
SyncFrequency = Convert.ToInt32(_configProvider.GetValue("SyncFrequency", "15", true)),
DownloadPropers = Convert.ToBoolean(_configProvider.GetValue("DownloadPropers", "false", true)),
Retention = Convert.ToInt32(_configProvider.GetValue("Retention", "500", true)),
SabHost = _configProvider.GetValue("SabHost", "localhost", false),
SabHost = _configProvider.GetValue("SabHost", "localhost", true),
SabPort = Convert.ToInt32(_configProvider.GetValue("SabPort", "8080", true)),
SabApiKey = _configProvider.GetValue("SabApiKey", String.Empty, false),
SabUsername = _configProvider.GetValue("SabUsername", String.Empty, false),
SabPassword = _configProvider.GetValue("SabPassword", String.Empty, false),
SabCategory = _configProvider.GetValue("SabCategory", String.Empty, false),
SabApiKey = _configProvider.GetValue("SabApiKey", String.Empty, true),
SabUsername = _configProvider.GetValue("SabUsername", String.Empty, true),
SabPassword = _configProvider.GetValue("SabPassword", String.Empty, true),
SabTvCategory = _configProvider.GetValue("SabTvCategory", String.Empty, true),
SabPriority = (SabnzbdPriorityType)Enum.Parse(typeof(SabnzbdPriorityType), _configProvider.GetValue("SabPriority", "Normal", true)),
};
@ -221,7 +221,7 @@ namespace NzbDrone.Web.Controllers
_configProvider.SetValue("SabApiKey", data.SabApiKey);
_configProvider.SetValue("SabUsername", data.SabUsername);
_configProvider.SetValue("SabPassword", data.SabPassword);
_configProvider.SetValue("SabCategory", data.SabCategory);
_configProvider.SetValue("SabTvCategory", data.SabTvCategory);
_configProvider.SetValue("SabPriority", data.SabPriority.ToString());
return Content(_settingsSaved);

@ -84,8 +84,8 @@ namespace NzbDrone.Web.Models
[DataType(DataType.Text)]
[DisplayFormat(ConvertEmptyStringToNull = false)]
[DisplayName("SABnzbd Category")]
public String SabCategory
[DisplayName("SABnzbd TV Category")]
public String SabTvCategory
{
get;
set;

@ -117,10 +117,10 @@
<div class="config-section">
<div class="config-group">
<div class="config-title"><%= Html.LabelFor(m => m.SabCategory)%></div>
<div class="config-value"><%= Html.TextBoxFor(m => m.SabCategory)%></div>
<div class="config-title"><%= Html.LabelFor(m => m.SabTvCategory)%></div>
<div class="config-value"><%= Html.TextBoxFor(m => m.SabTvCategory)%></div>
</div>
<div class="config-validation"><%= Html.ValidationMessageFor(m => m.SabCategory)%></div>
<div class="config-validation"><%= Html.ValidationMessageFor(m => m.SabTvCategory)%></div>
</div>
<div class="config-section">
@ -128,7 +128,7 @@
<div class="config-title"><%= Html.LabelFor(m => m.SabPriority) %></div>
<div class="config-value"><%= Html.DropDownListFor(m => m.SabPriority, Model.PrioritySelectList) %></div>
</div>
<div class="config-validation"><%= Html.ValidationMessageFor(m => m.SabCategory)%></div>
<div class="config-validation"><%= Html.ValidationMessageFor(m => m.SabTvCategory)%></div>
</div>
</fieldset>

Loading…
Cancel
Save