1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-20 01:42:35 +01:00

New: Scene and Nuked IndexerFlags for Newznab indexers

(cherry picked from commit 278c7891a3add639b4ff5bc1f4f5e8912dabc897)
This commit is contained in:
amdavie 2024-09-02 14:25:53 -06:00 committed by Bogdan
parent 7528882adf
commit 6095819005
5 changed files with 237 additions and 18 deletions

View File

@ -0,0 +1,128 @@
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:newznab="http://www.newznab.com/DTD/2010/feeds/attributes/">
<channel>
<title>somenewznabindexer.com</title>
<description>somenewznabindexer.com Feed</description>
<link>https://somenewznabindexer.com/</link>
<language>en-gb</language>
<webMaster>contact@somenewznabindexer.com</webMaster>
<category/>
<newznab:response offset="0" total="100"/>
<item>
<title>title</title>
<guid isPermaLink="true">no custom attributes</guid>
<link>link</link>
<comments>comments</comments>
<pubDate>Sat, 31 Aug 2024 12:28:40 +0300</pubDate>
<category>category</category>
<description>description</description>
<enclosure url="url" length="500" type="application/x-nzb"/>
</item>
<item>
<title>title</title>
<guid isPermaLink="true">prematch=1 attribute</guid>
<link>link</link>
<comments>comments</comments>
<pubDate>Sat, 31 Aug 2024 12:28:40 +0300</pubDate>
<category>category</category>
<description>description</description>
<enclosure url="url" length="500" type="application/x-nzb"/>
<newznab:attr name="prematch" value="1"/>
</item>
<item>
<title>title</title>
<guid isPermaLink="true">haspretime=1 attribute</guid>
<link>link</link>
<comments>comments</comments>
<pubDate>Sat, 31 Aug 2024 12:28:40 +0300</pubDate>
<category>category</category>
<description>description</description>
<enclosure url="url" length="500" type="application/x-nzb"/>
<newznab:attr name="haspretime" value="1"/>
</item>
<item>
<title>title</title>
<guid isPermaLink="true">prematch=0 attribute</guid>
<link>link</link>
<comments>comments</comments>
<pubDate>Sat, 31 Aug 2024 12:28:40 +0300</pubDate>
<category>category</category>
<description>description</description>
<enclosure url="url" length="500" type="application/x-nzb"/>
<newznab:attr name="prematch" value="0"/>
</item>
<item>
<title>title</title>
<guid isPermaLink="true">haspretime=0 attribute</guid>
<link>link</link>
<comments>comments</comments>
<pubDate>Sat, 31 Aug 2024 12:28:40 +0300</pubDate>
<category>category</category>
<description>description</description>
<enclosure url="url" length="500" type="application/x-nzb"/>
<newznab:attr name="haspretime" value="0"/>
</item>
<item>
<title>title</title>
<guid isPermaLink="true">nuked=1 attribute</guid>
<link>link</link>
<comments>comments</comments>
<pubDate>Sat, 31 Aug 2024 12:28:40 +0300</pubDate>
<category>category</category>
<description>description</description>
<enclosure url="url" length="500" type="application/x-nzb"/>
<newznab:attr name="nuked" value="1"/>
</item>
<item>
<title>title</title>
<guid isPermaLink="true">nuked=0 attribute</guid>
<link>link</link>
<comments>comments</comments>
<pubDate>Sat, 31 Aug 2024 12:28:40 +0300</pubDate>
<category>category</category>
<description>description</description>
<enclosure url="url" length="500" type="application/x-nzb"/>
<newznab:attr name="nuked" value="0"/>
</item>
<item>
<title>title</title>
<guid isPermaLink="true">prematch=1 and nuked=1 attributes</guid>
<link>link</link>
<comments>comments</comments>
<pubDate>Sat, 31 Aug 2024 12:28:40 +0300</pubDate>
<category>category</category>
<description>description</description>
<enclosure url="url" length="500" type="application/x-nzb"/>
<newznab:attr name="prematch" value="1"/>
<newznab:attr name="nuked" value="1"/>
</item>
<item>
<title>title</title>
<guid isPermaLink="true">haspretime=0 and nuked=0 attributes</guid>
<link>link</link>
<comments>comments</comments>
<pubDate>Sat, 31 Aug 2024 12:28:40 +0300</pubDate>
<category>category</category>
<description>description</description>
<enclosure url="url" length="500" type="application/x-nzb"/>
<newznab:attr name="haspretime" value="0"/>
<newznab:attr name="nuked" value="0"/>
</item>
</channel>
</rss>

View File

@ -9,6 +9,7 @@
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Newznab; using NzbDrone.Core.Indexers.Newznab;
using NzbDrone.Core.Languages; using NzbDrone.Core.Languages;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.IndexerTests.NewznabTests namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
@ -98,5 +99,29 @@ public async Task should_parse_languages()
releases[1].Languages.Should().BeEquivalentTo(new[] { Language.English, Language.Spanish }); releases[1].Languages.Should().BeEquivalentTo(new[] { Language.English, Language.Spanish });
releases[2].Languages.Should().BeEquivalentTo(new[] { Language.French }); releases[2].Languages.Should().BeEquivalentTo(new[] { Language.French });
} }
[TestCase("no custom attributes")]
[TestCase("prematch=1 attribute", IndexerFlags.G_Scene)]
[TestCase("haspretime=1 attribute", IndexerFlags.G_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.G_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<IHttpClient>()
.Setup(o => o.ExecuteAsync(It.Is<HttpRequest>(v => v.Method == HttpMethod.Get)))
.Returns<HttpRequest>(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.ToList().ForEach(f => release.IndexerFlags.Should().HaveFlag(f));
}
} }
} }

View File

@ -92,6 +92,7 @@ protected override ReleaseInfo ProcessItem(XElement item, ReleaseInfo releaseInf
{ {
releaseInfo = base.ProcessItem(item, releaseInfo); releaseInfo = base.ProcessItem(item, releaseInfo);
releaseInfo.ImdbId = GetImdbId(item); releaseInfo.ImdbId = GetImdbId(item);
releaseInfo.IndexerFlags = GetFlags(item);
return releaseInfo; return releaseInfo;
} }
@ -209,6 +210,23 @@ protected virtual int GetImdbYear(XElement item)
return 1900; return 1900;
} }
protected IndexerFlags GetFlags(XElement item)
{
IndexerFlags flags = 0;
if (TryGetNewznabAttribute(item, "prematch") == "1" || TryGetNewznabAttribute(item, "haspretime") == "1")
{
flags |= IndexerFlags.G_Scene;
}
if (TryGetNewznabAttribute(item, "nuked") == "1")
{
flags |= IndexerFlags.Nuked;
}
return flags;
}
protected string TryGetNewznabAttribute(XElement item, string key, string defaultValue = "") 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)); var attrElement = item.Elements(ns + "attr").FirstOrDefault(e => e.Attribute("name").Value.Equals(key, StringComparison.OrdinalIgnoreCase));

View File

@ -0,0 +1,66 @@
using System;
namespace NzbDrone.Core.Parser.Model
{
[Flags]
public enum IndexerFlags
{
/// <summary>
/// Torrent download amount does not count
/// </summary>
G_Freeleech = 1,
/// <summary>
/// Torrent download amount only counts 50%
/// </summary>
G_Halfleech = 2,
/// <summary>
/// Torrent upload amount is doubled
/// </summary>
G_DoubleUpload = 4,
/// <summary>
/// Torrent is a very high quality encode, as applied manually by the PTP staff
/// </summary>
PTP_Golden = 8,
/// <summary>
/// Torrent from PTP that has been checked (by staff or torrent checkers) for release description requirements
/// </summary>
PTP_Approved = 16,
/// <summary>
/// Uploader is an internal release group
/// </summary>
G_Internal = 32,
// AHD, internal
[Obsolete]
AHD_Internal = 64,
/// <summary>
/// The release comes from a scene group
/// </summary>
G_Scene = 128,
/// <summary>
/// Torrent download amount only counts 75%
/// </summary>
G_Freeleech75 = 256,
/// <summary>
/// Torrent download amount only counts 25%
/// </summary>
G_Freeleech25 = 512,
// AHD, internal
[Obsolete]
AHD_UserRelease = 1024,
/// <summary>
/// The release is nuked
/// </summary>
Nuked = 2048
}
}

View File

@ -99,22 +99,4 @@ public virtual string ToString(string format)
} }
} }
} }
[Flags]
public enum IndexerFlags
{
G_Freeleech = 1, // General
G_Halfleech = 2, // General, only 1/2 of download counted
G_DoubleUpload = 4, // General
PTP_Golden = 8, // PTP
PTP_Approved = 16, // PTP
G_Internal = 32, // General, uploader is an internal release group
[Obsolete]
AHD_Internal = 64, // AHD, internal
G_Scene = 128, // General, the torrent comes from a "scene" group
G_Freeleech75 = 256, // Signifies a torrent counts towards 75 percent of your download quota.
G_Freeleech25 = 512, // Signifies a torrent counts towards 25 percent of your download quota.
[Obsolete]
AHD_UserRelease = 1024 // AHD, internal
}
} }