From 3ad7673d697d983af3ee900d010cff47ef5f9fc8 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Mon, 13 Jul 2015 20:26:00 +0200 Subject: [PATCH] Fixed: Doki rss feed now uses correct url for torrent. --- .../TorrentRssIndexerFixture.cs | 28 +++++++++++++++++++ .../TorrentRssSettingsDetectorFixture.cs | 26 +++++++++++++++++ .../TorrentRssIndexerParserSettings.cs | 1 + .../TorrentRss/TorrentRssParserFactory.cs | 1 + .../TorrentRss/TorrentRssSettingsDetector.cs | 17 +++++++++-- .../Indexers/TorrentRssParser.cs | 9 ++++++ 6 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core.Test/IndexerTests/TorrentRssIndexerTests/TorrentRssIndexerFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/TorrentRssIndexerTests/TorrentRssIndexerFixture.cs index 097ac2ec4..0ca248dfd 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/TorrentRssIndexerTests/TorrentRssIndexerFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/TorrentRssIndexerTests/TorrentRssIndexerFixture.cs @@ -123,5 +123,33 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests torrentInfo.Peers.Should().NotHaveValue(); torrentInfo.Seeders.Should().NotHaveValue(); } + + [Test] + public void should_parse_recent_feed_from_Doki() + { + Subject.Definition.Settings.As().AllowZeroSize = true; + + GivenRecentFeedResponse("TorrentRss/Doki.xml"); + + var releases = Subject.FetchRecent(); + + releases.Should().HaveCount(5); + releases.First().Should().BeOfType(); + + var torrentInfo = releases.First() as TorrentInfo; + + torrentInfo.Title.Should().Be("[Doki] PriPara 50 (848x480 h264 AAC) [6F0B49FD] mkv"); + torrentInfo.DownloadProtocol.Should().Be(DownloadProtocol.Torrent); + torrentInfo.DownloadUrl.Should().Be("http://tracker.anime-index.org/download.php?id=82d8ad84403e01a7786130905ca169a3429e657f&f=%5BDoki%5D+PriPara+-+50+%28848x480+h264+AAC%29+%5B6F0B49FD%5D.mkv.torrent"); + torrentInfo.InfoUrl.Should().BeNullOrEmpty(); + torrentInfo.CommentUrl.Should().BeNullOrEmpty(); + torrentInfo.Indexer.Should().Be(Subject.Definition.Name); + torrentInfo.PublishDate.Should().Be(DateTime.Parse("Thu, 02 Jul 2015 08:18:29 GMT").ToUniversalTime()); + torrentInfo.Size.Should().Be(0); + torrentInfo.InfoHash.Should().BeNull(); + torrentInfo.MagnetUrl.Should().BeNull(); + torrentInfo.Peers.Should().NotHaveValue(); + torrentInfo.Seeders.Should().NotHaveValue(); + } } } diff --git a/src/NzbDrone.Core.Test/IndexerTests/TorrentRssIndexerTests/TorrentRssSettingsDetectorFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/TorrentRssIndexerTests/TorrentRssSettingsDetectorFixture.cs index 62b35bc66..df4753f2c 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/TorrentRssIndexerTests/TorrentRssSettingsDetectorFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/TorrentRssIndexerTests/TorrentRssSettingsDetectorFixture.cs @@ -43,6 +43,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests settings.ShouldBeEquivalentTo(new TorrentRssIndexerParserSettings { UseEZTVFormat = true, + UseEnclosureUrl = false, UseEnclosureLength = false, ParseSizeInDescription = false, ParseSeedersInDescription = false, @@ -60,6 +61,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests settings.ShouldBeEquivalentTo(new TorrentRssIndexerParserSettings { UseEZTVFormat = false, + UseEnclosureUrl = false, UseEnclosureLength = false, ParseSizeInDescription = true, ParseSeedersInDescription = false, @@ -77,6 +79,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests settings.ShouldBeEquivalentTo(new TorrentRssIndexerParserSettings { UseEZTVFormat = false, + UseEnclosureUrl = false, UseEnclosureLength = false, ParseSizeInDescription = true, ParseSeedersInDescription = true, @@ -96,6 +99,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests settings.ShouldBeEquivalentTo(new TorrentRssIndexerParserSettings { UseEZTVFormat = false, + UseEnclosureUrl = true, UseEnclosureLength = false, ParseSizeInDescription = false, ParseSeedersInDescription = false, @@ -113,6 +117,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests settings.ShouldBeEquivalentTo(new TorrentRssIndexerParserSettings { UseEZTVFormat = false, + UseEnclosureUrl = true, UseEnclosureLength = false, ParseSizeInDescription = true, ParseSeedersInDescription = false, @@ -130,6 +135,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests settings.ShouldBeEquivalentTo(new TorrentRssIndexerParserSettings { UseEZTVFormat = false, + UseEnclosureUrl = false, UseEnclosureLength = false, ParseSizeInDescription = false, ParseSeedersInDescription = false, @@ -137,6 +143,26 @@ namespace NzbDrone.Core.Test.IndexerTests.TorrentRssIndexerTests }); } + [Test] + public void should_detect_rss_settings_for_Doki() + { + _indexerSettings.AllowZeroSize = true; + + GivenRecentFeedResponse("TorrentRss/Doki.xml"); + + var settings = Subject.Detect(_indexerSettings); + + settings.ShouldBeEquivalentTo(new TorrentRssIndexerParserSettings + { + UseEZTVFormat = false, + UseEnclosureUrl = true, + UseEnclosureLength = false, + ParseSizeInDescription = false, + ParseSeedersInDescription = false, + SizeElementName = null + }); + } + [Test] [Ignore("Cannot reliably reject unparseable titles")] public void should_reject_rss_settings_for_AwesomeHD() diff --git a/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssIndexerParserSettings.cs b/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssIndexerParserSettings.cs index ecfd55abf..46e7226bc 100644 --- a/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssIndexerParserSettings.cs +++ b/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssIndexerParserSettings.cs @@ -6,6 +6,7 @@ namespace NzbDrone.Core.Indexers.TorrentRss { public bool UseEZTVFormat { get; set; } public bool ParseSeedersInDescription { get; set; } + public bool UseEnclosureUrl { get; set; } public bool UseEnclosureLength { get; set; } public bool ParseSizeInDescription { get; set; } public string SizeElementName { get; set; } diff --git a/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssParserFactory.cs b/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssParserFactory.cs index d3e47e591..a60e3cd9c 100644 --- a/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssParserFactory.cs +++ b/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssParserFactory.cs @@ -42,6 +42,7 @@ namespace NzbDrone.Core.Indexers.TorrentRss UseGuidInfoUrl = false, ParseSeedersInDescription = parserSettings.ParseSeedersInDescription, + UseEnclosureUrl = parserSettings.UseEnclosureUrl, UseEnclosureLength = parserSettings.UseEnclosureLength, ParseSizeInDescription = parserSettings.ParseSizeInDescription, SizeElementName = parserSettings.SizeElementName diff --git a/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssSettingsDetector.cs b/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssSettingsDetector.cs index 16a4c185c..7e0f55932 100644 --- a/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssSettingsDetector.cs +++ b/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssSettingsDetector.cs @@ -107,18 +107,31 @@ namespace NzbDrone.Core.Indexers.TorrentRss private TorrentRssIndexerParserSettings GetGenericTorrentRssParserSettings(IndexerResponse response, TorrentRssIndexerSettings indexerSettings) { - var settings = new TorrentRssIndexerParserSettings + var parser = new TorrentRssParser { + UseEnclosureUrl = true, UseEnclosureLength = true, ParseSeedersInDescription = true }; - var parser = new TorrentRssParser + var item = parser.GetItems(response).FirstOrDefault(); + if (item == null) { + throw new UnsupportedFeedException("Empty feed, cannot check if feed is parsable."); + } + + var settings = new TorrentRssIndexerParserSettings() + { + UseEnclosureUrl = true, UseEnclosureLength = true, ParseSeedersInDescription = true }; + if (item.Element("enclosure") == null) + { + parser.UseEnclosureUrl = settings.UseEnclosureUrl = false; + } + var releases = ParseResponse(parser, response); ValidateReleases(releases, indexerSettings); diff --git a/src/NzbDrone.Core/Indexers/TorrentRssParser.cs b/src/NzbDrone.Core/Indexers/TorrentRssParser.cs index 53aae1986..de5ba8a71 100644 --- a/src/NzbDrone.Core/Indexers/TorrentRssParser.cs +++ b/src/NzbDrone.Core/Indexers/TorrentRssParser.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Text.RegularExpressions; using System.Xml.Linq; using NzbDrone.Common.Extensions; @@ -19,6 +20,14 @@ namespace NzbDrone.Core.Indexers } + public IEnumerable GetItems(IndexerResponse indexerResponse) + { + var document = LoadXmlDocument(indexerResponse); + var items = GetItems(document); + + return items; + } + protected override ReleaseInfo CreateNewReleaseInfo() { return new TorrentInfo();