mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
SabController - Removed AddByPath, Completed AddByUrl and IsInQueue
Created SabControllerTest - Added AddByPath Test (Needs more work) Added, Episode, FeedItem, ItemInfo and Site classes to store information
This commit is contained in:
parent
f5cf44c2b3
commit
a427f9c16d
9 changed files with 329 additions and 15 deletions
|
@ -1,37 +1,108 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using log4net;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml;
|
||||
using NzbDrone.Core.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Controllers
|
||||
{
|
||||
public class SabController : IDownloadClientController
|
||||
{
|
||||
private readonly IConfigController _config;
|
||||
private readonly ILog _logger;
|
||||
|
||||
public SabController(IConfigController config)
|
||||
public SabController(IConfigController config, ILog logger)
|
||||
{
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public string AddByUrl(string url)
|
||||
#region IDownloadClientController Members
|
||||
|
||||
public bool AddByUrl(ItemInfo nzb)
|
||||
{
|
||||
|
||||
const string mode = "addurl";
|
||||
const string cat = "tv";
|
||||
string name = nzb.Link.ToString().Replace("&", "%26");
|
||||
string nzbName = CleanUrlString(nzb.Title);
|
||||
|
||||
return "";
|
||||
}
|
||||
string action = string.Format("mode={0}&name={1}&cat={2}&nzbname={3}", mode, name, cat, nzbName);
|
||||
string request = GetSabRequest(action);
|
||||
|
||||
public string AddByPath(string path)
|
||||
{
|
||||
_logger.DebugFormat("Adding report [{0}] to the queue.", nzbName);
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public bool IsInQueue(string goodName)
|
||||
{
|
||||
if (SendRequest(request) == "ok")
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsInQueue(Episode epsiode)
|
||||
{
|
||||
string action = "mode=queue&output=xml";
|
||||
|
||||
XDocument xDoc = XDocument.Load(action);
|
||||
|
||||
//If an Error Occurred, retuyrn
|
||||
if (xDoc.Descendants("error").Count() != 0)
|
||||
return false;
|
||||
|
||||
if (xDoc.Descendants("queue").Count() == 0)
|
||||
return false;
|
||||
|
||||
//Get the Count of Items in Queue where 'filename' is Equal to goodName, if not zero, return true (isInQueue)
|
||||
if ((from s in xDoc.Descendants("slot") where s.Element("filename").ToString().Equals(epsiode.FeedItem.TitleFix, StringComparison.InvariantCultureIgnoreCase) select s).Count() != 0)
|
||||
{
|
||||
_logger.DebugFormat("Episode in queue - '{0}'", epsiode.FeedItem.TitleFix);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; //Not in Queue
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string GetSabRequest(string action)
|
||||
{
|
||||
string sabnzbdInfo = _config.GetValue("SabnzbdInfo", String.Empty, false);
|
||||
string username = _config.GetValue("Username", String.Empty, false);
|
||||
string password = _config.GetValue("Password", String.Empty, false);
|
||||
string apiKey = _config.GetValue("ApiKey", String.Empty, false);
|
||||
string priority = _config.GetValue("Priority", String.Empty, false);
|
||||
|
||||
return string.Format(
|
||||
@"http://{0}/sabnzbd/api?$Action&priority={1}&apikey={2}&ma_username={3}&ma_password={4}",
|
||||
sabnzbdInfo, priority, apiKey, username, password).Replace("$Action", action);
|
||||
}
|
||||
|
||||
private string SendRequest(string request)
|
||||
{
|
||||
var webClient = new WebClient();
|
||||
string response = webClient.DownloadString(request).Replace("\n", String.Empty);
|
||||
_logger.DebugFormat("Queue Repsonse: [{0}]", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
private string CleanUrlString(string name)
|
||||
{
|
||||
string result = name;
|
||||
string[] badCharacters =
|
||||
{
|
||||
"%", "<", ">", "#", "{", "}", "|", "\\", "^", "`", "[", "]", "`", ";", "/", "?",
|
||||
":", "@", "=", "&", "$"
|
||||
};
|
||||
string[] goodCharacters =
|
||||
{
|
||||
"%25", "%3C", "%3E", "%23", "%7B", "%7D", "%7C", "%5C", "%5E", "%7E", "%5B",
|
||||
"%5D", "%60", "%3B", "%2F", "%3F", "%3A", "%40", "%3D", "%26", "%24"
|
||||
};
|
||||
|
||||
return result.Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue