diff --git a/NzbDrone.Core.Test/MediaFileProviderTests.cs b/NzbDrone.Core.Test/MediaFileProviderTests.cs index d6764f6ca..becfc86b0 100644 --- a/NzbDrone.Core.Test/MediaFileProviderTests.cs +++ b/NzbDrone.Core.Test/MediaFileProviderTests.cs @@ -135,8 +135,6 @@ namespace NzbDrone.Core.Test //Constants const string fileName = @"WEEDS.S03E01.DUAL.BDRip.XviD.AC3.-HELLYWOOD.avi"; - const int seasonNumber = 3; - const int episodeNumner = 1; const int size = 12345; //Fakes diff --git a/NzbDrone.Core.Test/SabControllerTest.cs b/NzbDrone.Core.Test/SabControllerTest.cs index 81ba760ec..e29adc6dd 100644 --- a/NzbDrone.Core.Test/SabControllerTest.cs +++ b/NzbDrone.Core.Test/SabControllerTest.cs @@ -32,22 +32,22 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(); var fakeConfig = mocker.GetMock(); - fakeConfig.Setup(c => c.SabHost) + fakeConfig.SetupGet(c => c.SabHost) .Returns(sabHost); - fakeConfig.Setup(c => c.SabPort) + fakeConfig.SetupGet(c => c.SabPort) .Returns(sabPort); - fakeConfig.Setup(c => c.SabApiKey) + fakeConfig.SetupGet(c => c.SabApiKey) .Returns(apikey); - fakeConfig.Setup(c => c.SabUsername) + fakeConfig.SetupGet(c => c.SabUsername) .Returns(username); - fakeConfig.Setup(c => c.SabPassword) + fakeConfig.SetupGet(c => c.SabPassword) .Returns(password); - fakeConfig.Setup(c => c.SabTvPriority) + fakeConfig.SetupGet(c => c.SabTvPriority) .Returns(priority); - fakeConfig.Setup(c => c.SabTvCategory) + fakeConfig.SetupGet(c => c.SabTvCategory) .Returns(category); - mocker.GetMock() + mocker.GetMock(MockBehavior.Strict) .Setup( s => s.DownloadString( @@ -59,31 +59,15 @@ namespace NzbDrone.Core.Test "http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an Nzb"); //Assert - Assert.AreEqual(true, result); + Assert.IsTrue(result); } [Test] public void AddByUrlError() { //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(); - 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); @@ -91,20 +75,16 @@ namespace NzbDrone.Core.Test .Returns(priority); fakeConfig.Setup(c => c.SabTvCategory) .Returns(category); - mocker.GetMock() - .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")) + .Setup(s => s.DownloadString(It.IsAny())) .Returns("error"); //Act - bool result = mocker.Resolve().AddByUrl( - "http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an Nzb"); + var sabProvider = mocker.Resolve(); + var result = sabProvider.AddByUrl("http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an nzb"); //Assert - Assert.AreEqual(false, result); + Assert.IsFalse(result); } [Test] @@ -120,24 +100,26 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(); var fakeConfig = mocker.GetMock(); - fakeConfig.Setup(c => c.GetValue("SabHost", String.Empty, false)).Returns(sabHost); - fakeConfig.Setup(c => c.GetValue("SabPort", String.Empty, false)).Returns(sabPort); - fakeConfig.Setup(c => c.GetValue("SabApiKey", String.Empty, false)).Returns(apikey); - fakeConfig.Setup(c => c.GetValue("SabUsername", String.Empty, false)).Returns(username); - fakeConfig.Setup(c => c.GetValue("SabPassword", String.Empty, false)).Returns(password); + 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() - .Setup( - s => - 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()); + mocker.GetMock(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().IsInQueue("Ubuntu Test"); //Assert - Assert.AreEqual(true, result); + Assert.IsTrue(result); } [Test] @@ -153,27 +135,30 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(); var fakeConfig = mocker.GetMock(); - fakeConfig.Setup(c => c.GetValue("SabHost", String.Empty, false)).Returns(sabHost); - fakeConfig.Setup(c => c.GetValue("SabPort", String.Empty, false)).Returns(sabPort); - fakeConfig.Setup(c => c.GetValue("SabApiKey", String.Empty, false)).Returns(apikey); - fakeConfig.Setup(c => c.GetValue("SabUsername", String.Empty, false)).Returns(username); - fakeConfig.Setup(c => c.GetValue("SabPassword", String.Empty, false)).Returns(password); + 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() - .Setup( - s => - 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()); + mocker.GetMock(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().IsInQueue(String.Empty); //Assert - Assert.AreEqual(false, result); + Assert.IsFalse(result); } [Test] + [ExpectedException(typeof(ApplicationException), Message = "API Key Incorrect")] public void IsInQueue_False_Error() { //Setup @@ -186,25 +171,24 @@ namespace NzbDrone.Core.Test var mocker = new AutoMoqer(); var fakeConfig = mocker.GetMock(); - fakeConfig.Setup(c => c.GetValue("SabHost", String.Empty, false)).Returns(sabHost); - fakeConfig.Setup(c => c.GetValue("SabPort", String.Empty, false)).Returns(sabPort); - fakeConfig.Setup(c => c.GetValue("SabApiKey", String.Empty, false)).Returns(apikey); - fakeConfig.Setup(c => c.GetValue("SabUsername", String.Empty, false)).Returns(username); - fakeConfig.Setup(c => c.GetValue("SabPassword", String.Empty, false)).Returns(password); + 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() - .Setup( - s => - 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()); + mocker.GetMock(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 - bool result = mocker.Resolve().IsInQueue(String.Empty); - - //Assert - Assert.AreEqual(false, result); + mocker.Resolve().IsInQueue(String.Empty); } [Test] diff --git a/NzbDrone.Core.Test/SabControllerTest.cs.orig b/NzbDrone.Core.Test/SabControllerTest.cs.orig new file mode 100644 index 000000000..a972761da --- /dev/null +++ b/NzbDrone.Core.Test/SabControllerTest.cs.orig @@ -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(); +<<<<<<< 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(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().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(); + 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() + .Setup(s => s.DownloadString(It.IsAny())) + .Returns("error"); + + //Act + var sabProvider = mocker.Resolve(); + 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(); + 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(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().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(); + 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(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().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(); + 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(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().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().GetSabTitle(parsResult); + + //Assert + Assert.AreEqual(excpected, actual); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Model/EpisodeParseResult.cs b/NzbDrone.Core/Model/EpisodeParseResult.cs index 749bb8670..7ca68acfb 100644 --- a/NzbDrone.Core/Model/EpisodeParseResult.cs +++ b/NzbDrone.Core/Model/EpisodeParseResult.cs @@ -22,6 +22,8 @@ namespace NzbDrone.Core.Model public QualityTypes Quality { get; set; } + public LanguageType Language { get; set; } + public override string ToString() { if (Episodes == null) diff --git a/NzbDrone.Core/Model/LanguageType.cs b/NzbDrone.Core/Model/LanguageType.cs new file mode 100644 index 000000000..2bdab3ae8 --- /dev/null +++ b/NzbDrone.Core/Model/LanguageType.cs @@ -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 + } +} diff --git a/NzbDrone.Core/Parser.cs b/NzbDrone.Core/Parser.cs index 72ec4ab0c..10d7ecaed 100644 --- a/NzbDrone.Core/Parser.cs +++ b/NzbDrone.Core/Parser.cs @@ -99,7 +99,8 @@ namespace NzbDrone.Core { Proper = title.ToLower().Contains("proper"), 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; } + 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; + } + /// /// Normalizes the title. removing all non-word characters as well as common tokens /// such as 'the' and 'and' @@ -273,7 +340,6 @@ namespace NzbDrone.Core return NormalizeRegex.Replace(title, String.Empty).ToLower(); } - public static string NormalizePath(string path) { if (String.IsNullOrWhiteSpace(path)) diff --git a/NzbDrone.Core/Providers/Core/ConfigProvider.cs b/NzbDrone.Core/Providers/Core/ConfigProvider.cs index 4761db871..c369e87f6 100644 --- a/NzbDrone.Core/Providers/Core/ConfigProvider.cs +++ b/NzbDrone.Core/Providers/Core/ConfigProvider.cs @@ -173,9 +173,9 @@ namespace NzbDrone.Core.Providers.Core set { SetValue("SabTvPriority", value); } } - public virtual String UseBlackhole + public virtual Boolean UseBlackhole { - get { return GetValue("UseBlackhole"); } + get { return GetValueBoolean("UseBlackhole"); } set { SetValue("UseBlackhole", value); } } diff --git a/NzbDrone.Core/Providers/ExternalNotification/XbmcNotificationProvider.cs b/NzbDrone.Core/Providers/ExternalNotification/XbmcNotificationProvider.cs index 9e84f9fcb..bcb2bd369 100644 --- a/NzbDrone.Core/Providers/ExternalNotification/XbmcNotificationProvider.cs +++ b/NzbDrone.Core/Providers/ExternalNotification/XbmcNotificationProvider.cs @@ -1,23 +1,17 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using NLog; -using NzbDrone.Core.Helpers; using NzbDrone.Core.Providers.Core; namespace NzbDrone.Core.Providers.ExternalNotification { public class XbmcNotificationProvider : ExternalNotificationProviderBase { - private readonly Logger _logger; private readonly XbmcProvider _xbmcProvider; public XbmcNotificationProvider(ConfigProvider configProvider, XbmcProvider xbmcProvider, - ExternalNotificationProvider externalNotificationProvider) : base(configProvider, externalNotificationProvider) + ExternalNotificationProvider externalNotificationProvider) + : base(configProvider, externalNotificationProvider) { _xbmcProvider = xbmcProvider; - _logger = LogManager.GetLogger(GetType().ToString()); } public override string Name @@ -27,13 +21,13 @@ namespace NzbDrone.Core.Providers.ExternalNotification 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("XbmcNotifyOnGrab", false, true))) { - _logger.Trace("Sending Notifcation to XBMC"); + _logger.Trace("Sending Notification to XBMC"); _xbmcProvider.Notify(header, message); return; } @@ -45,13 +39,13 @@ namespace NzbDrone.Core.Providers.ExternalNotification 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("XbmcNotifyOnDownload", false, true))) { - _logger.Trace("Sending Notifcation to XBMC"); + _logger.Trace("Sending Notification to XBMC"); _xbmcProvider.Notify(header, message); } @@ -73,11 +67,11 @@ namespace NzbDrone.Core.Providers.ExternalNotification 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))) { - _logger.Trace("Sending Notifcation to XBMC"); + _logger.Trace("Sending Notification to XBMC"); _xbmcProvider.Notify(header, message); } diff --git a/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs index 97c20dea2..f10cad1c1 100644 --- a/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs @@ -164,7 +164,7 @@ namespace NzbDrone.Core.Providers.Indexer parseResult.EpisodeTitle = episodes[0].Title; var sabTitle = _sabProvider.GetSabTitle(parseResult); - if (Convert.ToBoolean(_configProvider.UseBlackhole)) + if (_configProvider.UseBlackhole) { var blackholeDir = _configProvider.BlackholeDirectory; 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)) { + _logger.Warn("Unable to add item to SAB queue. {0} {1}", NzbDownloadUrl(feedItem), sabTitle); return; } } diff --git a/NzbDrone.Core/Providers/SabProvider.cs b/NzbDrone.Core/Providers/SabProvider.cs index ccd88ff3f..7fb71847d 100644 --- a/NzbDrone.Core/Providers/SabProvider.cs +++ b/NzbDrone.Core/Providers/SabProvider.cs @@ -28,24 +28,25 @@ namespace NzbDrone.Core.Providers public virtual bool AddByUrl(string url, string title) { - const string mode = "addurl"; string cat = _configProvider.SabTvCategory; int priority = (int)Enum.Parse(typeof(SabnzbdPriorityType), _configProvider.SabTvPriority); string name = url.Replace("&", "%26"); string nzbName = HttpUtility.UrlEncode(title); - string action = string.Format("mode={0}&name={1}&priority={2}&cat={3}&nzbname={4}", mode, name, priority, - cat, nzbName); + 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 Repsonse: [{0}]", response); + Logger.Debug("Queue Response: [{0}]", response); if (response == "ok") return true; + Logger.Warn("SAB returned unexpected response '{0}'", response); + return false; } @@ -59,11 +60,13 @@ namespace NzbDrone.Core.Providers //If an Error Occurred, return) if (xDoc.Descendants("error").Count() != 0) - return false; + 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( @@ -78,41 +81,15 @@ namespace NzbDrone.Core.Providers 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) { - 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); + 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); } public String GetSabTitle(EpisodeParseResult parseResult) diff --git a/NzbDrone.Core/Providers/SabProvider.cs.orig b/NzbDrone.Core/Providers/SabProvider.cs.orig new file mode 100644 index 000000000..acc93c5c9 --- /dev/null +++ b/NzbDrone.Core/Providers/SabProvider.cs.orig @@ -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(); + + 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; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index 5924ea7fd..d7a551f04 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -392,7 +392,7 @@ namespace NzbDrone.Web.Controllers _configProvider.SabTvCategory = data.SabTvCategory; _configProvider.SabUsername = data.SabUsername; _configProvider.SabTvPriority = data.SabTvPriority.ToString(); - _configProvider.UseBlackhole = data.UseBlackHole.ToString(); + _configProvider.UseBlackhole = data.UseBlackHole; _configProvider.BlackholeDirectory = data.BlackholeDirectory; return Content(SETTINGS_SAVED); diff --git a/NzbDrone.Web/Views/Series/Edit.cshtml b/NzbDrone.Web/Views/Series/Edit.cshtml index 8346c013f..d7bc3d4c6 100644 --- a/NzbDrone.Web/Views/Series/Edit.cshtml +++ b/NzbDrone.Web/Views/Series/Edit.cshtml @@ -43,7 +43,7 @@ @Html.LabelFor(model => model.Path)
- @Html.TextBoxFor(model => model.Path) + @Html.TextBoxFor(model => model.Path, new { style = "width: 250" }) @Html.ValidationMessageFor(model => model.Path)