mirror of
https://github.com/Radarr/Radarr
synced 2024-12-27 10:19:41 +00:00
Merge branch 'master' of git://github.com/kayone/NzbDrone
This commit is contained in:
commit
3dce6a13cd
3 changed files with 120 additions and 9 deletions
|
@ -135,6 +135,7 @@ public void parsing_our_own_quality_enum()
|
|||
[TestCase("The Borgias S01e01 e02 ShoHD On Demand 1080i DD5 1 ALANiS", "The Borgias", 1, new[] { 1, 2 }, 2)]
|
||||
[TestCase("Big Time Rush 1x01 to 10 480i DD2 0 Sianto", "Big Time Rush", 1, new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 10)]
|
||||
[TestCase("White.Collar.2x04.2x05.720p.BluRay-FUTV", "White.Collar", 2, new[] { 4, 5 }, 2)]
|
||||
[TestCase("Desperate.Housewives.S07E22E23.720p.HDTV.X264-DIMENSION", "Desperate.Housewives", 7, new[] { 22,23 }, 2)]
|
||||
//[Row("The.Kennedys.Part.1.and.Part.2.DSR.XviD-SYS", 1, new[] { 1, 2 })]
|
||||
public void episode_multipart_parse(string postTitle, string title, int season, int[] episodes, int count)
|
||||
{
|
||||
|
|
|
@ -66,6 +66,53 @@ public void AddByUrlSuccess()
|
|||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void AddByUrlNewzbin()
|
||||
{
|
||||
//Setup
|
||||
const string sabHost = "192.168.5.55";
|
||||
const int sabPort = 2222;
|
||||
const string apikey = "5c770e3197e4fe763423ee7c392c25d1";
|
||||
const string username = "admin";
|
||||
const string password = "pass";
|
||||
const SabnzbdPriorityType priority = SabnzbdPriorityType.Normal;
|
||||
const string category = "tv";
|
||||
|
||||
|
||||
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);
|
||||
fakeConfig.SetupGet(c => c.SabTvPriority)
|
||||
.Returns(priority);
|
||||
fakeConfig.SetupGet(c => c.SabTvCategory)
|
||||
.Returns(category);
|
||||
|
||||
mocker.GetMock<HttpProvider>(MockBehavior.Strict)
|
||||
.Setup(
|
||||
s =>
|
||||
s.DownloadString(
|
||||
"http://192.168.5.55:2222/api?mode=addid&name=6107863&priority=0&pp=3&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.newzbin.com/browse/post/6107863/nzb", "This is an Nzb");
|
||||
|
||||
//Assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddByUrlError()
|
||||
{
|
||||
|
@ -179,7 +226,7 @@ public void IsInQueue_False_Empty()
|
|||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ApplicationException), ExpectedMessage= "API Key Incorrect")]
|
||||
[ExpectedException(typeof(ApplicationException), ExpectedMessage = "API Key Incorrect")]
|
||||
public void IsInQueue_False_Error()
|
||||
{
|
||||
//Setup
|
||||
|
@ -213,12 +260,12 @@ public void IsInQueue_False_Error()
|
|||
}
|
||||
|
||||
[Test]
|
||||
[TestCase(1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, false, "My Series Name - 1x2 - My Episode Title [DVD]")]
|
||||
[TestCase(1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, true, "My Series Name - 1x2 - My Episode Title [DVD] [Proper]")]
|
||||
[TestCase(1, new[] { 2 }, "", QualityTypes.DVD, true, "My Series Name - 1x2 - [DVD] [Proper]")]
|
||||
[TestCase(1, new[] { 2, 4 }, "My Episode Title", QualityTypes.HDTV, false, "My Series Name - 1x2-1x4 - My Episode Title [HDTV]")]
|
||||
[TestCase(1, new[] { 2, 4 }, "My Episode Title", QualityTypes.HDTV, true, "My Series Name - 1x2-1x4 - My Episode Title [HDTV] [Proper]")]
|
||||
[TestCase(1, new[] { 2, 4 }, "", QualityTypes.HDTV, true, "My Series Name - 1x2-1x4 - [HDTV] [Proper]")]
|
||||
[TestCase(1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, false, "My Series Name - 1x2 - My Episode Title [DVD]")]
|
||||
[TestCase(1, new[] { 2 }, "My Episode Title", QualityTypes.DVD, true, "My Series Name - 1x2 - My Episode Title [DVD] [Proper]")]
|
||||
[TestCase(1, new[] { 2 }, "", QualityTypes.DVD, true, "My Series Name - 1x2 - [DVD] [Proper]")]
|
||||
[TestCase(1, new[] { 2, 4 }, "My Episode Title", QualityTypes.HDTV, false, "My Series Name - 1x2-1x4 - My Episode Title [HDTV]")]
|
||||
[TestCase(1, new[] { 2, 4 }, "My Episode Title", QualityTypes.HDTV, true, "My Series Name - 1x2-1x4 - My Episode Title [HDTV] [Proper]")]
|
||||
[TestCase(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();
|
||||
|
@ -235,7 +282,7 @@ public void sab_title(int seasons, int[] episodes, string title, QualityTypes qu
|
|||
{
|
||||
AirDate = DateTime.Now,
|
||||
EpisodeNumbers = episodes.ToList(),
|
||||
Quality = new Quality(quality,proper),
|
||||
Quality = new Quality(quality, proper),
|
||||
SeasonNumber = seasons,
|
||||
Series = series,
|
||||
Episodes = new List<Episode>() { episode }
|
||||
|
@ -247,5 +294,49 @@ public void sab_title(int seasons, int[] episodes, string title, QualityTypes qu
|
|||
//Assert
|
||||
Assert.AreEqual(excpected, actual);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[Explicit]
|
||||
public void AddNewzbingByUrlSuccess()
|
||||
{
|
||||
//Setup
|
||||
const string sabHost = "192.168.1.50";
|
||||
const int sabPort = 8080;
|
||||
const string apikey = "f37dc33baec2e5566f5aec666287870d";
|
||||
const string username = "root";
|
||||
const string password = "*************";
|
||||
const SabnzbdPriorityType priority = SabnzbdPriorityType.Normal;
|
||||
const string category = "tv";
|
||||
|
||||
|
||||
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);
|
||||
fakeConfig.SetupGet(c => c.SabTvPriority)
|
||||
.Returns(priority);
|
||||
fakeConfig.SetupGet(c => c.SabTvCategory)
|
||||
.Returns(category);
|
||||
|
||||
|
||||
mocker.SetConstant(new HttpProvider());
|
||||
|
||||
//Act
|
||||
bool result = mocker.Resolve<SabProvider>().AddByUrl(
|
||||
"http://www.newzbin.com/browse/post/6107863/nzb", "This is an Nzb");
|
||||
|
||||
//Assert
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using System.Xml.Linq;
|
||||
using NLog;
|
||||
|
@ -30,11 +31,17 @@ public virtual bool AddByUrl(string url, string title)
|
|||
{
|
||||
string cat = _configProvider.SabTvCategory;
|
||||
int priority = (int)_configProvider.SabTvPriority;
|
||||
string name = url.Replace("&", "%26");
|
||||
string name = GetNzbName(url);
|
||||
string nzbName = HttpUtility.UrlEncode(title);
|
||||
|
||||
string action = string.Format("mode=addurl&name={0}&priority={1}&pp=3&cat={2}&nzbname={3}",
|
||||
name, priority, cat, nzbName);
|
||||
|
||||
if (url.ToLower().Contains("newzbin"))
|
||||
{
|
||||
action = action.Replace("mode=addurl", "mode=addid");
|
||||
}
|
||||
|
||||
string request = GetSabRequest(action);
|
||||
|
||||
Logger.Info("Adding report [{0}] to the queue.", title);
|
||||
|
@ -50,6 +57,18 @@ public virtual bool AddByUrl(string url, string title)
|
|||
return false;
|
||||
}
|
||||
|
||||
private static string GetNzbName(string urlString)
|
||||
{
|
||||
var url = new Uri(urlString);
|
||||
if (url.Host.ToLower().Contains("newzbin"))
|
||||
{
|
||||
var postId = Regex.Match(urlString, @"\d{5,10}").Value;
|
||||
return postId;
|
||||
}
|
||||
|
||||
return urlString.Replace("&", "%26");
|
||||
}
|
||||
|
||||
public virtual bool IsInQueue(string title)
|
||||
{
|
||||
const string action = "mode=queue&output=xml";
|
||||
|
|
Loading…
Reference in a new issue