1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2025-11-06 09:19:38 +02:00

Start of AutoConfigureSab

This commit is contained in:
Mark McDowall
2011-04-25 00:42:29 -07:00
parent ea2e520632
commit a34bd818cf
13 changed files with 768 additions and 906 deletions

View File

@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers
{
public class AutoConfigureProvider
{
private HttpProvider _httpProvider;
private ConfigProvider _configProvider;
public AutoConfigureProvider(HttpProvider httpProvider, ConfigProvider configProvider)
{
_httpProvider = httpProvider;
_configProvider = configProvider;
}
public SabnzbdInfoModel AutoConfigureSab(string username, string password)
{
//Get Output from Netstat
var netStatOutput = String.Empty;
//var port = GetSabnzbdPort(netStatOutput);
var port = 2222;
var apiKey = GetSabnzbdApiKey(port);
if (port > 0 && !String.IsNullOrEmpty(apiKey))
{
return new SabnzbdInfoModel
{
ApiKey = apiKey,
Port = port,
Username = username,
Password = password
};
}
return null;
}
private int GetSabnzbdPort(string netstatOutput)
{
Regex regex = new Regex(@"^(?:TCP\W+127.0.0.1:(?<port>\d+\W+).+?\r\n\W+\[sabnzbd.exe\])", RegexOptions.IgnoreCase
| RegexOptions.Compiled);
var match = regex.Match(netstatOutput);
var port = 0;
Int32.TryParse(match.Groups["port"].Value, out port);
return port;
}
private string GetSabnzbdApiKey(int port, string ipAddress = "127.0.0.1")
{
var request = String.Format("http://{0}:{1}/config/general/", ipAddress, port);
var result = _httpProvider.DownloadString(request);
Regex regex = new Regex("\\<input\\Wtype\\=\\\"text\\\"\\Wid\\=\\\"apikey\\\"\\Wvalue\\=\\\"(?<apikey>\\w+)\\W", RegexOptions.IgnoreCase
| RegexOptions.Compiled);
var match = regex.Match(result);
return match.Groups["apikey"].Value;
}
}
}

View File

@@ -61,13 +61,13 @@ namespace NzbDrone.Core.Providers.Indexer
/// </summary>
public void Fetch()
{
_logger.Info("Fetching feeds from " + Settings.Name);
_logger.Debug("Fetching feeds from " + Settings.Name);
foreach (var url in Urls)
{
try
{
_logger.Debug("Downloading RSS " + url);
_logger.Trace("Downloading RSS " + url);
var feed = SyndicationFeed.Load(_httpProvider.DownloadXml(url)).Items;
foreach (var item in feed)
@@ -130,7 +130,7 @@ namespace NzbDrone.Core.Providers.Indexer
{
return;
}
var sabTitle = _sabProvider.GetSabTitle(parseResult);
if (_sabProvider.IsInQueue(sabTitle))

View File

@@ -78,7 +78,6 @@ namespace NzbDrone.Core.Providers.Jobs
try
{
Logger.Trace("Getting list of jobs needing to be executed");
var pendingJobs = All().Where(
t => t.Enable &&
@@ -114,16 +113,14 @@ namespace NzbDrone.Core.Providers.Jobs
{
if (_isRunning)
{
Logger.Info("Another instance of this job is already running. Ignoring request.");
Logger.Info("Another job is already running. Ignoring request.");
return false;
}
_isRunning = true;
}
Logger.Info("User has requested a manual execution of {0}", jobType.Name);
if (_jobThread == null || !_jobThread.IsAlive)
{
Logger.Debug("Initializing background thread");
Logger.Trace("Initializing background thread");
ThreadStart starter = () =>
{
@@ -170,7 +167,7 @@ namespace NzbDrone.Core.Providers.Jobs
{
try
{
Logger.Info("Starting job '{0}'. Last execution {1}", settings.Name, settings.LastExecution);
Logger.Debug("Starting job '{0}'. Last execution {1}", settings.Name, settings.LastExecution);
settings.LastExecution = DateTime.Now;
var sw = Stopwatch.StartNew();
@@ -180,7 +177,7 @@ namespace NzbDrone.Core.Providers.Jobs
settings.Success = true;
sw.Stop();
Logger.Info("Job '{0}' successfully completed in {1} seconds", timerClass.Name, sw.Elapsed.Minutes,
Logger.Debug("Job '{0}' successfully completed in {1} seconds", timerClass.Name, sw.Elapsed.Minutes,
sw.Elapsed.Seconds);
}
catch (Exception e)
@@ -201,7 +198,7 @@ namespace NzbDrone.Core.Providers.Jobs
/// </summary>
public virtual void Initialize()
{
Logger.Info("Initializing jobs. Count {0}", _jobs.Count());
Logger.Debug("Initializing jobs. Count {0}", _jobs.Count());
var currentTimer = All();
foreach (var timer in _jobs)