1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Backend work for omgwtfnzbs

This commit is contained in:
Mark McDowall 2012-12-17 17:52:56 -08:00
parent 8f1f96a573
commit 87cf09685c
6 changed files with 182 additions and 0 deletions

View File

@ -32,6 +32,7 @@ public class IndexerTests : CoreTest
[TestCase("filesharingtalk.xml")]
[TestCase("nzbindex.xml")]
[TestCase("nzbclub.xml")]
[TestCase("omgwtfnzbs.xml")]
public void parse_feed_xml(string fileName)
{
Mocker.GetMock<HttpProvider>()
@ -68,6 +69,9 @@ private void WithConfiguredIndexers()
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.FileSharingTalkUid).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.FileSharingTalkSecret).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.OmgwtfnzbsUsername).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.OmgwtfnzbsApiKey).Returns("MockedConfigValue");
}
[Test]
@ -209,6 +213,22 @@ public void size_nzbclub()
parseResults[0].Size.Should().Be(2652142305);
}
[Test]
public void size_omgwtfnzbs()
{
WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream("http://rss.omgwtfnzbs.com/rss-search.php?catid=19,20&user=MockedConfigValue&api=MockedConfigValue&eng=1", It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\omgwtfnzbs.xml"));
//Act
var parseResults = Mocker.Resolve<Omgwtfnzbs>().FetchRss();
parseResults.Should().HaveCount(1);
parseResults[0].Size.Should().Be(236820890);
}
[Test]
public void Server_Unavailable_503_should_not_log_exception()
{
@ -452,5 +472,21 @@ public void newznab_GetQueryTitle_should_return_expected_result(string seriesTit
{
Mocker.Resolve<Newznab>().GetQueryTitle(seriesTitle).Should().Be(expected);
}
[Test]
public void should_get_nzbInfoUrl_for_omgwtfnzbs()
{
WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream("http://rss.omgwtfnzbs.com/rss-search.php?catid=19,20&user=MockedConfigValue&api=MockedConfigValue&eng=1", It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\omgwtfnzbs.xml"));
//Act
var parseResults = Mocker.Resolve<Omgwtfnzbs>().FetchRss();
parseResults.Should().HaveCount(1);
parseResults[0].NzbInfoUrl.Should().Be("http://omgwtfnzbs.com/details.php?id=OAl4g");
}
}
}

View File

@ -279,12 +279,18 @@
<Content Include="Files\JsonError.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\RSS\omgwtfnzbs.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\RSS\nzbclub.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\RSS\nzbindex.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\RSS\SizeParsing\omgwtfnzbs.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Files\RSS\SizeParsing\nzbclub.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

View File

@ -92,6 +92,7 @@ private void InitIndexers()
Kernel.Bind<IndexerBase>().To<FileSharingTalk>();
Kernel.Bind<IndexerBase>().To<NzbIndex>();
Kernel.Bind<IndexerBase>().To<NzbClub>();
Kernel.Bind<IndexerBase>().To<Omgwtfnzbs>();
var indexers = Kernel.GetAll<IndexerBase>();
Kernel.Get<IndexerProvider>().InitializeIndexers(indexers.ToList());

View File

@ -311,6 +311,7 @@
<Compile Include="Providers\Indexer\NzbClub.cs" />
<Compile Include="Providers\Indexer\NzbIndex.cs" />
<Compile Include="Providers\Indexer\FileSharingTalk.cs" />
<Compile Include="Providers\Indexer\Omgwtfnzbs.cs" />
<Compile Include="Providers\Indexer\Wombles.cs" />
<Compile Include="Providers\MetadataProvider.cs" />
<Compile Include="Providers\Metadata\MetadataBase.cs" />

View File

@ -517,6 +517,18 @@ public virtual int RssSyncInterval
set { SetValue("RssSyncInterval", value); }
}
public virtual string OmgwtfnzbsUsername
{
get { return GetValue("OmgwtfnzbsUsername", String.Empty); }
set { SetValue("OmgwtfnzbsUsername", value); }
}
public virtual string OmgwtfnzbsApiKey
{
get { return GetValue("OmgwtfnzbsApiKey", String.Empty); }
set { SetValue("OmgwtfnzbsApiKey", value); }
}
private string GetValue(string key)
{
return GetValue(key, String.Empty);

View File

@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Syndication;
using System.Text;
using System.Text.RegularExpressions;
using Ninject;
using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers.Indexer
{
class Omgwtfnzbs : IndexerBase
{
[Inject]
public Omgwtfnzbs(HttpProvider httpProvider, ConfigProvider configProvider)
: base(httpProvider, configProvider)
{
}
public override string Name
{
get { return "omgwtfnzbs"; }
}
protected override string[] Urls
{
get
{
return new string[]
{
String.Format("http://rss.omgwtfnzbs.com/rss-search.php?catid=19,20&user={0}&api={1}&eng=1",
_configProvider.OmgwtfnzbsUsername, _configProvider.OmgwtfnzbsApiKey)
};
}
}
public override bool IsConfigured
{
get
{
return !string.IsNullOrWhiteSpace(_configProvider.OmgwtfnzbsUsername) &&
!string.IsNullOrWhiteSpace(_configProvider.OmgwtfnzbsApiKey);
}
}
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{
var searchUrls = new List<String>();
foreach (var url in Urls)
{
searchUrls.Add(String.Format("{0}&search={1}+S{2:00}E{3:00}", url, seriesTitle, seasonNumber, episodeNumber));
}
return searchUrls;
}
protected override IList<string> GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date)
{
var searchUrls = new List<String>();
foreach (var url in Urls)
{
searchUrls.Add(String.Format("{0}&search={1}+{2:yyyy MM dd}", url, seriesTitle, date));
}
return searchUrls;
}
protected override IList<string> GetSeasonSearchUrls(string seriesTitle, int seasonNumber)
{
var searchUrls = new List<String>();
foreach (var url in Urls)
{
searchUrls.Add(String.Format("{0}&search={1}+S{2:00}", url, seriesTitle, seasonNumber));
}
return searchUrls;
}
protected override IList<string> GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard)
{
var searchUrls = new List<String>();
foreach (var url in Urls)
{
searchUrls.Add(String.Format("{0}&search={1}+S{2:00}E{3}", url, seriesTitle, seasonNumber, episodeWildcard));
}
return searchUrls;
}
protected override string NzbDownloadUrl(SyndicationItem item)
{
return item.Links[0].Uri.ToString();
}
protected override string NzbInfoUrl(SyndicationItem item)
{
//Todo: Me thinks I need to parse details to get this...
var match = Regex.Match(item.Summary.Text, @"(?:\<b\>View NZB\:\<\/b\>\s\<a\shref\=\"")(?<URL>.+)(?:\""\starget)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
if(match.Success)
{
return match.Groups["URL"].Value;
}
return String.Empty;
}
protected override EpisodeParseResult CustomParser(SyndicationItem item, EpisodeParseResult currentResult)
{
if (currentResult != null)
{
var sizeString = Regex.Match(item.Summary.Text, @"Size:\<\/b\>\s\d+\.\d{1,2}\s\w{2}\<br \/\>", RegexOptions.IgnoreCase | RegexOptions.Compiled).Value;
currentResult.Size = Parser.GetReportSize(sizeString);
}
return currentResult;
}
}
}