diff --git a/src/NzbDrone.Core.Test/Files/Indexers/Newznab/newznab_indexerflags.xml b/src/NzbDrone.Core.Test/Files/Indexers/Newznab/newznab_indexerflags.xml new file mode 100644 index 000000000..0d70b3707 --- /dev/null +++ b/src/NzbDrone.Core.Test/Files/Indexers/Newznab/newznab_indexerflags.xml @@ -0,0 +1,128 @@ + + + somenewznabindexer.com + somenewznabindexer.com Feed + https://somenewznabindexer.com/ + en-gb + contact@somenewznabindexer.com + + + + title + no custom attributes + link + comments + Sat, 31 Aug 2024 12:28:40 +0300 + category + description + + + + + title + prematch=1 attribute + link + comments + Sat, 31 Aug 2024 12:28:40 +0300 + category + description + + + + + + + title + haspretime=1 attribute + link + comments + Sat, 31 Aug 2024 12:28:40 +0300 + category + description + + + + + + + title + prematch=0 attribute + link + comments + Sat, 31 Aug 2024 12:28:40 +0300 + category + description + + + + + + + title + haspretime=0 attribute + link + comments + Sat, 31 Aug 2024 12:28:40 +0300 + category + description + + + + + + + title + nuked=1 attribute + link + comments + Sat, 31 Aug 2024 12:28:40 +0300 + category + description + + + + + + + title + nuked=0 attribute + link + comments + Sat, 31 Aug 2024 12:28:40 +0300 + category + description + + + + + + + title + prematch=1 and nuked=1 attributes + link + comments + Sat, 31 Aug 2024 12:28:40 +0300 + category + description + + + + + + + + title + haspretime=0 and nuked=0 attributes + link + comments + Sat, 31 Aug 2024 12:28:40 +0300 + category + description + + + + + + + + \ No newline at end of file diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs index d400f6f5f..3530c137f 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabFixture.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Threading.Tasks; +using DryIoc.ImTools; using FluentAssertions; using Moq; using NUnit.Framework; @@ -154,5 +155,29 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests releases[1].Languages.Should().BeEquivalentTo(new[] { Language.English, Language.Spanish }); releases[2].Languages.Should().BeEquivalentTo(new[] { Language.French }); } + + [TestCase("no custom attributes")] + [TestCase("prematch=1 attribute", IndexerFlags.Scene)] + [TestCase("haspretime=1 attribute", IndexerFlags.Scene)] + [TestCase("prematch=0 attribute")] + [TestCase("haspretime=0 attribute")] + [TestCase("nuked=1 attribute", IndexerFlags.Nuked)] + [TestCase("nuked=0 attribute")] + [TestCase("prematch=1 and nuked=1 attributes", IndexerFlags.Scene, IndexerFlags.Nuked)] + [TestCase("haspretime=0 and nuked=0 attributes")] + public async Task should_parse_indexer_flags(string releaseGuid, params IndexerFlags[] indexerFlags) + { + var feed = ReadAllText(@"Files/Indexers/Newznab/newznab_indexerflags.xml"); + + Mocker.GetMock() + .Setup(o => o.ExecuteAsync(It.Is(v => v.Method == HttpMethod.Get))) + .Returns(r => Task.FromResult(new HttpResponse(r, new HttpHeader(), feed))); + + var releases = await Subject.FetchRecent(); + + var release = releases.Should().ContainSingle(r => r.Guid == releaseGuid).Subject; + + indexerFlags.ForEach(f => release.IndexerFlags.Should().HaveFlag(f)); + } } } diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs index 408d22b36..f43f0b5d4 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs @@ -91,6 +91,7 @@ namespace NzbDrone.Core.Indexers.Newznab releaseInfo.TvdbId = GetTvdbId(item); releaseInfo.TvRageId = GetTvRageId(item); releaseInfo.ImdbId = GetImdbId(item); + releaseInfo.IndexerFlags = GetFlags(item); return releaseInfo; } @@ -195,6 +196,23 @@ namespace NzbDrone.Core.Indexers.Newznab return null; } + protected IndexerFlags GetFlags(XElement item) + { + IndexerFlags flags = 0; + + if (TryGetNewznabAttribute(item, "prematch") == "1" || TryGetNewznabAttribute(item, "haspretime") == "1") + { + flags |= IndexerFlags.Scene; + } + + if (TryGetNewznabAttribute(item, "nuked") == "1") + { + flags |= IndexerFlags.Nuked; + } + + return flags; + } + protected string TryGetNewznabAttribute(XElement item, string key, string defaultValue = "") { var attrElement = item.Elements(ns + "attr").FirstOrDefault(e => e.Attribute("name").Value.Equals(key, StringComparison.OrdinalIgnoreCase)); diff --git a/src/NzbDrone.Core/Parser/Model/IndexerFlags.cs b/src/NzbDrone.Core/Parser/Model/IndexerFlags.cs new file mode 100644 index 000000000..dbc45df5c --- /dev/null +++ b/src/NzbDrone.Core/Parser/Model/IndexerFlags.cs @@ -0,0 +1,48 @@ +using System; + +namespace NzbDrone.Core.Parser.Model +{ + [Flags] + public enum IndexerFlags + { + /// + /// Torrent download amount does not count + /// + Freeleech = 1, + + /// + /// Torrent download amount only counts 50% + /// + Halfleech = 2, + + /// + /// Torrent upload amount is doubled + /// + DoubleUpload = 4, + + /// + /// Uploader is an internal release group + /// + Internal = 8, + + /// + /// The release comes from a scene group + /// + Scene = 16, + + /// + /// Torrent download amount only counts 75% + /// + Freeleech75 = 32, + + /// + /// Torrent download amount only counts 25% + /// + Freeleech25 = 64, + + /// + /// The release is nuked + /// + Nuked = 128 + } +} diff --git a/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs b/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs index 1266ac10c..19c3ad335 100644 --- a/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs +++ b/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs @@ -111,16 +111,4 @@ namespace NzbDrone.Core.Parser.Model } } } - - [Flags] - public enum IndexerFlags - { - Freeleech = 1, // General - Halfleech = 2, // General, only 1/2 of download counted - DoubleUpload = 4, // General - Internal = 8, // General, uploader is an internal release group - Scene = 16, // General, the torrent comes from a "scene" group - Freeleech75 = 32, // Signifies a torrent counts towards 75 percent of your download quota. - Freeleech25 = 64, // Signifies a torrent counts towards 25 percent of your download quota. - } }