Merge conflicts resolved.

Added Language parsing.
This commit is contained in:
Mark McDowall 2011-05-08 23:16:26 -07:00
commit 11b96afd75
13 changed files with 603 additions and 134 deletions

View File

@ -135,8 +135,6 @@ namespace NzbDrone.Core.Test
//Constants //Constants
const string fileName = @"WEEDS.S03E01.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi"; const string fileName = @"WEEDS.S03E01.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi";
const int seasonNumber = 3;
const int episodeNumner = 1;
const int size = 12345; const int size = 12345;
//Fakes //Fakes

View File

@ -32,22 +32,22 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = mocker.GetMock<ConfigProvider>();
fakeConfig.Setup(c => c.SabHost) fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost); .Returns(sabHost);
fakeConfig.Setup(c => c.SabPort) fakeConfig.SetupGet(c => c.SabPort)
.Returns(sabPort); .Returns(sabPort);
fakeConfig.Setup(c => c.SabApiKey) fakeConfig.SetupGet(c => c.SabApiKey)
.Returns(apikey); .Returns(apikey);
fakeConfig.Setup(c => c.SabUsername) fakeConfig.SetupGet(c => c.SabUsername)
.Returns(username); .Returns(username);
fakeConfig.Setup(c => c.SabPassword) fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password); .Returns(password);
fakeConfig.Setup(c => c.SabTvPriority) fakeConfig.SetupGet(c => c.SabTvPriority)
.Returns(priority); .Returns(priority);
fakeConfig.Setup(c => c.SabTvCategory) fakeConfig.SetupGet(c => c.SabTvCategory)
.Returns(category); .Returns(category);
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup( .Setup(
s => s =>
s.DownloadString( s.DownloadString(
@ -59,31 +59,15 @@ namespace NzbDrone.Core.Test
"http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an Nzb"); "http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an Nzb");
//Assert //Assert
Assert.AreEqual(true, result); Assert.IsTrue(result);
} }
[Test] [Test]
public void AddByUrlError() public void AddByUrlError()
{ {
//Setup //Setup
string sabHost = "192.168.5.55";
string sabPort = "2222";
string apikey = "5c770e3197e4fe763423ee7c392c25d1";
string username = "admin";
string password = "pass";
string priority = "Normal";
string category = "tv";
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
fakeConfig.Setup(c => c.SabHost)
.Returns(sabHost);
fakeConfig.Setup(c => c.SabPort)
.Returns(sabPort);
fakeConfig.Setup(c => c.SabApiKey)
.Returns(apikey);
fakeConfig.Setup(c => c.SabUsername)
.Returns(username); .Returns(username);
fakeConfig.Setup(c => c.SabPassword) fakeConfig.Setup(c => c.SabPassword)
.Returns(password); .Returns(password);
@ -91,20 +75,16 @@ namespace NzbDrone.Core.Test
.Returns(priority); .Returns(priority);
fakeConfig.Setup(c => c.SabTvCategory) fakeConfig.Setup(c => c.SabTvCategory)
.Returns(category); .Returns(category);
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>()
.Setup( .Setup(s => s.DownloadString(It.IsAny<String>()))
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"); .Returns("error");
//Act //Act
bool result = mocker.Resolve<SabProvider>().AddByUrl( var sabProvider = mocker.Resolve<SabProvider>();
"http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an Nzb"); var result = sabProvider.AddByUrl("http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an nzb");
//Assert //Assert
Assert.AreEqual(false, result); Assert.IsFalse(result);
} }
[Test] [Test]
@ -120,24 +100,26 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = mocker.GetMock<ConfigProvider>();
fakeConfig.Setup(c => c.GetValue("SabHost", String.Empty, false)).Returns(sabHost); fakeConfig.SetupGet(c => c.SabHost)
fakeConfig.Setup(c => c.GetValue("SabPort", String.Empty, false)).Returns(sabPort); .Returns(sabHost);
fakeConfig.Setup(c => c.GetValue("SabApiKey", String.Empty, false)).Returns(apikey); fakeConfig.SetupGet(c => c.SabPort)
fakeConfig.Setup(c => c.GetValue("SabUsername", String.Empty, false)).Returns(username); .Returns(sabPort);
fakeConfig.Setup(c => c.GetValue("SabPassword", String.Empty, false)).Returns(password); fakeConfig.SetupGet(c => c.SabApiKey)
.Returns(apikey);
fakeConfig.SetupGet(c => c.SabUsername)
.Returns(username);
fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password);
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup( .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
s => .Returns(File.ReadAllText(@".\Files\Queue.xml"));
s.DownloadString(
"http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(new StreamReader(@".\Files\Queue.xml").ReadToEnd());
//Act //Act
bool result = mocker.Resolve<SabProvider>().IsInQueue("Ubuntu Test"); bool result = mocker.Resolve<SabProvider>().IsInQueue("Ubuntu Test");
//Assert //Assert
Assert.AreEqual(true, result); Assert.IsTrue(result);
} }
[Test] [Test]
@ -153,27 +135,30 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = mocker.GetMock<ConfigProvider>();
fakeConfig.Setup(c => c.GetValue("SabHost", String.Empty, false)).Returns(sabHost); fakeConfig.SetupGet(c => c.SabHost)
fakeConfig.Setup(c => c.GetValue("SabPort", String.Empty, false)).Returns(sabPort); .Returns(sabHost);
fakeConfig.Setup(c => c.GetValue("SabApiKey", String.Empty, false)).Returns(apikey); fakeConfig.SetupGet(c => c.SabPort)
fakeConfig.Setup(c => c.GetValue("SabUsername", String.Empty, false)).Returns(username); .Returns(sabPort);
fakeConfig.Setup(c => c.GetValue("SabPassword", String.Empty, false)).Returns(password); fakeConfig.SetupGet(c => c.SabApiKey)
.Returns(apikey);
fakeConfig.SetupGet(c => c.SabUsername)
.Returns(username);
fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password);
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup( .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
s => .Returns(File.ReadAllText(@".\Files\QueueEmpty.xml"));
s.DownloadString(
"http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(new StreamReader(@".\Files\QueueEmpty.xml").ReadToEnd());
//Act //Act
bool result = mocker.Resolve<SabProvider>().IsInQueue(String.Empty); bool result = mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
//Assert //Assert
Assert.AreEqual(false, result); Assert.IsFalse(result);
} }
[Test] [Test]
[ExpectedException(typeof(ApplicationException), Message = "API Key Incorrect")]
public void IsInQueue_False_Error() public void IsInQueue_False_Error()
{ {
//Setup //Setup
@ -186,25 +171,24 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>(); var fakeConfig = mocker.GetMock<ConfigProvider>();
fakeConfig.Setup(c => c.GetValue("SabHost", String.Empty, false)).Returns(sabHost); fakeConfig.SetupGet(c => c.SabHost)
fakeConfig.Setup(c => c.GetValue("SabPort", String.Empty, false)).Returns(sabPort); .Returns(sabHost);
fakeConfig.Setup(c => c.GetValue("SabApiKey", String.Empty, false)).Returns(apikey); fakeConfig.SetupGet(c => c.SabPort)
fakeConfig.Setup(c => c.GetValue("SabUsername", String.Empty, false)).Returns(username); .Returns(sabPort);
fakeConfig.Setup(c => c.GetValue("SabPassword", String.Empty, false)).Returns(password); fakeConfig.SetupGet(c => c.SabApiKey)
.Returns(apikey);
fakeConfig.SetupGet(c => c.SabUsername)
.Returns(username);
fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password);
mocker.GetMock<HttpProvider>() mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup( .Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
s => .Returns(File.ReadAllText(@".\Files\QueueError.xml"));
s.DownloadString(
"http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(new StreamReader(@".\Files\QueueError.xml").ReadToEnd());
//Act //Act
bool result = mocker.Resolve<SabProvider>().IsInQueue(String.Empty); mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
//Assert
Assert.AreEqual(false, result);
} }
[Test] [Test]

View File

@ -0,0 +1,262 @@
using System;
using System.IO;
using System.Linq;
using AutoMoq;
using MbUnit.Framework;
using Moq;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class SabControllerTest
{
[Test]
public void AddByUrlSuccess()
{
//Setup
string sabHost = "192.168.5.55";
string sabPort = "2222";
string apikey = "5c770e3197e4fe763423ee7c392c25d1";
string username = "admin";
string password = "pass";
string priority = "Normal";
string category = "tv";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
<<<<<<< HEAD
fakeConfig.Setup(c => c.SabHost)
.Returns(sabHost);
fakeConfig.Setup(c => c.SabPort)
.Returns(sabPort);
fakeConfig.Setup(c => c.SabApiKey)
.Returns(apikey);
fakeConfig.Setup(c => c.SabUsername)
.Returns(username);
fakeConfig.Setup(c => c.SabPassword)
.Returns(password);
fakeConfig.Setup(c => c.SabTvPriority)
.Returns(priority);
fakeConfig.Setup(c => c.SabTvCategory)
=======
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
.Returns(sabPort);
fakeConfig.SetupGet(c => c.SabApiKey)
.Returns(apikey);
fakeConfig.SetupGet(c => c.SabUsername)
.Returns(username);
fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password);
fakeConfig.SetupGet(c => c.SabTvPriority)
.Returns(priority);
fakeConfig.SetupGet(c => c.SabTvCategory)
>>>>>>> cb4d0e245018bf547d1d8295a7271c21f26366f8
.Returns(category);
mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.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");
//Act
bool result = mocker.Resolve<SabProvider>().AddByUrl(
"http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an Nzb");
//Assert
Assert.IsTrue(result);
}
[Test]
public void AddByUrlError()
{
//Setup
<<<<<<< HEAD
string sabHost = "192.168.5.55";
string sabPort = "2222";
string apikey = "5c770e3197e4fe763423ee7c392c25d1";
string username = "admin";
string password = "pass";
string priority = "Normal";
string category = "tv";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
fakeConfig.Setup(c => c.SabHost)
.Returns(sabHost);
fakeConfig.Setup(c => c.SabPort)
.Returns(sabPort);
fakeConfig.Setup(c => c.SabApiKey)
.Returns(apikey);
fakeConfig.Setup(c => c.SabUsername)
.Returns(username);
fakeConfig.Setup(c => c.SabPassword)
.Returns(password);
fakeConfig.Setup(c => c.SabTvPriority)
.Returns(priority);
fakeConfig.Setup(c => c.SabTvCategory)
.Returns(category);
=======
var mocker = new AutoMoqer();
>>>>>>> cb4d0e245018bf547d1d8295a7271c21f26366f8
mocker.GetMock<HttpProvider>()
.Setup(s => s.DownloadString(It.IsAny<String>()))
.Returns("error");
//Act
var sabProvider = mocker.Resolve<SabProvider>();
var result = sabProvider.AddByUrl("http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an nzb");
//Assert
Assert.IsFalse(result);
}
[Test]
public void IsInQueue_True()
{
//Setup
string sabHost = "192.168.5.55";
string sabPort = "2222";
string apikey = "5c770e3197e4fe763423ee7c392c25d1";
string username = "admin";
string password = "pass";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
.Returns(sabPort);
fakeConfig.SetupGet(c => c.SabApiKey)
.Returns(apikey);
fakeConfig.SetupGet(c => c.SabUsername)
.Returns(username);
fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password);
mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\Queue.xml"));
//Act
bool result = mocker.Resolve<SabProvider>().IsInQueue("Ubuntu Test");
//Assert
Assert.IsTrue(result);
}
[Test]
public void IsInQueue_False_Empty()
{
//Setup
string sabHost = "192.168.5.55";
string sabPort = "2222";
string apikey = "5c770e3197e4fe763423ee7c392c25d1";
string username = "admin";
string password = "pass";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
.Returns(sabPort);
fakeConfig.SetupGet(c => c.SabApiKey)
.Returns(apikey);
fakeConfig.SetupGet(c => c.SabUsername)
.Returns(username);
fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password);
mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\QueueEmpty.xml"));
//Act
bool result = mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
//Assert
Assert.IsFalse(result);
}
[Test]
[ExpectedException(typeof(ApplicationException), Message = "API Key Incorrect")]
public void IsInQueue_False_Error()
{
//Setup
string sabHost = "192.168.5.55";
string sabPort = "2222";
string apikey = "5c770e3197e4fe763423ee7c392c25d1";
string username = "admin";
string password = "pass";
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
fakeConfig.SetupGet(c => c.SabHost)
.Returns(sabHost);
fakeConfig.SetupGet(c => c.SabPort)
.Returns(sabPort);
fakeConfig.SetupGet(c => c.SabApiKey)
.Returns(apikey);
fakeConfig.SetupGet(c => c.SabUsername)
.Returns(username);
fakeConfig.SetupGet(c => c.SabPassword)
.Returns(password);
mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup(s => s.DownloadString("http://192.168.5.55:2222/api?mode=queue&output=xml&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"))
.Returns(File.ReadAllText(@".\Files\QueueError.xml"));
//Act
mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
}
[Test]
[Row(1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, false, "My Series Name - 1x2 - My Episode Title [DVD]")]
[Row(1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, true, "My Series Name - 1x2 - My Episode Title [DVD] [Proper]")]
[Row(1, new[] { 2 }, "", QualityTypes.DVD, true, "My Series Name - 1x2 - [DVD] [Proper]")]
[Row(1, new[] { 2, 4 }, "My Episode Title", QualityTypes.HDTV, false, "My Series Name - 1x2-1x4 - My Episode Title [HDTV]")]
[Row(1, new[] { 2, 4 }, "My Episode Title", QualityTypes.HDTV, true, "My Series Name - 1x2-1x4 - My Episode Title [HDTV] [Proper]")]
[Row(1, new[] { 2, 4 }, "", QualityTypes.HDTV, true, "My Series Name - 1x2-1x4 - [HDTV] [Proper]")]
public void sab_title(int seasons, int[] episodes, string title, QualityTypes quality, bool proper, string excpected)
{
var mocker = new AutoMoqer();
var parsResult = new EpisodeParseResult()
{
SeriesId = 12,
AirDate = DateTime.Now,
Episodes = episodes.ToList(),
Proper = proper,
Quality = quality,
SeasonNumber = seasons,
EpisodeTitle = title,
FolderName = "My Series Name"
};
//Act
var actual = mocker.Resolve<SabProvider>().GetSabTitle(parsResult);
//Assert
Assert.AreEqual(excpected, actual);
}
}
}

View File

@ -22,6 +22,8 @@ namespace NzbDrone.Core.Model
public QualityTypes Quality { get; set; } public QualityTypes Quality { get; set; }
public LanguageType Language { get; set; }
public override string ToString() public override string ToString()
{ {
if (Episodes == null) if (Episodes == null)

View File

@ -0,0 +1,25 @@
namespace NzbDrone.Core.Model
{
public enum LanguageType
{
English = 0,
French = 1,
Spanish = 2,
German = 3,
Italian = 4,
Danish = 5,
Dutch = 6,
Japanese = 7,
Cantonese = 8,
Mandarin = 9,
Korean = 10,
Russian = 11,
Polish = 12,
Vietnamese = 13,
Swedish = 14,
Norwegian = 15,
Finnish = 16,
Turkish = 17,
Portuguese = 18
}
}

View File

@ -99,7 +99,8 @@ namespace NzbDrone.Core
{ {
Proper = title.ToLower().Contains("proper"), Proper = title.ToLower().Contains("proper"),
CleanTitle = seriesName, CleanTitle = seriesName,
AirDate = new DateTime(airyear, airmonth, airday) AirDate = new DateTime(airyear, airmonth, airday),
Language = ParseLanguage(simpleTitle)
}; };
} }
@ -262,6 +263,72 @@ namespace NzbDrone.Core
return result; return result;
} }
internal static LanguageType ParseLanguage(string title)
{
if (title.ToLower().Contains("english"))
return LanguageType.English;
if (title.ToLower().Contains("french"))
return LanguageType.French;
if (title.ToLower().Contains("spanish"))
return LanguageType.Spanish;
if (title.ToLower().Contains("german"))
{
//Make sure it doesn't contain Germany (Since we're not using REGEX for all this)
if (!title.ToLower().Contains("germany"))
return LanguageType.German;
}
if (title.ToLower().Contains("italian"))
return LanguageType.Italian;
if (title.ToLower().Contains("danish"))
return LanguageType.Danish;
if (title.ToLower().Contains("dutch"))
return LanguageType.Dutch;
if (title.ToLower().Contains("japanese"))
return LanguageType.Japanese;
if (title.ToLower().Contains("cantonese"))
return LanguageType.Cantonese;
if (title.ToLower().Contains("mandarin"))
return LanguageType.Mandarin;
if (title.ToLower().Contains("korean"))
return LanguageType.Korean;
if (title.ToLower().Contains("russian"))
return LanguageType.Russian;
if (title.ToLower().Contains("polish"))
return LanguageType.Polish;
if (title.ToLower().Contains("vietnamese"))
return LanguageType.Vietnamese;
if (title.ToLower().Contains("swedish"))
return LanguageType.Swedish;
if (title.ToLower().Contains("norwegian"))
return LanguageType.Norwegian;
if (title.ToLower().Contains("finnish"))
return LanguageType.Finnish;
if (title.ToLower().Contains("turkish"))
return LanguageType.Turkish;
if (title.ToLower().Contains("portuguese"))
return LanguageType.Portuguese;
return LanguageType.English;
}
/// <summary> /// <summary>
/// Normalizes the title. removing all non-word characters as well as common tokens /// Normalizes the title. removing all non-word characters as well as common tokens
/// such as 'the' and 'and' /// such as 'the' and 'and'
@ -273,7 +340,6 @@ namespace NzbDrone.Core
return NormalizeRegex.Replace(title, String.Empty).ToLower(); return NormalizeRegex.Replace(title, String.Empty).ToLower();
} }
public static string NormalizePath(string path) public static string NormalizePath(string path)
{ {
if (String.IsNullOrWhiteSpace(path)) if (String.IsNullOrWhiteSpace(path))

View File

@ -173,9 +173,9 @@ namespace NzbDrone.Core.Providers.Core
set { SetValue("SabTvPriority", value); } set { SetValue("SabTvPriority", value); }
} }
public virtual String UseBlackhole public virtual Boolean UseBlackhole
{ {
get { return GetValue("UseBlackhole"); } get { return GetValueBoolean("UseBlackhole"); }
set { SetValue("UseBlackhole", value); } set { SetValue("UseBlackhole", value); }
} }

View File

@ -1,23 +1,17 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers.ExternalNotification namespace NzbDrone.Core.Providers.ExternalNotification
{ {
public class XbmcNotificationProvider : ExternalNotificationProviderBase public class XbmcNotificationProvider : ExternalNotificationProviderBase
{ {
private readonly Logger _logger;
private readonly XbmcProvider _xbmcProvider; private readonly XbmcProvider _xbmcProvider;
public XbmcNotificationProvider(ConfigProvider configProvider, XbmcProvider xbmcProvider, public XbmcNotificationProvider(ConfigProvider configProvider, XbmcProvider xbmcProvider,
ExternalNotificationProvider externalNotificationProvider) : base(configProvider, externalNotificationProvider) ExternalNotificationProvider externalNotificationProvider)
: base(configProvider, externalNotificationProvider)
{ {
_xbmcProvider = xbmcProvider; _xbmcProvider = xbmcProvider;
_logger = LogManager.GetLogger(GetType().ToString());
} }
public override string Name public override string Name
@ -27,13 +21,13 @@ namespace NzbDrone.Core.Providers.ExternalNotification
public override void OnGrab(string message) public override void OnGrab(string message)
{ {
var header = "NzbDrone [TV] - Grabbed"; const string header = "NzbDrone [TV] - Grabbed";
if (Convert.ToBoolean(_configProvider.GetValue("XbmcEnabled", false, true))) if (Convert.ToBoolean(_configProvider.GetValue("XbmcEnabled", false, true)))
{ {
if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnGrab", false, true))) if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnGrab", false, true)))
{ {
_logger.Trace("Sending Notifcation to XBMC"); _logger.Trace("Sending Notification to XBMC");
_xbmcProvider.Notify(header, message); _xbmcProvider.Notify(header, message);
return; return;
} }
@ -45,13 +39,13 @@ namespace NzbDrone.Core.Providers.ExternalNotification
public override void OnDownload(string message, int seriesId) public override void OnDownload(string message, int seriesId)
{ {
var header = "NzbDrone [TV] - Downloaded"; const string header = "NzbDrone [TV] - Downloaded";
if (Convert.ToBoolean(_configProvider.GetValue("XbmcEnabled", false, true))) if (Convert.ToBoolean(_configProvider.GetValue("XbmcEnabled", false, true)))
{ {
if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnDownload", false, true))) if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnDownload", false, true)))
{ {
_logger.Trace("Sending Notifcation to XBMC"); _logger.Trace("Sending Notification to XBMC");
_xbmcProvider.Notify(header, message); _xbmcProvider.Notify(header, message);
} }
@ -73,11 +67,11 @@ namespace NzbDrone.Core.Providers.ExternalNotification
public override void OnRename(string message, int seriesId) public override void OnRename(string message, int seriesId)
{ {
var header = "NzbDrone [TV] - Renamed"; const string header = "NzbDrone [TV] - Renamed";
if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnRename", false, true))) if (Convert.ToBoolean(_configProvider.GetValue("XbmcNotifyOnRename", false, true)))
{ {
_logger.Trace("Sending Notifcation to XBMC"); _logger.Trace("Sending Notification to XBMC");
_xbmcProvider.Notify(header, message); _xbmcProvider.Notify(header, message);
} }

View File

@ -164,7 +164,7 @@ namespace NzbDrone.Core.Providers.Indexer
parseResult.EpisodeTitle = episodes[0].Title; parseResult.EpisodeTitle = episodes[0].Title;
var sabTitle = _sabProvider.GetSabTitle(parseResult); var sabTitle = _sabProvider.GetSabTitle(parseResult);
if (Convert.ToBoolean(_configProvider.UseBlackhole)) if (_configProvider.UseBlackhole)
{ {
var blackholeDir = _configProvider.BlackholeDirectory; var blackholeDir = _configProvider.BlackholeDirectory;
var folder = !String.IsNullOrEmpty(blackholeDir) ? blackholeDir : Path.Combine(CentralDispatch.AppPath, "App_Data"); var folder = !String.IsNullOrEmpty(blackholeDir) ? blackholeDir : Path.Combine(CentralDispatch.AppPath, "App_Data");
@ -187,6 +187,7 @@ namespace NzbDrone.Core.Providers.Indexer
if (!_sabProvider.AddByUrl(NzbDownloadUrl(feedItem), sabTitle)) if (!_sabProvider.AddByUrl(NzbDownloadUrl(feedItem), sabTitle))
{ {
_logger.Warn("Unable to add item to SAB queue. {0} {1}", NzbDownloadUrl(feedItem), sabTitle);
return; return;
} }
} }

View File

@ -28,24 +28,25 @@ namespace NzbDrone.Core.Providers
public virtual bool AddByUrl(string url, string title) public virtual bool AddByUrl(string url, string title)
{ {
const string mode = "addurl";
string cat = _configProvider.SabTvCategory; string cat = _configProvider.SabTvCategory;
int priority = (int)Enum.Parse(typeof(SabnzbdPriorityType), _configProvider.SabTvPriority); int priority = (int)Enum.Parse(typeof(SabnzbdPriorityType), _configProvider.SabTvPriority);
string name = url.Replace("&", "%26"); string name = url.Replace("&", "%26");
string nzbName = HttpUtility.UrlEncode(title); string nzbName = HttpUtility.UrlEncode(title);
string action = string.Format("mode={0}&name={1}&priority={2}&cat={3}&nzbname={4}", mode, name, priority, string action = string.Format("mode=addurl&name={0}&priority={1}&cat={2}&nzbname={3}",
cat, nzbName); name, priority, cat, nzbName);
string request = GetSabRequest(action); string request = GetSabRequest(action);
Logger.Info("Adding report [{0}] to the queue.", title); Logger.Info("Adding report [{0}] to the queue.", title);
string response = _httpProvider.DownloadString(request).Replace("\n", String.Empty); string response = _httpProvider.DownloadString(request).Replace("\n", String.Empty);
Logger.Debug("Queue Repsonse: [{0}]", response); Logger.Debug("Queue Response: [{0}]", response);
if (response == "ok") if (response == "ok")
return true; return true;
Logger.Warn("SAB returned unexpected response '{0}'", response);
return false; return false;
} }
@ -59,11 +60,13 @@ namespace NzbDrone.Core.Providers
//If an Error Occurred, return) //If an Error Occurred, return)
if (xDoc.Descendants("error").Count() != 0) if (xDoc.Descendants("error").Count() != 0)
return false; throw new ApplicationException(xDoc.Descendants("error").FirstOrDefault().Value);
if (xDoc.Descendants("queue").Count() == 0) if (xDoc.Descendants("queue").Count() == 0)
{
Logger.Debug("SAB Queue is empty. retiring false");
return false; return false;
}
//Get the Count of Items in Queue where 'filename' is Equal to goodName, if not zero, return true (isInQueue))) //Get the Count of Items in Queue where 'filename' is Equal to goodName, if not zero, return true (isInQueue)))
if ( if (
(xDoc.Descendants("slot").Where( (xDoc.Descendants("slot").Where(
@ -78,41 +81,15 @@ namespace NzbDrone.Core.Providers
return false; //Not in Queue return false; //Not in Queue
} }
public virtual bool AddById(string id, string title)
{
//mode=addid&name=333333&pp=3&script=customscript.cmd&cat=Example&priority=-1
const string mode = "addid";
string cat = _configProvider.SabTvCategory;
int priority = (int)Enum.Parse(typeof(SabnzbdPriorityType), _configProvider.SabTvPriority);
string nzbName = HttpUtility.UrlEncode(title);
string action = string.Format("mode={0}&name={1}&priority={2}&cat={3}&nzbname={4}", mode, id, priority, cat,
nzbName);
string request = GetSabRequest(action);
Logger.Debug("Adding report [{0}] to the queue.", nzbName);
string response = _httpProvider.DownloadString(request).Replace("\n", String.Empty);
Logger.Debug("Queue Repsonse: [{0}]", response);
if (response == "ok")
return true;
return false;
}
private string GetSabRequest(string action) private string GetSabRequest(string action)
{ {
string sabnzbdInfo = _configProvider.SabHost + ":" + return string.Format(@"http://{0}:{1}/api?{2}&apikey={3}&ma_username={4}&ma_password={5}",
_configProvider.SabPort; _configProvider.SabHost,
string username = _configProvider.SabUsername; _configProvider.SabPort,
string password = _configProvider.SabPassword; action,
string apiKey = _configProvider.SabApiKey; _configProvider.SabApiKey,
_configProvider.SabUsername,
return _configProvider.SabPassword);
string.Format(@"http://{0}/api?$Action&apikey={1}&ma_username={2}&ma_password={3}", sabnzbdInfo, apiKey,
username, password).Replace("$Action", action);
} }
public String GetSabTitle(EpisodeParseResult parseResult) public String GetSabTitle(EpisodeParseResult parseResult)

View File

@ -0,0 +1,160 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers
{
public class SabProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly ConfigProvider _configProvider;
private readonly HttpProvider _httpProvider;
public SabProvider()
{
}
public SabProvider(ConfigProvider configProvider, HttpProvider httpProvider)
{
_configProvider = configProvider;
_httpProvider = httpProvider;
}
public virtual bool AddByUrl(string url, string title)
{
string cat = _configProvider.SabTvCategory;
<<<<<<< HEAD
int priority = (int)Enum.Parse(typeof(SabnzbdPriorityType), _configProvider.SabTvPriority);
=======
string priority = _configProvider.SabTvPriority;
>>>>>>> cb4d0e245018bf547d1d8295a7271c21f26366f8
string name = url.Replace("&", "%26");
string nzbName = HttpUtility.UrlEncode(title);
string action = string.Format("mode=addurl&name={0}&priority={1}&cat={2}&nzbname={3}",
name, priority, cat, nzbName);
string request = GetSabRequest(action);
Logger.Info("Adding report [{0}] to the queue.", title);
string response = _httpProvider.DownloadString(request).Replace("\n", String.Empty);
Logger.Debug("Queue Response: [{0}]", response);
if (response == "ok")
return true;
Logger.Warn("SAB returned unexpected response '{0}'", response);
return false;
}
public virtual bool IsInQueue(string title)
{
const string action = "mode=queue&output=xml";
string request = GetSabRequest(action);
string response = _httpProvider.DownloadString(request);
XDocument xDoc = XDocument.Parse(response);
//If an Error Occurred, return)
if (xDoc.Descendants("error").Count() != 0)
throw new ApplicationException(xDoc.Descendants("error").FirstOrDefault().Value);
if (xDoc.Descendants("queue").Count() == 0)
{
Logger.Debug("SAB Queue is empty. retiring false");
return false;
}
//Get the Count of Items in Queue where 'filename' is Equal to goodName, if not zero, return true (isInQueue)))
if (
(xDoc.Descendants("slot").Where(
s => s.Element("filename").Value.Equals(title, StringComparison.InvariantCultureIgnoreCase))).Count() !=
0)
{
Logger.Debug("Episode in queue - '{0}'", title);
return true;
}
return false; //Not in Queue
}
<<<<<<< HEAD
public virtual bool AddById(string id, string title)
{
//mode=addid&name=333333&pp=3&script=customscript.cmd&cat=Example&priority=-1
const string mode = "addid";
string cat = _configProvider.SabTvCategory;
int priority = (int)Enum.Parse(typeof(SabnzbdPriorityType), _configProvider.SabTvPriority);
string nzbName = HttpUtility.UrlEncode(title);
string action = string.Format("mode={0}&name={1}&priority={2}&cat={3}&nzbname={4}", mode, id, priority, cat,
nzbName);
string request = GetSabRequest(action);
Logger.Debug("Adding report [{0}] to the queue.", nzbName);
string response = _httpProvider.DownloadString(request).Replace("\n", String.Empty);
Logger.Debug("Queue Repsonse: [{0}]", response);
if (response == "ok")
return true;
return false;
}
private string GetSabRequest(string action)
{
string sabnzbdInfo = _configProvider.SabHost + ":" +
_configProvider.SabPort;
string username = _configProvider.SabUsername;
string password = _configProvider.SabPassword;
string apiKey = _configProvider.SabApiKey;
return
string.Format(@"http://{0}/api?$Action&apikey={1}&ma_username={2}&ma_password={3}", sabnzbdInfo, apiKey,
username, password).Replace("$Action", action);
=======
private string GetSabRequest(string action)
{
return string.Format(@"http://{0}:{1}/api?{2}&apikey={3}&ma_username={4}&ma_password={5}",
_configProvider.SabHost,
_configProvider.SabPort,
action,
_configProvider.SabApiKey,
_configProvider.SabUsername,
_configProvider.SabPassword);
>>>>>>> cb4d0e245018bf547d1d8295a7271c21f26366f8
}
public String GetSabTitle(EpisodeParseResult parseResult)
{
//Show Name - 1x01-1x02 - Episode Name
//Show Name - 1x01 - Episode Name
var episodeString = new List<String>();
foreach (var episode in parseResult.Episodes)
{
episodeString.Add(String.Format("{0}x{1}", parseResult.SeasonNumber, episode));
}
var epNumberString = String.Join("-", episodeString);
var result = String.Format("{0} - {1} - {2} [{3}]", parseResult.FolderName, epNumberString, parseResult.EpisodeTitle, parseResult.Quality);
if (parseResult.Proper)
{
result += " [Proper]";
}
return result;
}
}
}

View File

@ -392,7 +392,7 @@ namespace NzbDrone.Web.Controllers
_configProvider.SabTvCategory = data.SabTvCategory; _configProvider.SabTvCategory = data.SabTvCategory;
_configProvider.SabUsername = data.SabUsername; _configProvider.SabUsername = data.SabUsername;
_configProvider.SabTvPriority = data.SabTvPriority.ToString(); _configProvider.SabTvPriority = data.SabTvPriority.ToString();
_configProvider.UseBlackhole = data.UseBlackHole.ToString(); _configProvider.UseBlackhole = data.UseBlackHole;
_configProvider.BlackholeDirectory = data.BlackholeDirectory; _configProvider.BlackholeDirectory = data.BlackholeDirectory;
return Content(SETTINGS_SAVED); return Content(SETTINGS_SAVED);

View File

@ -43,7 +43,7 @@
@Html.LabelFor(model => model.Path) @Html.LabelFor(model => model.Path)
</div> </div>
<div class="editor-field"> <div class="editor-field">
@Html.TextBoxFor(model => model.Path) @Html.TextBoxFor(model => model.Path, new { style = "width: 250" })
@Html.ValidationMessageFor(model => model.Path) @Html.ValidationMessageFor(model => model.Path)
</div> </div>