New: Add Headphones VIP Indexer (#147)

* New: Add Headphones VIP Indexer

* fixup! String Format Invalid

* fixup! Remove hyphen from search string

* Add Tests for Headphones Indexer
pull/152/head
Qstick 7 years ago committed by GitHub
parent 532e14040b
commit ede3a55c68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,377 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:newznab="http://www.newznab.com/DTD/2010/feeds/attributes/">
<channel>
<title>Headphones Indexer</title>
<description>powered by pynab</description>
<link>https://indexer.codeshy.com</link>
<newznab:response offset="0" total="16"/>
<item>
<title>Lady Gaga Born This Way 2CD FLAC 2011 WRE</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/123456</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=123456&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 14:39:52 -0000</pubDate>
<category>Audio &gt; Lossless</category>
<description>Lady Gaga Born This Way 2CD FLAC 2011 WRE</description>
<posted>Sun, 02 Jun 2013 08:58:54 -0000</posted>
<group>alt.binaries.sounds.flac</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=123456&amp;apikey=123456789" length="917347414" type="application/x-nzb"></enclosure>
<grabs>146</grabs>
<newznab:attr name="category" value="3040"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="123456"/>
<newznab:attr name="poster" value="flac@4u.tv (flac)"/>
<newznab:attr name="usenetdate" value="Sun, 02 Jun 2013 08:58:54 -0000"/>
<newznab:attr name="grabs" value="146"/>
<newznab:attr name="group" value="alt.binaries.sounds.flac"/>
<newznab:attr name="size" value="917347414"/>
<size>917347414</size>
</item>
<item>
<title>Lady Gaga Born This Way PROMO CDR2 FLAC 2011 WRE</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/178728</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=178728&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 15:37:26 -0000</pubDate>
<category>Audio &gt; Lossless</category>
<description>Lady Gaga Born This Way PROMO CDR2 FLAC 2011 WRE</description>
<posted>Wed, 19 Sep 2012 18:17:13 -0000</posted>
<group>alt.binaries.sounds.flac</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=178728&amp;apikey=123456789" length="523005229" type="application/x-nzb"></enclosure>
<grabs>4</grabs>
<newznab:attr name="category" value="3040"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="178728"/>
<newznab:attr name="poster" value="flac@4u.tv (flac)"/>
<newznab:attr name="usenetdate" value="Wed, 19 Sep 2012 18:17:13 -0000"/>
<newznab:attr name="grabs" value="4"/>
<newznab:attr name="group" value="alt.binaries.sounds.flac"/>
<newznab:attr name="size" value="523005229"/>
<size>523005229</size>
</item>
<item>
<title>Lady Gaga Born This Way PROMO CDR FLAC 2011 WRE</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/178732</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=178732&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 15:37:27 -0000</pubDate>
<category>Audio &gt; Lossless</category>
<description>Lady Gaga Born This Way PROMO CDR FLAC 2011 WRE</description>
<posted>Wed, 19 Sep 2012 18:12:24 -0000</posted>
<group>alt.binaries.sounds.flac</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=178732&amp;apikey=123456789" length="297599650" type="application/x-nzb"></enclosure>
<grabs>2</grabs>
<newznab:attr name="category" value="3040"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="178732"/>
<newznab:attr name="poster" value="flac@4u.tv (flac)"/>
<newznab:attr name="usenetdate" value="Wed, 19 Sep 2012 18:12:24 -0000"/>
<newznab:attr name="grabs" value="2"/>
<newznab:attr name="group" value="alt.binaries.sounds.flac"/>
<newznab:attr name="size" value="297599650"/>
<size>297599650</size>
</item>
<item>
<title>Lady Gaga Born This Way (The Remix) (2011) FLAC</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/97557</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=97557&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 09:28:03 -0000</pubDate>
<category>Audio &gt; Lossless</category>
<description>Lady Gaga Born This Way (The Remix) (2011) FLAC</description>
<posted>Thu, 17 Nov 2011 15:38:07 -0000</posted>
<group>alt.binaries.sounds.lossless</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=97557&amp;apikey=123456789" length="542418884" type="application/x-nzb"></enclosure>
<grabs>0</grabs>
<newznab:attr name="category" value="3040"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="97557"/>
<newznab:attr name="poster" value="nocrap@honestposting.com (NoCrap)"/>
<newznab:attr name="usenetdate" value="Thu, 17 Nov 2011 15:38:07 -0000"/>
<newznab:attr name="grabs" value="0"/>
<newznab:attr name="group" value="alt.binaries.sounds.lossless"/>
<newznab:attr name="size" value="542418884"/>
<size>542418884</size>
</item>
<item>
<title>Lady Gaga Born This Way The Remix CD FLAC 2011 EMG</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/97580</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=97580&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 09:28:05 -0000</pubDate>
<category>Audio &gt; Lossless</category>
<description>Lady Gaga Born This Way The Remix CD FLAC 2011 EMG</description>
<posted>Thu, 17 Nov 2011 09:21:00 -0000</posted>
<group>alt.binaries.sounds.lossless</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=97580&amp;apikey=123456789" length="44608274" type="application/x-nzb"></enclosure>
<grabs>0</grabs>
<newznab:attr name="category" value="3040"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="97580"/>
<newznab:attr name="poster" value="quack@dream-of-usenet.org (Quack)"/>
<newznab:attr name="usenetdate" value="Thu, 17 Nov 2011 09:21:00 -0000"/>
<newznab:attr name="grabs" value="0"/>
<newznab:attr name="group" value="alt.binaries.sounds.lossless"/>
<newznab:attr name="size" value="44608274"/>
<size>44608274</size>
</item>
<item>
<title>Lady Gaga Born This Way The Remix CD FLAC 2011 EMG</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/204233</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=204233&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 17:05:21 -0000</pubDate>
<category>Audio &gt; Lossless</category>
<description>Lady Gaga Born This Way The Remix CD FLAC 2011 EMG</description>
<posted>Thu, 17 Nov 2011 07:39:41 -0000</posted>
<group>alt.binaries.sounds.flac</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=204233&amp;apikey=123456789" length="42548396" type="application/x-nzb"></enclosure>
<grabs>0</grabs>
<newznab:attr name="category" value="3040"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="204233"/>
<newznab:attr name="poster" value="autoSEK9 &lt;auto@SEK9.edu&gt;"/>
<newznab:attr name="usenetdate" value="Thu, 17 Nov 2011 07:39:41 -0000"/>
<newznab:attr name="grabs" value="0"/>
<newznab:attr name="group" value="alt.binaries.sounds.flac"/>
<newznab:attr name="size" value="42548396"/>
<size>42548396</size>
</item>
<item>
<title>Lady Gaga Born This Way The Remix CD FLAC 2011 EMG</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/204234</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=204234&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 17:05:22 -0000</pubDate>
<category>Audio &gt; Lossless</category>
<description>Lady Gaga Born This Way The Remix CD FLAC 2011 EMG</description>
<posted>Thu, 17 Nov 2011 07:38:23 -0000</posted>
<group>alt.binaries.sounds.flac</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=204234&amp;apikey=123456789" length="514617494" type="application/x-nzb"></enclosure>
<grabs>0</grabs>
<newznab:attr name="category" value="3040"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="204234"/>
<newznab:attr name="poster" value="autoSEK9 &lt;auto@SEK9.edu&gt;"/>
<newznab:attr name="usenetdate" value="Thu, 17 Nov 2011 07:38:23 -0000"/>
<newznab:attr name="grabs" value="0"/>
<newznab:attr name="group" value="alt.binaries.sounds.flac"/>
<newznab:attr name="size" value="514617494"/>
<size>514617494</size>
</item>
<item>
<title>Lady Gaga Born This Way The Remix CD FLAC 2011 EMG</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/204235</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=204235&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 17:05:22 -0000</pubDate>
<category>Audio &gt; Lossless</category>
<description>Lady Gaga Born This Way The Remix CD FLAC 2011 EMG</description>
<posted>Thu, 17 Nov 2011 07:37:20 -0000</posted>
<group>alt.binaries.sounds.flac</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=204235&amp;apikey=123456789" length="541983521" type="application/x-nzb"></enclosure>
<grabs>0</grabs>
<newznab:attr name="category" value="3040"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="204235"/>
<newznab:attr name="poster" value="flac@4u.tv (flac)"/>
<newznab:attr name="usenetdate" value="Thu, 17 Nov 2011 07:37:20 -0000"/>
<newznab:attr name="grabs" value="0"/>
<newznab:attr name="group" value="alt.binaries.sounds.flac"/>
<newznab:attr name="size" value="541983521"/>
<size>541983521</size>
</item>
<item>
<title>Lady Gaga Born This Way (The Remix) 2011 pLAN9</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/101273</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=101273&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 10:45:43 -0000</pubDate>
<category>Audio &gt; MP3</category>
<description>Lady Gaga Born This Way (The Remix) 2011 pLAN9</description>
<posted>Wed, 16 Nov 2011 23:19:32 -0000</posted>
<group>alt.binaries.sounds.mp3</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=101273&amp;apikey=123456789" length="12390648" type="application/x-nzb"></enclosure>
<grabs>5</grabs>
<newznab:attr name="category" value="3010"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="101273"/>
<newznab:attr name="poster" value="quack@dream-of-usenet.org (Quack)"/>
<newznab:attr name="usenetdate" value="Wed, 16 Nov 2011 23:19:32 -0000"/>
<newznab:attr name="grabs" value="5"/>
<newznab:attr name="group" value="alt.binaries.sounds.mp3"/>
<newznab:attr name="size" value="12390648"/>
<size>12390648</size>
</item>
<item>
<title>Lady GaGa Born This Way (Special Edition) 2CD FLAC 2011 PERFECT</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/214301</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=214301&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 17:38:58 -0000</pubDate>
<category>Audio &gt; Lossless</category>
<description>Lady GaGa Born This Way (Special Edition) 2CD FLAC 2011 PERFECT</description>
<posted>Mon, 17 Oct 2011 16:43:14 -0000</posted>
<group>alt.binaries.sounds.flac</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=214301&amp;apikey=123456789" length="823716079" type="application/x-nzb"></enclosure>
<grabs>5</grabs>
<newznab:attr name="category" value="3040"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="214301"/>
<newznab:attr name="poster" value="flac@4u.tv (flac)"/>
<newznab:attr name="usenetdate" value="Mon, 17 Oct 2011 16:43:14 -0000"/>
<newznab:attr name="grabs" value="5"/>
<newznab:attr name="group" value="alt.binaries.sounds.flac"/>
<newznab:attr name="size" value="823716079"/>
<size>823716079</size>
</item>
<item>
<title>Lady GaGa Born This Way Bonus Track CD FLAC 2011 PERFECT</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/214424</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=214424&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 17:39:21 -0000</pubDate>
<category>Audio &gt; Lossless</category>
<description>Lady GaGa Born This Way Bonus Track CD FLAC 2011 PERFECT</description>
<posted>Mon, 17 Oct 2011 03:37:35 -0000</posted>
<group>alt.binaries.sounds.flac</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=214424&amp;apikey=123456789" length="38894529" type="application/x-nzb"></enclosure>
<grabs>0</grabs>
<newznab:attr name="category" value="3040"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="214424"/>
<newznab:attr name="poster" value="flac@4u.tv (flac)"/>
<newznab:attr name="usenetdate" value="Mon, 17 Oct 2011 03:37:35 -0000"/>
<newznab:attr name="grabs" value="0"/>
<newznab:attr name="group" value="alt.binaries.sounds.flac"/>
<newznab:attr name="size" value="38894529"/>
<size>38894529</size>
</item>
<item>
<title>Lady Gaga Born This Way CDM FLAC 2011 WRE</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/214428</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=214428&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 17:39:22 -0000</pubDate>
<category>Audio &gt; Lossless</category>
<description>Lady Gaga Born This Way CDM FLAC 2011 WRE</description>
<posted>Mon, 17 Oct 2011 03:36:31 -0000</posted>
<group>alt.binaries.sounds.flac</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=214428&amp;apikey=123456789" length="174562763" type="application/x-nzb"></enclosure>
<grabs>1</grabs>
<newznab:attr name="category" value="3040"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="214428"/>
<newznab:attr name="poster" value="flac@4u.tv (flac)"/>
<newznab:attr name="usenetdate" value="Mon, 17 Oct 2011 03:36:31 -0000"/>
<newznab:attr name="grabs" value="1"/>
<newznab:attr name="group" value="alt.binaries.sounds.flac"/>
<newznab:attr name="size" value="174562763"/>
<size>174562763</size>
</item>
<item>
<title>Lady GaGa Born This Way Special Edition FLAC</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/205419</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=205419&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 17:07:40 -0000</pubDate>
<category>Audio &gt; Lossless</category>
<description>Lady GaGa Born This Way Special Edition FLAC</description>
<posted>Tue, 14 Jun 2011 22:06:05 -0000</posted>
<group>alt.binaries.music</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=205419&amp;apikey=123456789" length="8045237" type="application/x-nzb"></enclosure>
<grabs>0</grabs>
<newznab:attr name="category" value="3040"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="205419"/>
<newznab:attr name="poster" value="CPP-user@domain.com (CPP-User)"/>
<newznab:attr name="usenetdate" value="Tue, 14 Jun 2011 22:06:05 -0000"/>
<newznab:attr name="grabs" value="0"/>
<newznab:attr name="group" value="alt.binaries.music"/>
<newznab:attr name="size" value="8045237"/>
<size>8045237</size>
</item>
<item>
<title>Lutheria Lady Gaga Born This Way CD1</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/205457</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=205457&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 17:07:49 -0000</pubDate>
<category>Audio &gt; MP3</category>
<description>Lutheria Lady Gaga Born This Way CD1</description>
<posted>Tue, 31 May 2011 02:04:02 -0000</posted>
<group>alt.binaries.music</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=205457&amp;apikey=123456789" length="4198420" type="application/x-nzb"></enclosure>
<grabs>4</grabs>
<newznab:attr name="category" value="3010"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="205457"/>
<newznab:attr name="poster" value="blabla@hotmail.com (Lynn1994)"/>
<newznab:attr name="usenetdate" value="Tue, 31 May 2011 02:04:02 -0000"/>
<newznab:attr name="grabs" value="4"/>
<newznab:attr name="group" value="alt.binaries.music"/>
<newznab:attr name="size" value="4198420"/>
<size>4198420</size>
</item>
<item>
<title>Lady Gaga Born This Way (New Single) Feb 2011 Mp3ViLLe</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/24756</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=24756&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 01:29:53 -0000</pubDate>
<category>Audio &gt; MP3</category>
<description>Lady Gaga Born This Way (New Single) Feb 2011 Mp3ViLLe</description>
<posted>Fri, 11 Mar 2011 11:08:08 -0000</posted>
<group>alt.binaries.sounds.mp3.complete_cd</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=24756&amp;apikey=123456789" length="10301727" type="application/x-nzb"></enclosure>
<grabs>43</grabs>
<newznab:attr name="category" value="3010"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="24756"/>
<newznab:attr name="poster" value="ripman &lt;ripman@frefr.us&gt;"/>
<newznab:attr name="usenetdate" value="Fri, 11 Mar 2011 11:08:08 -0000"/>
<newznab:attr name="grabs" value="43"/>
<newznab:attr name="group" value="alt.binaries.sounds.mp3.complete_cd"/>
<newznab:attr name="size" value="10301727"/>
<size>10301727</size>
</item>
<item>
<title>Lady Gaga Born This Way (New Single) Feb 2011 Mp3ViLLe</title>
<guid isPermaLink="true">https://indexer.codeshy.com/details/109954</guid>
<link>https://indexer.codeshy.com/api?t=g&amp;guid=109954&amp;apikey=123456789</link>
<pubDate>Tue, 13 Sep 2016 11:30:12 -0000</pubDate>
<category>Audio &gt; MP3</category>
<description>Lady Gaga Born This Way (New Single) Feb 2011 Mp3ViLLe</description>
<posted>Fri, 11 Mar 2011 11:04:06 -0000</posted>
<group>alt.binaries.sounds.mp3</group>
<enclosure url="https://indexer.codeshy.com/api?t=g&amp;guid=109954&amp;apikey=123456789" length="10301727" type="application/x-nzb"></enclosure>
<grabs>1</grabs>
<newznab:attr name="category" value="3010"/>
<newznab:attr name="category" value="3000"/>
<newznab:attr name="guid" value="109954"/>
<newznab:attr name="poster" value="ripman &lt;ripman@frefr.us&gt;"/>
<newznab:attr name="usenetdate" value="Fri, 11 Mar 2011 11:04:06 -0000"/>
<newznab:attr name="grabs" value="1"/>
<newznab:attr name="group" value="alt.binaries.sounds.mp3"/>
<newznab:attr name="size" value="10301727"/>
<size>10301727</size>
</item>
</channel>
</rss>

@ -0,0 +1,98 @@
using System;
using System.Xml;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Http;
using NzbDrone.Core.Indexers.Headphones;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.IndexerTests.HeadphonesTests
{
[TestFixture]
public class HeadphonesCapabilitiesProviderFixture : CoreTest<HeadphonesCapabilitiesProvider>
{
private HeadphonesSettings _settings;
private string _caps;
[SetUp]
public void SetUp()
{
_settings = new HeadphonesSettings();
_caps = ReadAllText("Files/Indexers/Newznab/newznab_caps.xml");
}
private void GivenCapsResponse(string caps)
{
Mocker.GetMock<IHttpClient>()
.Setup(o => o.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), caps));
}
[Test]
public void should_not_request_same_caps_twice()
{
GivenCapsResponse(_caps);
Subject.GetCapabilities(_settings);
Subject.GetCapabilities(_settings);
Mocker.GetMock<IHttpClient>()
.Verify(o => o.Get(It.IsAny<HttpRequest>()), Times.Once());
}
[Test]
public void should_report_pagesize()
{
GivenCapsResponse(_caps);
var caps = Subject.GetCapabilities(_settings);
caps.DefaultPageSize.Should().Be(25);
caps.MaxPageSize.Should().Be(60);
}
[Test]
public void should_use_default_pagesize_if_missing()
{
GivenCapsResponse(_caps.Replace("<limits", "<abclimits"));
var caps = Subject.GetCapabilities(_settings);
caps.DefaultPageSize.Should().Be(100);
caps.MaxPageSize.Should().Be(100);
}
[Test]
public void should_throw_if_failed_to_get()
{
Mocker.GetMock<IHttpClient>()
.Setup(o => o.Get(It.IsAny<HttpRequest>()))
.Throws<Exception>();
Assert.Throws<Exception>(() => Subject.GetCapabilities(_settings));
}
[Test]
public void should_throw_if_xml_invalid()
{
GivenCapsResponse(_caps.Replace("<limits", "<>"));
Assert.Throws<XmlException>(() => Subject.GetCapabilities(_settings));
}
[Test]
public void should_not_throw_on_xml_data_unexpected()
{
GivenCapsResponse(_caps.Replace("3040", "asdf"));
var result = Subject.GetCapabilities(_settings);
result.Should().NotBeNull();
ExceptionVerification.ExpectedErrors(1);
}
}
}

@ -0,0 +1,70 @@
using System;
using System.Linq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Http;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Headphones;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.IndexerTests.HeadphonesTests
{
[TestFixture]
public class HeadphonesFixture : CoreTest<Headphones>
{
private HeadphonesCapabilities _caps;
[SetUp]
public void Setup()
{
Subject.Definition = new IndexerDefinition()
{
Name = "Headphones VIP",
Settings = new HeadphonesSettings()
{
Categories = new int[] { 3000 }
}
};
_caps = new HeadphonesCapabilities();
Mocker.GetMock<IHeadphonesCapabilitiesProvider>()
.Setup(v => v.GetCapabilities(It.IsAny<HeadphonesSettings>()))
.Returns(_caps);
}
[Test]
public void should_parse_recent_feed_from_headphones()
{
var recentFeed = ReadAllText(@"Files/Indexers/Headphones/Headphones.xml");
Mocker.GetMock<IHttpClient>()
.Setup(o => o.Execute(It.Is<HttpRequest>(v => v.Method == HttpMethod.GET)))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), recentFeed));
var releases = Subject.FetchRecent();
releases.Should().HaveCount(16);
releases.First().Should().BeOfType<ReleaseInfo>();
var releaseInfo = releases.First() as ReleaseInfo;
releaseInfo.Title.Should().Be("Lady Gaga Born This Way 2CD FLAC 2011 WRE");
releaseInfo.DownloadProtocol.Should().Be(DownloadProtocol.Usenet);
releaseInfo.DownloadUrl.Should().Be("https://indexer.codeshy.com/api?t=g&guid=123456&apikey=123456789");
releaseInfo.Indexer.Should().Be(Subject.Definition.Name);
releaseInfo.PublishDate.Should().Be(DateTime.Parse("2013/06/02 08:58:54"));
releaseInfo.Size.Should().Be(917347414);
}
[Test]
public void should_use_pagesize_reported_by_caps()
{
_caps.MaxPageSize = 30;
_caps.DefaultPageSize = 25;
Subject.PageSize.Should().Be(25);
}
}
}

@ -221,6 +221,8 @@
<Compile Include="IndexerSearchTests\ArtistSearchServiceFixture.cs" />
<Compile Include="IndexerSearchTests\SearchDefinitionFixture.cs" />
<Compile Include="IndexerTests\BasicRssParserFixture.cs" />
<Compile Include="IndexerTests\HeadphonesTests\HeadphonesFixture.cs" />
<Compile Include="IndexerTests\HeadphonesTests\HeadphonesCapabilitiesProviderFixture.cs" />
<Compile Include="IndexerTests\IndexerServiceFixture.cs" />
<Compile Include="IndexerTests\IndexerStatusServiceFixture.cs" />
<Compile Include="IndexerTests\IntegrationTests\IndexerIntegrationTests.cs" />
@ -390,6 +392,9 @@
<Link>sqlite3.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\Indexers\Headphones\Headphones.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\Indexers\TorrentRss\EvolutionWorld.xml">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation.Results;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Indexers.Newznab;
namespace NzbDrone.Core.Indexers.Headphones
{
public class Headphones : HttpIndexerBase<HeadphonesSettings>
{
private readonly IHeadphonesCapabilitiesProvider _capabilitiesProvider;
public override string Name => "Headphones VIP";
public override DownloadProtocol Protocol => DownloadProtocol.Usenet;
public override int PageSize => _capabilitiesProvider.GetCapabilities(Settings).DefaultPageSize;
public override IIndexerRequestGenerator GetRequestGenerator()
{
return new HeadphonesRequestGenerator(_capabilitiesProvider)
{
PageSize = PageSize,
Settings = Settings
};
}
public override IParseIndexerResponse GetParser()
{
return new NewznabRssParser();
}
public Headphones(IHeadphonesCapabilitiesProvider capabilitiesProvider, IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, IParsingService parsingService, Logger logger)
: base(httpClient, indexerStatusService, configService, parsingService, logger)
{
_capabilitiesProvider = capabilitiesProvider;
}
protected override void Test(List<ValidationFailure> failures)
{
base.Test(failures);
if (failures.Any()) return;
failures.AddIfNotNull(TestCapabilities());
}
protected virtual ValidationFailure TestCapabilities()
{
try
{
var capabilities = _capabilitiesProvider.GetCapabilities(Settings);
if (capabilities.SupportedSearchParameters != null && capabilities.SupportedSearchParameters.Contains("q"))
{
return null;
}
return new ValidationFailure(string.Empty, "Indexer does not support required search parameters");
}
catch (Exception ex)
{
_logger.Warn(ex, "Unable to connect to indexer: " + ex.Message);
return new ValidationFailure(string.Empty, "Unable to connect to indexer, check the log for more details");
}
}
}
}

@ -0,0 +1,21 @@
using System.Collections.Generic;
using NzbDrone.Core.Indexers.Newznab;
namespace NzbDrone.Core.Indexers.Headphones
{
public class HeadphonesCapabilities
{
public int DefaultPageSize { get; set; }
public int MaxPageSize { get; set; }
public string[] SupportedSearchParameters { get; set; }
public List<NewznabCategory> Categories { get; set; }
public HeadphonesCapabilities()
{
DefaultPageSize = 100;
MaxPageSize = 100;
SupportedSearchParameters = new[] { "q" };
Categories = new List<NewznabCategory>();
}
}
}

@ -0,0 +1,156 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Xml;
using System.Xml.Linq;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Indexers.Newznab;
namespace NzbDrone.Core.Indexers.Headphones
{
public interface IHeadphonesCapabilitiesProvider
{
HeadphonesCapabilities GetCapabilities(HeadphonesSettings settings);
}
public class HeadphonesCapabilitiesProvider : IHeadphonesCapabilitiesProvider
{
private readonly ICached<HeadphonesCapabilities> _capabilitiesCache;
private readonly IHttpClient _httpClient;
private readonly Logger _logger;
public HeadphonesCapabilitiesProvider(ICacheManager cacheManager, IHttpClient httpClient, Logger logger)
{
_capabilitiesCache = cacheManager.GetCache<HeadphonesCapabilities>(GetType());
_httpClient = httpClient;
_logger = logger;
}
public HeadphonesCapabilities GetCapabilities(HeadphonesSettings indexerSettings)
{
var key = indexerSettings.ToJson();
var capabilities = _capabilitiesCache.Get(key, () => FetchCapabilities(indexerSettings), TimeSpan.FromDays(7));
return capabilities;
}
private HeadphonesCapabilities FetchCapabilities(HeadphonesSettings indexerSettings)
{
var capabilities = new HeadphonesCapabilities();
var url = string.Format("{0}{1}?t=caps", indexerSettings.BaseUrl.TrimEnd('/'), indexerSettings.ApiPath.TrimEnd('/'));
if (indexerSettings.ApiKey.IsNotNullOrWhiteSpace())
{
url += "&apikey=" + indexerSettings.ApiKey;
}
var request = new HttpRequest(url, HttpAccept.Rss);
request.AddBasicAuthentication(indexerSettings.Username, indexerSettings.Password);
HttpResponse response;
try
{
response = _httpClient.Get(request);
}
catch (Exception ex)
{
_logger.Debug(ex, "Failed to get headphones api capabilities from {0}", indexerSettings.BaseUrl);
throw;
}
try
{
capabilities = ParseCapabilities(response);
}
catch (XmlException ex)
{
_logger.Debug(ex, "Failed to parse headphones api capabilities for {0}", indexerSettings.BaseUrl);
ex.WithData(response);
throw;
}
catch (Exception ex)
{
_logger.Error(ex, "Failed to determine headphones api capabilities for {0}, using the defaults instead till Lidarr restarts", indexerSettings.BaseUrl);
}
return capabilities;
}
private HeadphonesCapabilities ParseCapabilities(HttpResponse response)
{
var capabilities = new HeadphonesCapabilities();
var xDoc = XDocument.Parse(response.Content);
if (xDoc == null)
{
throw new XmlException("Invalid XML");
}
var xmlRoot = xDoc.Element("caps");
if (xmlRoot == null)
{
throw new XmlException("Unexpected XML");
}
var xmlLimits = xmlRoot.Element("limits");
if (xmlLimits != null)
{
capabilities.DefaultPageSize = int.Parse(xmlLimits.Attribute("default").Value);
capabilities.MaxPageSize = int.Parse(xmlLimits.Attribute("max").Value);
}
var xmlSearching = xmlRoot.Element("searching");
if (xmlSearching != null)
{
var xmlBasicSearch = xmlSearching.Element("search");
if (xmlBasicSearch == null || xmlBasicSearch.Attribute("available").Value != "yes")
{
capabilities.SupportedSearchParameters = null;
}
else if (xmlBasicSearch.Attribute("supportedParams") != null)
{
capabilities.SupportedSearchParameters = xmlBasicSearch.Attribute("supportedParams").Value.Split(',');
}
}
var xmlCategories = xmlRoot.Element("categories");
if (xmlCategories != null)
{
foreach (var xmlCategory in xmlCategories.Elements("category"))
{
var cat = new NewznabCategory
{
Id = int.Parse(xmlCategory.Attribute("id").Value),
Name = xmlCategory.Attribute("name").Value,
Description = xmlCategory.Attribute("description") != null ? xmlCategory.Attribute("description").Value : string.Empty,
Subcategories = new List<NewznabCategory>()
};
foreach (var xmlSubcat in xmlCategory.Elements("subcat"))
{
cat.Subcategories.Add(new NewznabCategory
{
Id = int.Parse(xmlSubcat.Attribute("id").Value),
Name = xmlSubcat.Attribute("name").Value,
Description = xmlSubcat.Attribute("description") != null ? xmlSubcat.Attribute("description").Value : string.Empty
});
}
capabilities.Categories.Add(cat);
}
}
return capabilities;
}
}
}

@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Core.IndexerSearch.Definitions;
namespace NzbDrone.Core.Indexers.Headphones
{
public class HeadphonesRequestGenerator : IIndexerRequestGenerator
{
private readonly IHeadphonesCapabilitiesProvider _capabilitiesProvider;
public int MaxPages { get; set; }
public int PageSize { get; set; }
public HeadphonesSettings Settings { get; set; }
public HeadphonesRequestGenerator(IHeadphonesCapabilitiesProvider capabilitiesProvider)
{
_capabilitiesProvider = capabilitiesProvider;
MaxPages = 30;
PageSize = 100;
}
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories, "search", ""));
return pageableRequests;
}
public virtual IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.AddTier();
pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories, "search",
string.Format("&q={0}",
NewsnabifyTitle(string.Format("{0} {1}",
searchCriteria.Artist.Name,
searchCriteria.AlbumTitle)))));
return pageableRequests;
}
public virtual IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria)
{
var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.AddTier();
pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories, "search",
string.Format("&q={0}",
NewsnabifyTitle(searchCriteria.Artist.Name))));
return pageableRequests;
}
private IEnumerable<IndexerRequest> GetPagedRequests(int maxPages, IEnumerable<int> categories, string searchType, string parameters)
{
if (categories.Empty())
{
yield break;
}
var categoriesQuery = string.Join(",", categories.Distinct());
var baseUrl = string.Format("{0}{1}?t={2}&cat={3}&extended=1", Settings.BaseUrl.TrimEnd('/'), Settings.ApiPath.TrimEnd('/'), searchType, categoriesQuery);
if (Settings.ApiKey.IsNotNullOrWhiteSpace())
{
baseUrl += "&apikey=" + Settings.ApiKey;
}
if (PageSize == 0)
{
var request = new IndexerRequest($"{baseUrl}{parameters}", HttpAccept.Rss);
request.HttpRequest.AddBasicAuthentication(Settings.Username, Settings.Password);
yield return request;
}
else
{
for (var page = 0; page < maxPages; page++)
{
var request = new IndexerRequest(string.Format("{0}&offset={1}&limit={2}{3}", baseUrl, page * PageSize, PageSize, parameters), HttpAccept.Rss);
request.HttpRequest.AddBasicAuthentication(Settings.Username, Settings.Password);
yield return request;
}
}
}
private static string NewsnabifyTitle(string title)
{
return title.Replace("+", "%20");
}
}
}

@ -0,0 +1,61 @@
using System.Collections.Generic;
using FluentValidation;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Indexers.Headphones
{
public class HeadphonesSettingsValidator : AbstractValidator<HeadphonesSettings>
{
public HeadphonesSettingsValidator()
{
Custom(newznab =>
{
if (newznab.Categories.Empty())
{
return new ValidationFailure("", "'Categories' must be provided");
}
return null;
});
RuleFor(c => c.Username).NotEmpty();
RuleFor(c => c.Password).NotEmpty();
}
}
public class HeadphonesSettings : IIndexerSettings
{
private static readonly HeadphonesSettingsValidator Validator = new HeadphonesSettingsValidator();
public HeadphonesSettings()
{
ApiPath = "/api";
BaseUrl = "https://indexer.codeshy.com";
ApiKey = "964d601959918a578a670984bdee9357";
Categories = new[] { 3000, 3010, 3020, 3030, 3040 };
}
public string BaseUrl { get; set; }
public string ApiPath { get; set; }
public string ApiKey { get; set; }
[FieldDefinition(0, Label = "Categories", HelpText = "Comma Separated list, leave blank to disable standard/daily shows", Advanced = true)]
public IEnumerable<int> Categories { get; set; }
[FieldDefinition(1, Label = "Username")]
public string Username { get; set; }
[FieldDefinition(2, Label = "Password", Type = FieldType.Password)]
public string Password { get; set; }
public virtual NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
}
}

@ -81,7 +81,7 @@ namespace NzbDrone.Core.Indexers.Newznab
pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories, "search",
string.Format("&q={0}",
NewsnabifyTitle(string.Format("{0} - {1}",
NewsnabifyTitle(string.Format("{0} {1}",
searchCriteria.Artist.Name,
searchCriteria.AlbumTitle)))));

@ -521,6 +521,11 @@
<Compile Include="Indexers\Gazelle\GazelleParser.cs" />
<Compile Include="Indexers\Gazelle\GazelleRequestGenerator.cs" />
<Compile Include="Indexers\Gazelle\GazelleSettings.cs" />
<Compile Include="Indexers\Headphones\Headphones.cs" />
<Compile Include="Indexers\Headphones\HeadphonesSettings.cs" />
<Compile Include="Indexers\Headphones\HeadphonesCapabilitiesProvider.cs" />
<Compile Include="Indexers\Headphones\HeadphonesCapabilities.cs" />
<Compile Include="Indexers\Headphones\HeadphonesRequestGenerator.cs" />
<Compile Include="Indexers\IIndexerSettings.cs" />
<Compile Include="Indexers\IndexerDefaults.cs" />
<Compile Include="Indexers\ITorrentIndexerSettings.cs" />

Loading…
Cancel
Save