diff --git a/src/NzbDrone.Core.Test/IndexerTests/KickassTorrentsTests/KickassTorrentsFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/KickassTorrentsTests/KickassTorrentsFixture.cs index d85f90f03..e7ee1255e 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/KickassTorrentsTests/KickassTorrentsFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/KickassTorrentsTests/KickassTorrentsFixture.cs @@ -9,6 +9,7 @@ using NzbDrone.Test.Common; using System; using System.Linq; using FluentAssertions; +using System.Text.RegularExpressions; namespace NzbDrone.Core.Test.IndexerTests.KickassTorrentsTests { @@ -85,5 +86,50 @@ namespace NzbDrone.Core.Test.IndexerTests.KickassTorrentsTests releases.Should().HaveCount(4); } + [Test] + public void should_set_seeders_to_null() + { + // Atm, Kickass supplies 0 as seeders and leechers on the rss feed (but not the site), so set it to null if there aren't any peers. + var recentFeed = ReadAllText(@"Files/Indexers/KickassTorrents/KickassTorrents.xml"); + + recentFeed = Regex.Replace(recentFeed, @"(seeds|peers)\>\d*", "$1>0"); + + Mocker.GetMock() + .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.GET))) + .Returns(r => new HttpResponse(r, new HttpHeader(), recentFeed)); + + var releases = Subject.FetchRecent(); + + releases.Should().HaveCount(5); + releases.First().Should().BeOfType(); + + var torrentInfo = (TorrentInfo)releases.First(); + + torrentInfo.Peers.Should().NotHaveValue(); + torrentInfo.Seeders.Should().NotHaveValue(); + } + + [Test] + public void should_not_set_seeders_to_null_if_has_peers() + { + // Atm, Kickass supplies 0 as seeders and leechers on the rss feed (but not the site), so set it to null if there aren't any peers. + var recentFeed = ReadAllText(@"Files/Indexers/KickassTorrents/KickassTorrents.xml"); + + recentFeed = Regex.Replace(recentFeed, @"(seeds)\>\d*", "$1>0"); + + Mocker.GetMock() + .Setup(o => o.Execute(It.Is(v => v.Method == HttpMethod.GET))) + .Returns(r => new HttpResponse(r, new HttpHeader(), recentFeed)); + + var releases = Subject.FetchRecent(); + + releases.Should().HaveCount(5); + releases.First().Should().BeOfType(); + + var torrentInfo = (TorrentInfo)releases.First(); + + torrentInfo.Peers.Should().HaveValue(); + torrentInfo.Seeders.Should().HaveValue(); + } } } diff --git a/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRssParser.cs b/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRssParser.cs index 4b1529c21..ef3f2744f 100644 --- a/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRssParser.cs +++ b/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRssParser.cs @@ -28,6 +28,14 @@ namespace NzbDrone.Core.Indexers.KickassTorrents return null; } + // Atm, Kickass supplies 0 as seeders and leechers on the rss feed (but not the site), so set it to null if there aren't any peers. + var torrentInfo = releaseInfo as TorrentInfo; + if (torrentInfo.Peers.HasValue && torrentInfo.Peers.Value == 0) + { + torrentInfo.Seeders = null; + torrentInfo.Peers = null; + } + return base.PostProcess(item, releaseInfo); } }