1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

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 @@ public void import_existing_season_file()
//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

View File

@ -32,22 +32,22 @@ public void AddByUrlSuccess()
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
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<HttpProvider>()
mocker.GetMock<HttpProvider>(MockBehavior.Strict)
.Setup(
s =>
s.DownloadString(
@ -59,31 +59,15 @@ public void AddByUrlSuccess()
"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<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);
@ -91,20 +75,16 @@ public void AddByUrlError()
.Returns(priority);
fakeConfig.Setup(c => c.SabTvCategory)
.Returns(category);
mocker.GetMock<HttpProvider>()
.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<String>()))
.Returns("error");
//Act
bool result = mocker.Resolve<SabProvider>().AddByUrl(
"http://www.nzbclub.com/nzb_download.aspx?mid=1950232", "This is an Nzb");
var sabProvider = mocker.Resolve<SabProvider>();
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 @@ public void IsInQueue_True()
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
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<HttpProvider>()
.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<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.AreEqual(true, result);
Assert.IsTrue(result);
}
[Test]
@ -153,27 +135,30 @@ public void IsInQueue_False_Empty()
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
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<HttpProvider>()
.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<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.AreEqual(false, result);
Assert.IsFalse(result);
}
[Test]
[ExpectedException(typeof(ApplicationException), Message = "API Key Incorrect")]
public void IsInQueue_False_Error()
{
//Setup
@ -186,25 +171,24 @@ public void IsInQueue_False_Error()
var mocker = new AutoMoqer();
var fakeConfig = mocker.GetMock<ConfigProvider>();
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<HttpProvider>()
.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<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
bool result = mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
//Assert
Assert.AreEqual(false, result);
mocker.Resolve<SabProvider>().IsInQueue(String.Empty);
}
[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 @@ public class EpisodeParseResult
public QualityTypes Quality { get; set; }
public LanguageType Language { get; set; }
public override string ToString()
{
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 @@ internal static EpisodeParseResult ParseEpisodeInfo(string title)
{
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 @@ internal static QualityTypes ParseQuality(string name)
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>
/// Normalizes the title. removing all non-word characters as well as common tokens
/// such as 'the' and 'and'
@ -273,7 +340,6 @@ public static string NormalizeTitle(string title)
return NormalizeRegex.Replace(title, String.Empty).ToLower();
}
public static string NormalizePath(string path)
{
if (String.IsNullOrWhiteSpace(path))

View File

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

View File

@ -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 @@ public override string Name
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 @@ public override void OnGrab(string message)
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 @@ public override void OnDownload(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)))
{
_logger.Trace("Sending Notifcation to XBMC");
_logger.Trace("Sending Notification to XBMC");
_xbmcProvider.Notify(header, message);
}

View File

@ -164,7 +164,7 @@ internal void ProcessItem(SyndicationItem feedItem)
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 @@ internal void ProcessItem(SyndicationItem feedItem)
if (!_sabProvider.AddByUrl(NzbDownloadUrl(feedItem), sabTitle))
{
_logger.Warn("Unable to add item to SAB queue. {0} {1}", NzbDownloadUrl(feedItem), sabTitle);
return;
}
}

View File

@ -28,24 +28,25 @@ public SabProvider(ConfigProvider configProvider, HttpProvider httpProvider)
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 @@ public virtual bool IsInQueue(string title)
//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 @@ public virtual bool IsInQueue(string title)
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)

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 @@ public ActionResult SaveDownloads(DownloadSettingsModel data)
_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);

View File

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