From c63b65eba132988a98b5a2b0a7b29ffc41634aae Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Thu, 24 Sep 2015 22:33:01 +0200 Subject: [PATCH] Only apply kat peers fix for recent releases. --- .../KickassTorrentsFixture.cs | 31 ++++++++++++++++--- .../KickassTorrentsRssParser.cs | 6 ++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Core.Test/IndexerTests/KickassTorrentsTests/KickassTorrentsFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/KickassTorrentsTests/KickassTorrentsFixture.cs index e7ee1255e..14446ef52 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/KickassTorrentsTests/KickassTorrentsFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/KickassTorrentsTests/KickassTorrentsFixture.cs @@ -52,8 +52,6 @@ namespace NzbDrone.Core.Test.IndexerTests.KickassTorrentsTests torrentInfo.Size.Should().Be(1205364736); torrentInfo.InfoHash.Should().Be("208C4F7866612CC88BFEBC7C496FA72C2368D1C0"); torrentInfo.MagnetUrl.Should().Be("magnet:?xt=urn:btih:208C4F7866612CC88BFEBC7C496FA72C2368D1C0&dn=doctor+stranger+e03+140512+hdtv+h264+720p+ipop+avi+ctrg&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce"); - torrentInfo.Peers.Should().Be(311); - torrentInfo.Seeders.Should().Be(206); } [Test] @@ -92,6 +90,7 @@ namespace NzbDrone.Core.Test.IndexerTests.KickassTorrentsTests // 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 = recentFeed.Replace("Mon, 12 May 2014 16:16:49 +0000", string.Format("{0:R}", DateTime.UtcNow)); recentFeed = Regex.Replace(recentFeed, @"(seeds|peers)\>\d*", "$1>0"); Mocker.GetMock() @@ -115,6 +114,7 @@ namespace NzbDrone.Core.Test.IndexerTests.KickassTorrentsTests // 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 = recentFeed.Replace("Mon, 12 May 2014 16:16:49 +0000", string.Format("{0:R}", DateTime.UtcNow)); recentFeed = Regex.Replace(recentFeed, @"(seeds)\>\d*", "$1>0"); Mocker.GetMock() @@ -128,8 +128,31 @@ namespace NzbDrone.Core.Test.IndexerTests.KickassTorrentsTests var torrentInfo = (TorrentInfo)releases.First(); - torrentInfo.Peers.Should().HaveValue(); - torrentInfo.Seeders.Should().HaveValue(); + torrentInfo.Peers.Should().Be(311); + torrentInfo.Seeders.Should().Be(0); + } + + [Test] + public void should_not_set_seeders_to_null_if_older_than_12_hours() + { + // 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().Be(0); + torrentInfo.Seeders.Should().Be(0); } } } diff --git a/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRssParser.cs b/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRssParser.cs index ef3f2744f..7e9e58235 100644 --- a/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRssParser.cs +++ b/src/NzbDrone.Core/Indexers/KickassTorrents/KickassTorrentsRssParser.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using System.Xml.Linq; using NzbDrone.Common.Extensions; @@ -28,9 +29,10 @@ 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. + // Atm, Kickass supplies 0 as seeders and leechers on the rss feed for recent releases, so set it to null if there aren't any peers. + // But only for releases younger than 12h (the real number seems to be close to 14h, but it depends on a number of factors). var torrentInfo = releaseInfo as TorrentInfo; - if (torrentInfo.Peers.HasValue && torrentInfo.Peers.Value == 0) + if (torrentInfo.Peers.HasValue && torrentInfo.Peers.Value == 0 && torrentInfo.PublishDate > DateTime.UtcNow.AddHours(-12)) { torrentInfo.Seeders = null; torrentInfo.Peers = null;