GitExtensions, go fuck yourself

pull/6/head
Mark McDowall 12 years ago
parent 27a939a56a
commit 7fa523dd97

@ -8,7 +8,6 @@ using NCrunch.Framework;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Providers;
using NzbDrone.Core.Jobs; using NzbDrone.Core.Jobs;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.ExternalNotification; using NzbDrone.Core.Providers.ExternalNotification;

@ -11,7 +11,6 @@ using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Providers;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
@ -164,7 +163,7 @@ namespace NzbDrone.Core.Test.IndexerTests
.With(n => n.ApiKey = String.Empty) .With(n => n.ApiKey = String.Empty)
.Build(); .Build();
Mocker.GetMock<NewznabProvider>().Setup(s => s.Enabled()).Returns(newznabDefs.ToList()); Mocker.GetMock<NewznabService>().Setup(s => s.Enabled()).Returns(newznabDefs.ToList());
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
@ -363,7 +362,7 @@ namespace NzbDrone.Core.Test.IndexerTests
.With(n => n.ApiKey = String.Empty) .With(n => n.ApiKey = String.Empty)
.Build(); .Build();
Mocker.GetMock<NewznabProvider>().Setup(s => s.Enabled()).Returns(newznabDefs.ToList()); Mocker.GetMock<NewznabService>().Setup(s => s.Enabled()).Returns(newznabDefs.ToList());
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))

@ -10,7 +10,7 @@ using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.Indexers.Providers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;

@ -9,7 +9,6 @@ using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Providers;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;

@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Security.Policy;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.Indexers
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class NewznabProviderTest : CoreTest<NewznabService>
{
private void WithInvalidName()
{
Mocker.GetMock<INewznabRepository>()
.Setup(s => s.All())
.Returns(new List<NewznabDefinition>{new NewznabDefinition { OID = 1, Name = "", Url = "http://www.nzbdrone.com" }});
}
private void WithExisting()
{
Mocker.GetMock<INewznabRepository>()
.Setup(s => s.All())
.Returns(new List<NewznabDefinition> { new NewznabDefinition { OID = 1, Name = "Nzbs.org", Url = "http://nzbs.org" } });
}
[Test]
public void InitializeNewznabIndexers_should_initialize_build_in_indexers()
{
Subject.Init();
Mocker.GetMock<INewznabRepository>()
.Verify(s => s.Insert(It.Is<NewznabDefinition>(n => n.BuiltIn)), Times.Exactly(3));
}
[Test]
public void should_delete_indexers_without_names()
{
WithInvalidName();
Subject.Init();
Mocker.GetMock<INewznabRepository>()
.Verify(s => s.Delete(1), Times.Once());
}
[Test]
public void should_add_new_indexers()
{
WithExisting();
Subject.Init();
Mocker.GetMock<INewznabRepository>()
.Verify(s => s.Insert(It.IsAny<NewznabDefinition>()), Times.Exactly(2));
}
[Test]
public void should_update_existing()
{
WithExisting();
Subject.Init();
Mocker.GetMock<INewznabRepository>()
.Verify(s => s.Update(It.IsAny<NewznabDefinition>()), Times.Once());
}
[Test]
public void CheckHostname_should_do_nothing_if_hostname_is_valid()
{
Subject.CheckHostname("http://www.google.com");
}
[Test]
public void CheckHostname_should_log_error_and_throw_exception_if_dnsHostname_is_invalid()
{
Assert.Throws<SocketException>(() => Subject.CheckHostname("http://BadName"));
ExceptionVerification.ExpectedErrors(1);
}
}
}

@ -1,220 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class NewznabProviderTest : SqlCeTest<NewznabProvider>
{
[SetUp]
public void SetUp()
{
WithRealDb();
InitiateSubject();
}
[Test]
public void Save_should_clean_url_before_inserting()
{
var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world" };
const string expectedUrl = "http://www.nzbdrone.com";
var result = Subject.Save(newznab);
Db.Single<NewznabDefinition>(result).Url.Should().Be(expectedUrl);
}
[Test]
public void Save_should_clean_url_before_updating()
{
var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world" };
var result = Subject.Save(newznab);
Subject.All().Single(c => c.Id == result).Url.Should().Be("http://www.nzbdrone.com");
}
[Test]
public void Save_should_clean_url_before_inserting_when_url_is_not_empty()
{
var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "" };
var result = Subject.Save(newznab);
Subject.All().Single(c => c.Id == result).Url.Should().Be("");
}
[Test]
public void Save_should_clean_url_before_updating_when_url_is_not_empty()
{
var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "" };
var result = Subject.Save(newznab);
Db.Single<NewznabDefinition>(result).Url.Should().Be("");
}
[Test]
[Ignore("No longer clean newznab URLs")]
public void SaveAll_should_clean_urls_before_updating()
{
var definitions = Builder<NewznabDefinition>.CreateListOfSize(5)
.All()
.With(d => d.Url = "http://www.nzbdrone.com")
.Build();
var expectedUrl = "http://www.nzbdrone.com";
var newUrl = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world";
Db.InsertMany(definitions);
definitions.ToList().ForEach(d => d.Url = newUrl);
Subject.SaveAll(definitions);
Db.Fetch<NewznabDefinition>().Where(d => d.Url == expectedUrl).Should().HaveCount(5);
}
[Test]
public void Enabled_should_return_all_enabled_newznab_providers()
{
var definitions = Builder<NewznabDefinition>.CreateListOfSize(5)
.TheFirst(2)
.With(d => d.Enable = false)
.TheLast(3)
.With(d => d.Enable = true)
.Build();
Db.InsertMany(definitions);
var result = Subject.Enabled();
result.Should().HaveCount(3);
result.All(d => d.Enable).Should().BeTrue();
}
[Test]
public void All_should_return_all_newznab_providers()
{
var userIndexers = Builder<NewznabDefinition>.CreateListOfSize(5)
.All().With(c => c.Url = "http://www.host.com/12")
.Build();
Db.InsertMany(userIndexers);
var result = Subject.All();
result.Should().HaveCount(8);
}
[Test]
public void All_should_return_empty_list_when_no_indexers_exist()
{
Db.Delete<NewznabDefinition>("");
Subject.All().Should().NotBeNull();
Subject.All().Should().BeEmpty();
}
[Test]
public void Delete_should_delete_newznab_provider()
{
var toBeDelete = Subject.All()[2];
Subject.Delete(toBeDelete.Id);
Subject.All().Should().NotBeEmpty();
Subject.All().Should().NotContain(c => c.Id == toBeDelete.Id);
}
[Test]
public void InitializeNewznabIndexers_should_initialize_build_in_indexers()
{
var indexers = Subject.All();
indexers.Should().NotBeEmpty();
indexers.Should().OnlyContain(i => i.BuiltIn);
}
[Test]
public void InitializeNewznabIndexers_should_initialize_new_indexers_only()
{
var definitions = Builder<NewznabDefinition>.CreateListOfSize(5)
.All()
.With(d => d.Id = 0)
.TheFirst(2)
.With(d => d.Url = "http://www.nzbdrone2.com")
.TheLast(3)
.With(d => d.Url = "http://www.nzbdrone.com")
.Build();
Db.Insert(definitions[0]);
Db.Insert(definitions[2]);
Mocker.SetConstant<IEnumerable<NewznabDefinition>>(definitions);
var result = Db.Fetch<NewznabDefinition>();
result.Where(d => d.Url == "http://www.nzbdrone.com").Should().HaveCount(1);
result.Where(d => d.Url == "http://www.nzbdrone2.com").Should().HaveCount(1);
}
[Test]
public void InitializeNewznabIndexers_should_not_blow_up_if_more_than_one_indexer_with_the_same_url_is_found()
{
var definition = Builder<NewznabDefinition>.CreateNew()
.With(d => d.Url = "http://www.nzbdrone2.com")
.With(d => d.BuiltIn = false)
.Build();
Db.Insert(definition);
Db.Insert(definition);
Mocker.SetConstant<IEnumerable<NewznabDefinition>>(new List<NewznabDefinition> { definition });
var result = Db.Fetch<NewznabDefinition>().Where(c => c.BuiltIn == false);
result.Should().HaveCount(2);
}
[Test]
public void CheckHostname_should_do_nothing_if_hostname_is_valid()
{
Subject.CheckHostname("http://www.google.com");
}
[Test]
public void CheckHostname_should_log_error_and_throw_exception_if_dnsHostname_is_invalid()
{
Assert.Throws<SocketException>(() => Subject.CheckHostname("http://BadName"));
ExceptionVerification.ExpectedErrors(1);
}
}
}

@ -6,7 +6,6 @@ using FizzWare.NBuilder;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Providers;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Model.Notification;

@ -6,7 +6,7 @@ using Autofac.Core;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Indexers.Providers; using NzbDrone.Core.Indexers;
using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Providers.ExternalNotification; using NzbDrone.Core.Providers.ExternalNotification;
using NzbDrone.Core.Providers.Metadata; using NzbDrone.Core.Providers.Metadata;

@ -6,7 +6,7 @@ using NzbDrone.Common;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Indexers.Providers namespace NzbDrone.Core.Indexers
{ {
public class FileSharingTalk : IndexerBase public class FileSharingTalk : IndexerBase
{ {

@ -9,7 +9,7 @@ using NzbDrone.Common;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Indexers.Providers namespace NzbDrone.Core.Indexers
{ {
public abstract class IndexerBase public abstract class IndexerBase
{ {

@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Core.Indexers.Providers;
using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Lifecycle;
using PetaPoco; using PetaPoco;

@ -8,13 +8,13 @@ using NzbDrone.Core.Model;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Indexers.Providers namespace NzbDrone.Core.Indexers
{ {
public class Newznab : IndexerBase public class Newznab : IndexerBase
{ {
private readonly NewznabProvider _newznabProvider; private readonly NewznabService _newznabProvider;
public Newznab(HttpProvider httpProvider, ConfigProvider configProvider, NewznabProvider newznabProvider) public Newznab(HttpProvider httpProvider, ConfigProvider configProvider, NewznabService newznabProvider)
: base(httpProvider, configProvider) : base(httpProvider, configProvider)
{ {
_newznabProvider = newznabProvider; _newznabProvider = newznabProvider;

@ -0,0 +1,16 @@
using System;
using System.ComponentModel.DataAnnotations;
using NzbDrone.Core.Datastore;
using PetaPoco;
namespace NzbDrone.Core.Indexers
{
public class NewznabDefinition : ModelBase
{
public Boolean Enabled { get; set; }
public String Name { get; set; }
public String Url { get; set; }
public String ApiKey { get; set; }
public bool BuiltIn { get; set; }
}
}

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Indexers
{
public interface INewznabRepository : IBasicRepository<NewznabDefinition>
{
IEnumerable<NewznabDefinition> Enabled();
}
public class NewznabRepository : BasicRepository<NewznabDefinition>, INewznabRepository
{
public NewznabRepository(IObjectDatabase objectDatabase) : base(objectDatabase)
{
}
public IEnumerable<NewznabDefinition> Enabled()
{
return Queryable.Where(n => n.Enabled);
}
}
}

@ -0,0 +1,140 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using NLog;
using NzbDrone.Core.Lifecycle;
using PetaPoco;
namespace NzbDrone.Core.Indexers
{
public interface INewznabService
{
List<NewznabDefinition> All();
List<NewznabDefinition> Enabled();
NewznabDefinition Insert(NewznabDefinition definition);
void Update(NewznabDefinition definition);
}
public class NewznabService : INewznabService, IInitializable
{
private readonly INewznabRepository _newznabRepository;
private readonly Logger _logger;
public NewznabService(INewznabRepository newznabRepository, Logger logger)
{
_newznabRepository = newznabRepository;
_logger = logger;
}
public List<NewznabDefinition> All()
{
return _newznabRepository.All().ToList();
}
public List<NewznabDefinition> Enabled()
{
return _newznabRepository.Enabled().ToList();
}
public NewznabDefinition Insert(NewznabDefinition definition)
{
definition.Url = definition.Url.ToLower();
_logger.Debug("Adding Newznab definition for {0}", definition.Name);
return _newznabRepository.Insert(definition);
}
public void Update(NewznabDefinition definition)
{
definition.Url = definition.Url.ToLower();
_logger.Debug("Updating Newznab definition for {0}", definition.Name);
_newznabRepository.Update(definition);
}
public void Delete(int id)
{
_newznabRepository.Delete(id);
}
public void CheckHostname(string url)
{
try
{
var uri = new Uri(url);
var hostname = uri.DnsSafeHost;
Dns.GetHostEntry(hostname);
}
catch (Exception ex)
{
_logger.Error("Invalid address {0}, please correct the site URL.", url);
_logger.TraceException(ex.Message, ex);
throw;
}
}
public void Init()
{
var newznabIndexers = new List<NewznabDefinition>
{
new NewznabDefinition { Enabled = false, Name = "Nzbs.org", Url = "http://nzbs.org", BuiltIn = true },
new NewznabDefinition { Enabled = false, Name = "Nzb.su", Url = "https://nzb.su", BuiltIn = true },
new NewznabDefinition { Enabled = false, Name = "Dognzb.cr", Url = "https://dognzb.cr", BuiltIn = true }
};
_logger.Debug("Initializing Newznab indexers. Count {0}", newznabIndexers);
try
{
var currentIndexers = All();
_logger.Debug("Deleting broken Newznab indexer");
var brokenIndexers = currentIndexers.Where(i => String.IsNullOrEmpty(i.Name) || String.IsNullOrWhiteSpace(i.Url)).ToList();
brokenIndexers.ForEach(e => Delete(e.OID));
currentIndexers = All();
foreach (var feedProvider in newznabIndexers)
{
try
{
NewznabDefinition indexerLocal = feedProvider;
var currentIndexer = currentIndexers
.FirstOrDefault(c => new Uri(c.Url.ToLower()).Host == new Uri(indexerLocal.Url.ToLower()).Host);
if (currentIndexer == null)
{
var definition = new NewznabDefinition
{
Enabled = false,
Name = indexerLocal.Name,
Url = indexerLocal.Url,
ApiKey = indexerLocal.ApiKey,
BuiltIn = true
};
Insert(definition);
}
else
{
currentIndexer.Url = indexerLocal.Url;
currentIndexer.BuiltIn = true;
Update(currentIndexer);
}
}
catch (Exception ex)
{
_logger.ErrorException("An error occurred while setting up indexer: " + feedProvider.Name, ex);
}
}
}
catch (Exception ex)
{
_logger.ErrorException("An Error occurred while initializing Newznab Indexers", ex);
}
}
}
}

@ -7,7 +7,7 @@ using NzbDrone.Common;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Indexers.Providers namespace NzbDrone.Core.Indexers
{ {
public class NzbClub : IndexerBase public class NzbClub : IndexerBase
{ {

@ -7,7 +7,7 @@ using NzbDrone.Common;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Indexers.Providers namespace NzbDrone.Core.Indexers
{ {
public class NzbIndex : IndexerBase public class NzbIndex : IndexerBase
{ {

@ -7,7 +7,7 @@ using NzbDrone.Common;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Indexers.Providers namespace NzbDrone.Core.Indexers
{ {
public class NzbsRUs : IndexerBase public class NzbsRUs : IndexerBase
{ {

@ -9,7 +9,7 @@ using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Nzbx; using NzbDrone.Core.Model.Nzbx;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Indexers.Providers namespace NzbDrone.Core.Indexers
{ {
class Nzbx : IndexerBase class Nzbx : IndexerBase
{ {

@ -7,7 +7,7 @@ using NzbDrone.Common;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Indexers.Providers namespace NzbDrone.Core.Indexers
{ {
class Omgwtfnzbs : IndexerBase class Omgwtfnzbs : IndexerBase
{ {

@ -11,7 +11,7 @@ using System.Threading;
using System.Xml; using System.Xml;
using NLog; using NLog;
namespace NzbDrone.Core.Indexers.Providers namespace NzbDrone.Core.Indexers
{ {
public class SyndicationFeedXmlReader : XmlTextReader public class SyndicationFeedXmlReader : XmlTextReader
{ {

@ -6,7 +6,7 @@ using NzbDrone.Common;
using NzbDrone.Core.Model; using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Indexers.Providers namespace NzbDrone.Core.Indexers
{ {
public class Wombles : IndexerBase public class Wombles : IndexerBase
{ {

@ -269,6 +269,7 @@
<Compile Include="Helpers\SabnzbdPriorityTypeConverter.cs" /> <Compile Include="Helpers\SabnzbdPriorityTypeConverter.cs" />
<Compile Include="Helpers\XElementHelper.cs" /> <Compile Include="Helpers\XElementHelper.cs" />
<Compile Include="Indexers\IndexerRepository.cs" /> <Compile Include="Indexers\IndexerRepository.cs" />
<Compile Include="Indexers\NewznabRepository.cs" />
<Compile Include="Instrumentation\LogInjectionModule.cs" /> <Compile Include="Instrumentation\LogInjectionModule.cs" />
<Compile Include="Jobs\CleanupRecycleBinJob.cs" /> <Compile Include="Jobs\CleanupRecycleBinJob.cs" />
<Compile Include="Jobs\JobRepository.cs" /> <Compile Include="Jobs\JobRepository.cs" />
@ -341,13 +342,13 @@
<Compile Include="DecisionEngine\AllowedReleaseGroupSpecification.cs" /> <Compile Include="DecisionEngine\AllowedReleaseGroupSpecification.cs" />
<Compile Include="DecisionEngine\CustomStartDateSpecification.cs" /> <Compile Include="DecisionEngine\CustomStartDateSpecification.cs" />
<Compile Include="Providers\DownloadClients\PneumaticProvider.cs" /> <Compile Include="Providers\DownloadClients\PneumaticProvider.cs" />
<Compile Include="Indexers\Providers\Nzbx.cs" /> <Compile Include="Indexers\Nzbx.cs" />
<Compile Include="Providers\Hubs\EpisodeHub.cs" /> <Compile Include="Providers\Hubs\EpisodeHub.cs" />
<Compile Include="Indexers\Providers\NzbClub.cs" /> <Compile Include="Indexers\NzbClub.cs" />
<Compile Include="Indexers\Providers\NzbIndex.cs" /> <Compile Include="Indexers\NzbIndex.cs" />
<Compile Include="Indexers\Providers\FileSharingTalk.cs" /> <Compile Include="Indexers\FileSharingTalk.cs" />
<Compile Include="Indexers\Providers\Omgwtfnzbs.cs" /> <Compile Include="Indexers\Omgwtfnzbs.cs" />
<Compile Include="Indexers\Providers\Wombles.cs" /> <Compile Include="Indexers\Wombles.cs" />
<Compile Include="Providers\MetadataProvider.cs" /> <Compile Include="Providers\MetadataProvider.cs" />
<Compile Include="Providers\Metadata\MetadataBase.cs" /> <Compile Include="Providers\Metadata\MetadataBase.cs" />
<Compile Include="Providers\Metadata\Xbmc.cs" /> <Compile Include="Providers\Metadata\Xbmc.cs" />
@ -494,16 +495,16 @@
<Compile Include="Indexers\IndexerService.cs"> <Compile Include="Indexers\IndexerService.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Indexers\Providers\IndexerBase.cs"> <Compile Include="Indexers\IndexerBase.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Indexers\Providers\Newznab.cs"> <Compile Include="Indexers\Newznab.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Indexers\Providers\NzbsRUs.cs"> <Compile Include="Indexers\NzbsRUs.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Indexers\Providers\SyndicationFeedXmlReader.cs"> <Compile Include="Indexers\SyndicationFeedXmlReader.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Providers\MediaFileProvider.cs"> <Compile Include="Providers\MediaFileProvider.cs">
@ -512,7 +513,7 @@
<Compile Include="Providers\MisnamedProvider.cs"> <Compile Include="Providers\MisnamedProvider.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Providers\NewznabProvider.cs"> <Compile Include="Indexers\NewznabService.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Providers\NotificationProvider.cs"> <Compile Include="Providers\NotificationProvider.cs">
@ -574,7 +575,7 @@
<Compile Include="Providers\Xbmc\ResourceManager.cs"> <Compile Include="Providers\Xbmc\ResourceManager.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Repository\NewznabDefinition.cs" /> <Compile Include="Indexers\NewznabDefinition.cs" />
<Compile Include="Repository\ExternalNotificationDefinition.cs" /> <Compile Include="Repository\ExternalNotificationDefinition.cs" />
<Compile Include="Jobs\JobDefinition.cs" /> <Compile Include="Jobs\JobDefinition.cs" />
<Compile Include="Indexers\Indexer.cs" /> <Compile Include="Indexers\Indexer.cs" />

@ -1,155 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using NLog;
using NzbDrone.Core.Repository;
using PetaPoco;
namespace NzbDrone.Core.Providers
{
public class NewznabProvider
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
private readonly IDatabase _database;
public NewznabProvider(IDatabase database)
{
_database = database;
var newznabIndexers = new List<NewznabDefinition>
{
new NewznabDefinition { Enable = false, Name = "Nzbs.org", Url = "http://nzbs.org", BuiltIn = true },
new NewznabDefinition { Enable = false, Name = "Nzb.su", Url = "https://nzb.su", BuiltIn = true },
new NewznabDefinition { Enable = false, Name = "Dognzb.cr", Url = "https://dognzb.cr", BuiltIn = true }
};
InitializeNewznabIndexers(newznabIndexers);
}
public NewznabProvider()
{
}
public virtual List<NewznabDefinition> Enabled()
{
return _database.Fetch<NewznabDefinition>("WHERE Enable = 1");
}
public virtual List<NewznabDefinition> All()
{
return _database.Fetch<NewznabDefinition>();
}
public virtual int Save(NewznabDefinition definition)
{
//Cleanup the URL if it is not null or whitespace
if (!String.IsNullOrWhiteSpace(definition.Url))
definition.Url = (new Uri(definition.Url).ParentUriString());
if (definition.Id == 0)
{
logger.Debug("Adding Newznab definitions for {0}", definition.Name);
return Convert.ToInt32(_database.Insert(definition));
}
logger.Debug("Updating Newznab definitions for {0}", definition.Name);
return _database.Update(definition);
}
public virtual void SaveAll(IEnumerable<NewznabDefinition> definitions)
{
var definitionsList = definitions.ToList();
//Cleanup the URL for each definition
foreach (var newznabDefinition in definitionsList)
{
CheckHostname(newznabDefinition.Url);
//newznabDefinition.Url = new Uri(newznabDefinition.Url).ParentUriString();
}
_database.UpdateMany(definitionsList);
}
private void InitializeNewznabIndexers(IList<NewznabDefinition> indexers)
{
logger.Debug("Initializing Newznab indexers. Count {0}", indexers.Count);
try
{
var currentIndexers = All();
logger.Debug("Deleting broken Newznab indexer");
var brokenIndexers = currentIndexers.Where(i => String.IsNullOrEmpty(i.Name) || String.IsNullOrWhiteSpace(i.Url)).ToList();
brokenIndexers.ForEach(e => _database.Delete<NewznabDefinition>(e.Id));
currentIndexers = All();
foreach (var feedProvider in indexers)
{
try
{
NewznabDefinition indexerLocal = feedProvider;
var currentIndexer = currentIndexers
.FirstOrDefault(
c =>
new Uri(c.Url.ToLower()).Host == new Uri(indexerLocal.Url.ToLower()).Host);
if (currentIndexer == null)
{
var settings = new NewznabDefinition
{
Enable = false,
Name = indexerLocal.Name,
Url = indexerLocal.Url,
ApiKey = indexerLocal.ApiKey,
BuiltIn = true
};
Save(settings);
}
else
{
currentIndexer.Url = indexerLocal.Url;
currentIndexer.BuiltIn = true;
Save(currentIndexer);
}
}
catch (Exception ex)
{
logger.ErrorException("An error occurred while setting up indexer: " + feedProvider.Name, ex);
}
}
}
catch (Exception ex)
{
logger.ErrorException("An Error occurred while initializing Newznab Indexers", ex);
}
}
public virtual void Delete(int id)
{
_database.Delete<NewznabDefinition>(id);
}
public virtual void CheckHostname(string url)
{
try
{
var uri = new Uri(url);
var hostname = uri.DnsSafeHost;
Dns.GetHostEntry(hostname);
}
catch (Exception ex)
{
logger.Error("Invalid address {0}, please correct the site URL.", url);
logger.TraceException(ex.Message, ex);
throw;
}
}
}
}

@ -1,27 +0,0 @@
using System;
using System.ComponentModel.DataAnnotations;
using PetaPoco;
namespace NzbDrone.Core.Repository
{
[TableName("NewznabDefinitions")]
[PrimaryKey("Id", autoIncrement = true)]
public class NewznabDefinition
{
public int Id { get; set; }
public Boolean Enable { get; set; }
[StringLength(100, MinimumLength = 2)]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public String Name { get; set; }
[DisplayFormat(ConvertEmptyStringToNull = false)]
[RegularExpression(@"^http[s]?://.+")]
public String Url { get; set; }
public String ApiKey { get; set; }
public bool BuiltIn { get; set; }
}
}
Loading…
Cancel
Save