HDBits fixup.

pull/4/head
Taloth Saldono 9 years ago
parent 3ae2883eb5
commit 4a6778c609

@ -1,20 +1,21 @@
using Moq; using System;
using System.Linq;
using System.Text;
using FluentAssertions;
using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.HDBits; using NzbDrone.Core.Indexers.HDBits;
using NzbDrone.Core.Test.Framework;
using FluentAssertions;
using System.Linq;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using System; using NzbDrone.Core.Test.Framework;
using System.Text;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.IndexerTests.HdBitsTests namespace NzbDrone.Core.Test.IndexerTests.HDBitsTests
{ {
[TestFixture] [TestFixture]
public class HdBitsFixture : CoreTest<HdBits> public class HDBitsFixture : CoreTest<HDBits>
{ {
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -22,12 +23,12 @@ namespace NzbDrone.Core.Test.IndexerTests.HdBitsTests
Subject.Definition = new IndexerDefinition() Subject.Definition = new IndexerDefinition()
{ {
Name = "HdBits", Name = "HdBits",
Settings = new HdBitsSettings() { ApiKey = "fakekey" } Settings = new HDBitsSettings() { ApiKey = "fakekey" }
}; };
} }
[Test] [Test]
public void TestSimpleResponse() public void should_parse_recent_feed_from_HDBits()
{ {
var responseJson = ReadAllText(@"Files/Indexers/HdBits/RecentFeed.json"); var responseJson = ReadAllText(@"Files/Indexers/HdBits/RecentFeed.json");
@ -49,19 +50,17 @@ namespace NzbDrone.Core.Test.IndexerTests.HdBitsTests
first.InfoUrl.Should().Be("https://hdbits.org/details.php?id=257142"); first.InfoUrl.Should().Be("https://hdbits.org/details.php?id=257142");
first.PublishDate.Should().Be(DateTime.Parse("2015-04-04T20:30:46+0000")); first.PublishDate.Should().Be(DateTime.Parse("2015-04-04T20:30:46+0000"));
first.Size.Should().Be(1718009717); first.Size.Should().Be(1718009717);
first.InfoHash.Should().Be("EABC50AEF9F53CEDED84ADF14144D3368E586F3A");
first.MagnetUrl.Should().BeNullOrEmpty(); first.MagnetUrl.Should().BeNullOrEmpty();
first.Peers.Should().Be(47); first.Peers.Should().Be(47);
first.Seeders.Should().Be(46); first.Seeders.Should().Be(46);
} }
[Test] [Test]
public void TestBadPasskey() public void should_warn_on_wrong_passkey()
{ {
var responseJson = @" var responseJson = new { status = 5, message = "Invalid authentication credentials" }.ToJson();
{
""status"": 5,
""message"": ""Invalid authentication credentials""
}";
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(v => v.Execute(It.IsAny<HttpRequest>())) .Setup(v => v.Execute(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(),

@ -204,7 +204,7 @@
<Compile Include="IndexerTests\BitMeTvTests\BitMeTvFixture.cs" /> <Compile Include="IndexerTests\BitMeTvTests\BitMeTvFixture.cs" />
<Compile Include="IndexerTests\BroadcastheNetTests\BroadcastheNetFixture.cs" /> <Compile Include="IndexerTests\BroadcastheNetTests\BroadcastheNetFixture.cs" />
<Compile Include="IndexerTests\EztvTests\EztvFixture.cs" /> <Compile Include="IndexerTests\EztvTests\EztvFixture.cs" />
<Compile Include="IndexerTests\HdBitsTests\HdBitsFixture.cs" /> <Compile Include="IndexerTests\HDBitsTests\HDBitsFixture.cs" />
<Compile Include="IndexerTests\IndexerServiceFixture.cs" /> <Compile Include="IndexerTests\IndexerServiceFixture.cs" />
<Compile Include="IndexerTests\IntegrationTests\IndexerIntegrationTests.cs" /> <Compile Include="IndexerTests\IntegrationTests\IndexerIntegrationTests.cs" />
<Compile Include="IndexerTests\TorznabTests\TorznabFixture.cs" /> <Compile Include="IndexerTests\TorznabTests\TorznabFixture.cs" />

@ -1,19 +1,20 @@
using NLog; using System;
using NLog;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using System;
namespace NzbDrone.Core.Indexers.HDBits namespace NzbDrone.Core.Indexers.HDBits
{ {
public class HdBits : HttpIndexerBase<HdBitsSettings> public class HDBits : HttpIndexerBase<HDBitsSettings>
{ {
public override string Name { get { return "HDBits"; } }
public override DownloadProtocol Protocol { get { return DownloadProtocol.Torrent; } } public override DownloadProtocol Protocol { get { return DownloadProtocol.Torrent; } }
public override bool SupportsRss { get { return true; } } public override bool SupportsRss { get { return true; } }
public override bool SupportsSearch { get { return true; } } public override bool SupportsSearch { get { return true; } }
public override int PageSize { get { return 30; } } public override int PageSize { get { return 30; } }
public HdBits(IHttpClient httpClient, public HDBits(IHttpClient httpClient,
IConfigService configService, IConfigService configService,
IParsingService parsingService, IParsingService parsingService,
Logger logger) Logger logger)
@ -22,12 +23,12 @@ namespace NzbDrone.Core.Indexers.HDBits
public override IIndexerRequestGenerator GetRequestGenerator() public override IIndexerRequestGenerator GetRequestGenerator()
{ {
return new HdBitsRequestGenerator() { Settings = Settings }; return new HDBitsRequestGenerator() { Settings = Settings };
} }
public override IParseIndexerResponse GetParser() public override IParseIndexerResponse GetParser()
{ {
return new HdBitsParser(Settings); return new HDBitsParser(Settings);
} }
} }
} }

@ -1,5 +1,5 @@
using Newtonsoft.Json; using System;
using System; using Newtonsoft.Json;
namespace NzbDrone.Core.Indexers.HDBits namespace NzbDrone.Core.Indexers.HDBits
{ {
@ -44,7 +44,7 @@ namespace NzbDrone.Core.Indexers.HDBits
} }
} }
public class HdBitsResponse public class HDBitsResponse
{ {
[JsonProperty(Required = Required.Always)] [JsonProperty(Required = Required.Always)]
public StatusCode Status { get; set; } public StatusCode Status { get; set; }

@ -1,20 +1,20 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Core.Parser.Model; using System.Collections.Specialized;
using System.Net; using System.Net;
using NzbDrone.Core.Indexers.Exceptions; using System.Web;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Web; using NzbDrone.Core.Indexers.Exceptions;
using System.Collections.Specialized; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Indexers.HDBits namespace NzbDrone.Core.Indexers.HDBits
{ {
public class HdBitsParser : IParseIndexerResponse public class HDBitsParser : IParseIndexerResponse
{ {
private readonly HdBitsSettings _settings; private readonly HDBitsSettings _settings;
public HdBitsParser(HdBitsSettings settings) public HDBitsParser(HDBitsSettings settings)
{ {
_settings = settings; _settings = settings;
} }
@ -25,28 +25,25 @@ namespace NzbDrone.Core.Indexers.HDBits
if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK) if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
{ {
throw new IndexerException( throw new IndexerException(indexerResponse,
indexerResponse,
"Unexpected response status {0} code from API request", "Unexpected response status {0} code from API request",
indexerResponse.HttpResponse.StatusCode); indexerResponse.HttpResponse.StatusCode);
} }
var jsonResponse = JsonConvert.DeserializeObject<HdBitsResponse>(indexerResponse.Content); var jsonResponse = JsonConvert.DeserializeObject<HDBitsResponse>(indexerResponse.Content);
if (jsonResponse.Status != StatusCode.Success) if (jsonResponse.Status != StatusCode.Success)
{ {
throw new IndexerException( throw new IndexerException(indexerResponse,
indexerResponse, "HDBits API request returned status code {0}: {1}",
@"HDBits API request returned status code {0} with message ""{1}""",
jsonResponse.Status, jsonResponse.Status,
jsonResponse.Message ?? ""); jsonResponse.Message ?? string.Empty);
} }
var responseData = jsonResponse.Data as JArray; var responseData = jsonResponse.Data as JArray;
if (responseData == null) if (responseData == null)
{ {
throw new IndexerException( throw new IndexerException(indexerResponse,
indexerResponse,
"Indexer API call response missing result data"); "Indexer API call response missing result data");
} }
@ -60,6 +57,7 @@ namespace NzbDrone.Core.Indexers.HDBits
Guid = string.Format("HDBits-{0}", id), Guid = string.Format("HDBits-{0}", id),
Title = result.Name, Title = result.Name,
Size = result.Size, Size = result.Size,
InfoHash = result.Hash,
DownloadUrl = GetDownloadUrl(id), DownloadUrl = GetDownloadUrl(id),
InfoUrl = GetInfoUrl(id), InfoUrl = GetInfoUrl(id),
Seeders = result.Seeders, Seeders = result.Seeders,

@ -1,16 +1,15 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Core.IndexerSearch.Definitions; using System.Linq;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer; using NzbDrone.Common.Serializer;
using System.Linq; using NzbDrone.Core.IndexerSearch.Definitions;
namespace NzbDrone.Core.Indexers.HDBits namespace NzbDrone.Core.Indexers.HDBits
{ {
public class HdBitsRequestGenerator : IIndexerRequestGenerator public class HDBitsRequestGenerator : IIndexerRequestGenerator
{ {
public HdBitsSettings Settings { get; set; } public HDBitsSettings Settings { get; set; }
public IList<IEnumerable<IndexerRequest>> GetRecentRequests() public IList<IEnumerable<IndexerRequest>> GetRecentRequests()
{ {

@ -1,25 +1,25 @@
using System; using System;
using FluentValidation; using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation; using NzbDrone.Core.Validation;
using NzbDrone.Core.Annotations;
namespace NzbDrone.Core.Indexers.HDBits namespace NzbDrone.Core.Indexers.HDBits
{ {
public class HdBitsSettingsValidator : AbstractValidator<HdBitsSettings> public class HDBitsSettingsValidator : AbstractValidator<HDBitsSettings>
{ {
public HdBitsSettingsValidator() public HDBitsSettingsValidator()
{ {
RuleFor(c => c.BaseUrl).ValidRootUrl(); RuleFor(c => c.BaseUrl).ValidRootUrl();
RuleFor(c => c.ApiKey).NotEmpty(); RuleFor(c => c.ApiKey).NotEmpty();
} }
} }
public class HdBitsSettings : IProviderConfig public class HDBitsSettings : IProviderConfig
{ {
private static readonly HdBitsSettingsValidator Validator = new HdBitsSettingsValidator(); private static readonly HDBitsSettingsValidator Validator = new HDBitsSettingsValidator();
public HdBitsSettings() public HDBitsSettings()
{ {
BaseUrl = "https://hdbits.org"; BaseUrl = "https://hdbits.org";
} }

@ -479,11 +479,11 @@
<Compile Include="Indexers\Fanzub\FanzubRequestGenerator.cs" /> <Compile Include="Indexers\Fanzub\FanzubRequestGenerator.cs" />
<Compile Include="Indexers\Fanzub\FanzubSettings.cs" /> <Compile Include="Indexers\Fanzub\FanzubSettings.cs" />
<Compile Include="Indexers\FetchAndParseRssService.cs" /> <Compile Include="Indexers\FetchAndParseRssService.cs" />
<Compile Include="Indexers\HDBits\HdBits.cs" /> <Compile Include="Indexers\HDBits\HDBits.cs" />
<Compile Include="Indexers\HDBits\HdBitsApi.cs" /> <Compile Include="Indexers\HDBits\HDBitsApi.cs" />
<Compile Include="Indexers\HDBits\HdBitsParser.cs" /> <Compile Include="Indexers\HDBits\HDBitsParser.cs" />
<Compile Include="Indexers\HDBits\HdBitsRequestGenerator.cs" /> <Compile Include="Indexers\HDBits\HDBitsRequestGenerator.cs" />
<Compile Include="Indexers\HDBits\HdBitsSettings.cs" /> <Compile Include="Indexers\HDBits\HDBitsSettings.cs" />
<Compile Include="Indexers\IIndexer.cs" /> <Compile Include="Indexers\IIndexer.cs" />
<Compile Include="Indexers\IIndexerRequestGenerator.cs" /> <Compile Include="Indexers\IIndexerRequestGenerator.cs" />
<Compile Include="Indexers\IndexerBase.cs" /> <Compile Include="Indexers\IndexerBase.cs" />

Loading…
Cancel
Save