mirror of
https://github.com/Sonarr/Sonarr
synced 2025-01-03 05:35:29 +00:00
parent
0a0e03dca0
commit
278c7891a3
5 changed files with 219 additions and 12 deletions
|
@ -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>
|
|
@ -3,6 +3,7 @@ using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using DryIoc.ImTools;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
@ -154,5 +155,29 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
|
||||||
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.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<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.ForEach(f => release.IndexerFlags.Should().HaveFlag(f));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,7 @@ namespace NzbDrone.Core.Indexers.Newznab
|
||||||
releaseInfo.TvdbId = GetTvdbId(item);
|
releaseInfo.TvdbId = GetTvdbId(item);
|
||||||
releaseInfo.TvRageId = GetTvRageId(item);
|
releaseInfo.TvRageId = GetTvRageId(item);
|
||||||
releaseInfo.ImdbId = GetImdbId(item);
|
releaseInfo.ImdbId = GetImdbId(item);
|
||||||
|
releaseInfo.IndexerFlags = GetFlags(item);
|
||||||
|
|
||||||
return releaseInfo;
|
return releaseInfo;
|
||||||
}
|
}
|
||||||
|
@ -195,6 +196,23 @@ namespace NzbDrone.Core.Indexers.Newznab
|
||||||
return null;
|
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 = "")
|
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));
|
||||||
|
|
48
src/NzbDrone.Core/Parser/Model/IndexerFlags.cs
Normal file
48
src/NzbDrone.Core/Parser/Model/IndexerFlags.cs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Parser.Model
|
||||||
|
{
|
||||||
|
[Flags]
|
||||||
|
public enum IndexerFlags
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Torrent download amount does not count
|
||||||
|
/// </summary>
|
||||||
|
Freeleech = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Torrent download amount only counts 50%
|
||||||
|
/// </summary>
|
||||||
|
Halfleech = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Torrent upload amount is doubled
|
||||||
|
/// </summary>
|
||||||
|
DoubleUpload = 4,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Uploader is an internal release group
|
||||||
|
/// </summary>
|
||||||
|
Internal = 8,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The release comes from a scene group
|
||||||
|
/// </summary>
|
||||||
|
Scene = 16,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Torrent download amount only counts 75%
|
||||||
|
/// </summary>
|
||||||
|
Freeleech75 = 32,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Torrent download amount only counts 25%
|
||||||
|
/// </summary>
|
||||||
|
Freeleech25 = 64,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The release is nuked
|
||||||
|
/// </summary>
|
||||||
|
Nuked = 128
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue