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

fixed nzbclub parser.

This commit is contained in:
Keivan Beigi 2013-05-02 16:06:08 -07:00
parent 16425cdab6
commit 385edbf464
14 changed files with 94 additions and 64 deletions

View File

@ -22,7 +22,7 @@ public class ResourceMappingFixture : TestBase
[TestCase(typeof(Core.Tv.Episode), typeof(EpisodeResource))]
[TestCase(typeof(RootFolder), typeof(RootFolderResource))]
[TestCase(typeof(NamingConfig), typeof(NamingConfigResource))]
[TestCase(typeof(IndexerDefinition), typeof(IndexerResource))]
[TestCase(typeof(Indexer), typeof(IndexerResource))]
[TestCase(typeof(ReportInfo), typeof(ReleaseResource))]
[TestCase(typeof(ParsedEpisodeInfo), typeof(ReleaseResource))]
[TestCase(typeof(DownloadDecision), typeof(ReleaseResource))]

View File

@ -9,7 +9,6 @@ public class IndexerResource : RestResource
{
public Boolean Enable { get; set; }
public String Name { get; set; }
public List<Field> Fields { get; set; }
}
}

View File

@ -6,6 +6,6 @@ namespace NzbDrone.Api.RootFolders
public class RootFolderResource : RestResource
{
public String Path { get; set; }
public UInt64 FreeSpace { get; set; }
public Int64 FreeSpace { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Moq;
@ -17,21 +18,21 @@ namespace NzbDrone.Core.Test.IndexerTests
{
public class IndexerServiceFixture : DbTest<IndexerService, IndexerDefinition>
{
private List<IIndexer> _indexers;
private List<Func<IIndexer>> _indexers;
[SetUp]
public void Setup()
{
_indexers = new List<IIndexer>();
_indexers = new List<Func<IIndexer>>();
_indexers.Add(new Newznab());
_indexers.Add(new Nzbsrus());
_indexers.Add(new NzbClub());
_indexers.Add(new NzbIndex());
_indexers.Add(new Omgwtfnzbs());
_indexers.Add(new Wombles());
_indexers.Add(() => new Newznab());
_indexers.Add(() => new Nzbsrus());
_indexers.Add(() => new NzbClub());
_indexers.Add(() => new NzbIndex());
_indexers.Add(() => new Omgwtfnzbs());
_indexers.Add(() => new Wombles());
Mocker.SetConstant<IEnumerable<IIndexer>>(_indexers);
Mocker.SetConstant<IEnumerable<Func<IIndexer>>>(_indexers);
}
@ -66,7 +67,6 @@ public void getting_list_of_indexers()
indexers.Should().NotContain(c => c.Name == null);
indexers.Select(c => c.Name).Should().OnlyHaveUniqueItems();
indexers.Select(c => c.Instance).Should().OnlyHaveUniqueItems();
}
}

View File

@ -0,0 +1,28 @@
using FluentAssertions;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.NzbClub;
using NzbDrone.Core.Test.Framework;
using NUnit.Framework;
namespace NzbDrone.Core.Test.IndexerTests.IntegrationTests
{
public class NzbClubIntegrationTests : CoreTest<FetchFeedService>
{
[Test]
public void should_be_able_to_fetch_rss()
{
UseRealHttp();
var indexer = new NzbClub();
var result = Subject.FetchRss(indexer);
result.Should().NotBeEmpty();
result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Title));
result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.NzbInfoUrl));
result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.NzbUrl));
result.Should().OnlyContain(c => c.Size > 0);
}
}
}

View File

@ -133,7 +133,8 @@
<Compile Include="IndexerSearchTests\SearchDefinitionFixture.cs" />
<Compile Include="IndexerTests\BasicRssParserFixture.cs" />
<Compile Include="IndexerTests\IndexerServiceFixture.cs" />
<Compile Include="IndexerTests\IntegrationTests\NzbxIntegerationTests.cs" />
<Compile Include="IndexerTests\IntegrationTests\NzbxIntegrationTests.cs" />
<Compile Include="IndexerTests\IntegrationTests\NzbClubIntegrationTests.cs" />
<Compile Include="IndexerTests\ParserTests\NzbxParserFixture.cs" />
<Compile Include="JobTests\JobRepositoryFixture.cs" />
<Compile Include="JobTests\RenameSeasonJobFixture.cs" />

View File

@ -5,8 +5,6 @@
using System.ServiceModel.Syndication;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Indexers
@ -27,6 +25,7 @@ public BasicRssParser()
public IEnumerable<ReportInfo> Process(Stream source)
{
//TODO: replace this BS with plain Linq to XML
var reader = new SyndicationFeedXmlReader(source);
var feed = SyndicationFeed.Load(reader).Items;

View File

@ -5,13 +5,11 @@
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Lifecycle;
namespace NzbDrone.Core.Indexers
{
public class Indexer
{
public int DefinitionId { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public bool Enable { get; set; }
public IIndexerSetting Settings { get; set; }
@ -30,16 +28,15 @@ public class IndexerService : IIndexerService, IHandle<ApplicationStartedEvent>
private readonly IIndexerRepository _indexerRepository;
private readonly Logger _logger;
private readonly IList<IIndexer> _indexers;
private readonly List<Func<IIndexer>> _indexers;
public IndexerService(IIndexerRepository indexerRepository, IEnumerable<IIndexer> indexers, Logger logger)
public IndexerService(IIndexerRepository indexerRepository, IEnumerable<Func<IIndexer>> indexers, Logger logger)
{
_indexerRepository = indexerRepository;
_logger = logger;
_indexers = indexers.ToList();
}
public List<Indexer> All()
{
return _indexerRepository.All().Select(ToIndexer).ToList();
@ -50,7 +47,6 @@ public List<IIndexer> GetAvailableIndexers()
return All().Where(c => c.Enable && c.Settings.IsValid).Select(c => c.Instance).ToList();
}
public Indexer Get(string name)
{
return ToIndexer(_indexerRepository.Get(name));
@ -60,7 +56,7 @@ public Indexer Get(string name)
private Indexer ToIndexer(IndexerDefinition definition)
{
var indexer = new Indexer();
indexer.DefinitionId = definition.Id;
indexer.Id = definition.Id;
indexer.Enable = definition.Enable;
indexer.Instance = GetInstance(definition);
indexer.Name = definition.Name;
@ -74,16 +70,13 @@ private Indexer ToIndexer(IndexerDefinition definition)
indexer.Settings = NullSetting.Instance;
}
return indexer;
}
private IIndexer GetInstance(IndexerDefinition indexerDefinition)
{
var existingInstance = _indexers.Single(c => c.GetType().Name.Equals(indexerDefinition.Implementation, StringComparison.CurrentCultureIgnoreCase));
var instance = (IIndexer)Activator.CreateInstance(existingInstance.GetType());
var instance = _indexers.Single(c => c().GetType().Name.Equals(indexerDefinition.Implementation, StringComparison.InvariantCultureIgnoreCase))();
instance.InstanceDefinition = indexerDefinition;
return instance;
}
@ -93,11 +86,7 @@ public void Handle(ApplicationStartedEvent message)
if (!All().Any())
{
var definitions = _indexers.SelectMany(delegate(IIndexer indexer)
{
return indexer.DefaultDefinitions;
});
var definitions = _indexers.SelectMany(indexer => indexer().DefaultDefinitions);
_indexerRepository.InsertMany(definitions.ToList());
}
}

View File

@ -10,6 +10,14 @@ public override string Name
get { return "NzbClub"; }
}
public override IParseFeed Parser
{
get
{
return new NzbClubParser();
}
}
public override IEnumerable<string> RecentFeed
{
get

View File

@ -1,8 +1,6 @@
using System;
using System.ServiceModel.Syndication;
using System.Text.RegularExpressions;
using NzbDrone.Core.Model;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Indexers.NzbClub
@ -13,7 +11,7 @@ protected override ReportInfo PostProcessor(SyndicationItem item, ReportInfo cur
{
if (currentResult != null)
{
var sizeString = Regex.Match(item.Summary.Text, @"Size:\s\d+\.\d{1,2}\s\w{2}\s", RegexOptions.IgnoreCase | RegexOptions.Compiled).Value;
var sizeString = Regex.Match(item.Summary.Text, @"Size:\s\d+\s+\w+", RegexOptions.IgnoreCase | RegexOptions.Compiled).Value;
currentResult.Size = GetReportSize(sizeString);
}

View File

@ -71,6 +71,7 @@
<Compile Include="Client\SeriesClient - Copy.cs" />
<Compile Include="Client\SeriesClient.cs" />
<Compile Include="CommandIntegerationTests.cs" />
<Compile Include="QualityProfileIntegrationTest.cs" />
<Compile Include="ReleaseIntegrationTest.cs" />
<Compile Include="IntegrationTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -0,0 +1,33 @@
using System.IO;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Api.RootFolders;
namespace NzbDrone.Integration.Test
{
[TestFixture]
public class QualityProfileIntegrationTest : IntegrationTest
{
[Test]
public void should_have_2_quality_profiles_initially()
{
RootFolders.All().Should().BeEmpty();
var rootFolder = new RootFolderResource
{
Path = Directory.GetCurrentDirectory()
};
var postResponse = RootFolders.Post(rootFolder);
postResponse.Id.Should().NotBe(0);
postResponse.FreeSpace.Should().NotBe(0);
RootFolders.All().Should().OnlyContain(c => c.Id == postResponse.Id);
RootFolders.Delete(postResponse.Id);
RootFolders.All().Should().BeEmpty();
}
}
}

View File

@ -26,32 +26,6 @@ public void should_have_no_root_folder_initially()
RootFolders.All().Should().OnlyContain(c => c.Id == postResponse.Id);
RootFolders.Delete(postResponse.Id);
RootFolders.All().Should().BeEmpty();
}
}
[TestFixture]
public class QualityProfileIntegrationTest : IntegrationTest
{
[Test]
public void should_have_2_quality_profiles_initially()
{
RootFolders.All().Should().BeEmpty();
var rootFolder = new RootFolderResource
{
Path = Directory.GetCurrentDirectory()
};
var postResponse = RootFolders.Post(rootFolder);
postResponse.Id.Should().NotBe(0);
postResponse.FreeSpace.Should().NotBe(0);
RootFolders.All().Should().OnlyContain(c => c.Id == postResponse.Id);
RootFolders.Delete(postResponse.Id);
RootFolders.All().Should().BeEmpty();