mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-26 09:47:39 +00:00
70fd11231d
Will send from SAB to NzbDrone. Changed SabCategory to SabTvCategory (Support for movies later?)
84 lines
2.5 KiB
C#
84 lines
2.5 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|