1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-18 21:35:27 -04:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Taloth Saldono 97c3863efb Temporary mock data while services isn't updated with new endpoint. 2017-05-13 00:19:34 +02:00
Taloth Saldono 7b4cb4145d Ability to blacklist and rename indexer urls via services. 2017-05-13 00:19:34 +02:00
Taloth Saldono 766520b851 Renamed DownloadClientStatus to DownloadClientInfo to avoid conflict. 2017-05-13 00:16:53 +02:00
Taloth Saldono 14144bd4d9 Renamed IndexerStatus.IndexerId to ProviderId. 2017-05-13 00:16:53 +02:00
Taloth Saldono 7b0e40d5d0 Replaced Url with BaseUrl in most indexers. 2017-05-13 00:16:53 +02:00
66 changed files with 678 additions and 116 deletions
@@ -44,7 +44,7 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
{ {
Mocker.GetMock<IIndexerStatusService>() Mocker.GetMock<IIndexerStatusService>()
.Setup(v => v.GetBlockedIndexers()) .Setup(v => v.GetBlockedIndexers())
.Returns(new List<IndexerStatus> { new IndexerStatus { IndexerId = 1, DisabledTill = DateTime.UtcNow.AddHours(2) } }); .Returns(new List<IndexerStatus> { new IndexerStatus { ProviderId = 1, DisabledTill = DateTime.UtcNow.AddHours(2) } });
GivenPendingRelease(); GivenPendingRelease();
@@ -40,7 +40,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
{ {
_blockedIndexers.Add(new IndexerStatus _blockedIndexers.Add(new IndexerStatus
{ {
IndexerId = id, ProviderId = id,
InitialFailure = DateTime.UtcNow.AddHours(-failureHours), InitialFailure = DateTime.UtcNow.AddHours(-failureHours),
MostRecentFailure = DateTime.UtcNow.AddHours(-0.1), MostRecentFailure = DateTime.UtcNow.AddHours(-0.1),
EscalationLevel = 5, EscalationLevel = 5,
@@ -28,7 +28,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
public void should_delete_orphaned_indexerstatus() public void should_delete_orphaned_indexerstatus()
{ {
var status = Builder<IndexerStatus>.CreateNew() var status = Builder<IndexerStatus>.CreateNew()
.With(h => h.IndexerId = _indexer.Id) .With(h => h.ProviderId = _indexer.Id)
.BuildNew(); .BuildNew();
Db.Insert(status); Db.Insert(status);
@@ -42,13 +42,13 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
GivenIndexer(); GivenIndexer();
var status = Builder<IndexerStatus>.CreateNew() var status = Builder<IndexerStatus>.CreateNew()
.With(h => h.IndexerId = _indexer.Id) .With(h => h.ProviderId = _indexer.Id)
.BuildNew(); .BuildNew();
Db.Insert(status); Db.Insert(status);
Subject.Clean(); Subject.Clean();
AllStoredModels.Should().HaveCount(1); AllStoredModels.Should().HaveCount(1);
AllStoredModels.Should().Contain(h => h.IndexerId == _indexer.Id); AllStoredModels.Should().Contain(h => h.ProviderId == _indexer.Id);
} }
} }
} }
@@ -20,7 +20,7 @@ namespace NzbDrone.Core.Test.IndexerTests.IPTorrentsTests
Subject.Definition = new IndexerDefinition() Subject.Definition = new IndexerDefinition()
{ {
Name = "IPTorrents", Name = "IPTorrents",
Settings = new IPTorrentsSettings() { Url = "http://fake.com/" } Settings = new IPTorrentsSettings() { BaseUrl = "http://fake.com/" }
}; };
} }
@@ -21,7 +21,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
{ {
_settings = new NewznabSettings() _settings = new NewznabSettings()
{ {
Url = "http://indxer.local" BaseUrl = "http://indxer.local"
}; };
_caps = ReadAllText("Files/Indexers/Newznab/newznab_caps.xml"); _caps = ReadAllText("Files/Indexers/Newznab/newznab_caps.xml");
@@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
Name = "Newznab", Name = "Newznab",
Settings = new NewznabSettings() Settings = new NewznabSettings()
{ {
Url = "http://indexer.local/", BaseUrl = "http://indexer.local/",
Categories = new int[] { 1 } Categories = new int[] { 1 }
} }
}; };
@@ -20,10 +20,10 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
{ {
Subject.Settings = new NewznabSettings() Subject.Settings = new NewznabSettings()
{ {
Url = "http://127.0.0.1:1234/", BaseUrl = "http://127.0.0.1:1234/",
Categories = new [] { 1, 2 }, Categories = new [] { 1, 2 },
AnimeCategories = new [] { 3, 4 }, AnimeCategories = new [] { 3, 4 },
ApiKey = "abcd", ApiKey = "abcd",
}; };
_singleEpisodeSearchCriteria = new SingleEpisodeSearchCriteria _singleEpisodeSearchCriteria = new SingleEpisodeSearchCriteria
@@ -84,7 +84,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
page.Url.FullUri.Should().Contain("&cat=3,4&"); page.Url.FullUri.Should().Contain("&cat=3,4&");
} }
[Test] [Test]
public void should_use_mode_search_for_anime() public void should_use_mode_search_for_anime()
{ {
@@ -15,12 +15,12 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
var setting = new NewznabSettings() var setting = new NewznabSettings()
{ {
ApiKey = "", ApiKey = "",
Url = url BaseUrl = url
}; };
setting.Validate().IsValid.Should().BeFalse(); setting.Validate().IsValid.Should().BeFalse();
setting.Validate().Errors.Should().Contain(c => c.PropertyName == "ApiKey"); setting.Validate().Errors.Should().Contain(c => c.PropertyName == nameof(NewznabSettings.ApiKey));
} }
@@ -32,13 +32,13 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
var setting = new NewznabSettings var setting = new NewznabSettings
{ {
ApiKey = "", ApiKey = "",
Url = url BaseUrl = url
}; };
setting.Validate().IsValid.Should().BeFalse(); setting.Validate().IsValid.Should().BeFalse();
setting.Validate().Errors.Should().NotContain(c => c.PropertyName == "ApiKey"); setting.Validate().Errors.Should().NotContain(c => c.PropertyName == nameof(NewznabSettings.ApiKey));
setting.Validate().Errors.Should().Contain(c => c.PropertyName == "Url"); setting.Validate().Errors.Should().Contain(c => c.PropertyName == nameof(NewznabSettings.BaseUrl));
} }
@@ -49,11 +49,11 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
var setting = new NewznabSettings() var setting = new NewznabSettings()
{ {
ApiKey = "", ApiKey = "",
Url = url BaseUrl = url
}; };
setting.Validate().IsValid.Should().BeTrue(); setting.Validate().IsValid.Should().BeTrue();
} }
} }
} }
@@ -1,14 +1,17 @@
using System; using System;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation; using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Test.IndexerTests namespace NzbDrone.Core.Test.IndexerTests
{ {
public class TestIndexerSettings : IProviderConfig public class TestIndexerSettings : IIndexerSettings
{ {
public NzbDroneValidationResult Validate() public NzbDroneValidationResult Validate()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public string BaseUrl { get; set; }
} }
} }
@@ -25,7 +25,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorznabTests
Name = "Torznab", Name = "Torznab",
Settings = new TorznabSettings() Settings = new TorznabSettings()
{ {
Url = "http://indexer.local/", BaseUrl = "http://indexer.local/",
Categories = new int[] { 1 } Categories = new int[] { 1 }
} }
}; };
@@ -44,7 +44,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorznabTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(o => o.Execute(It.Is<HttpRequest>(v => v.Method == HttpMethod.GET))) .Setup(o => o.Execute(It.Is<HttpRequest>(v => v.Method == HttpMethod.GET)))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), recentFeed)); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), recentFeed));
var releases = Subject.FetchRecent(); var releases = Subject.FetchRecent();
releases.Should().HaveCount(5); releases.Should().HaveCount(5);
@@ -366,6 +366,7 @@
<Compile Include="Qualities\QualityModelComparerFixture.cs" /> <Compile Include="Qualities\QualityModelComparerFixture.cs" />
<Compile Include="RootFolderTests\RootFolderServiceFixture.cs" /> <Compile Include="RootFolderTests\RootFolderServiceFixture.cs" />
<Compile Include="SeriesStatsTests\SeriesStatisticsFixture.cs" /> <Compile Include="SeriesStatsTests\SeriesStatisticsFixture.cs" />
<Compile Include="SkyhookNotifications\SkyhookNotificationServiceFixture.cs" />
<Compile Include="ThingiProvider\ProviderBaseFixture.cs" /> <Compile Include="ThingiProvider\ProviderBaseFixture.cs" />
<Compile Include="ThingiProviderTests\NullConfigFixture.cs" /> <Compile Include="ThingiProviderTests\NullConfigFixture.cs" />
<Compile Include="TvTests\EpisodeServiceTests\FindEpisodeByTitleFixture.cs" /> <Compile Include="TvTests\EpisodeServiceTests\FindEpisodeByTitleFixture.cs" />
@@ -0,0 +1,172 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.SkyhookNotifications;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.SkyhookNotifications
{
public class SkyhookNotificationServiceFixture : CoreTest<SkyhookNotificationService>
{
private static readonly Version _previousVersion = new Version(BuildInfo.Version.Major, BuildInfo.Version.Minor, BuildInfo.Version.Build, BuildInfo.Version.Revision - 1);
private static readonly Version _currentVersion = BuildInfo.Version;
private static readonly Version _nextVersion = new Version(BuildInfo.Version.Major, BuildInfo.Version.Minor, BuildInfo.Version.Build, BuildInfo.Version.Revision + 1);
private List<SkyhookNotification> _expiredNotifications;
private List<SkyhookNotification> _currentNotifications;
private List<SkyhookNotification> _futureNotifications;
private List<SkyhookNotification> _urlNotifications;
[SetUp]
public void SetUp()
{
_expiredNotifications = new List<SkyhookNotification>
{
new SkyhookNotification
{
Id = 1,
Type = SkyhookNotificationType.Notification,
Title = "Expired Notification",
MaximumVersion = _previousVersion.ToString()
}
};
_currentNotifications = new List<SkyhookNotification>
{
new SkyhookNotification
{
Id = 2,
Type = SkyhookNotificationType.Notification,
Title = "Timeless current Notification"
},
new SkyhookNotification
{
Id = 2,
Type = SkyhookNotificationType.Notification,
Title = "Ending current Notification",
MaximumVersion = _currentVersion.ToString()
},
new SkyhookNotification
{
Id = 2,
Type = SkyhookNotificationType.Notification,
Title = "Ending future Notification",
MaximumVersion = _nextVersion.ToString()
},
new SkyhookNotification
{
Id = 2,
Type = SkyhookNotificationType.Notification,
Title = "Starting previous Notification",
MinimumVersion = _previousVersion.ToString()
},
new SkyhookNotification
{
Id = 2,
Type = SkyhookNotificationType.Notification,
Title = "Starting current Notification",
MinimumVersion = _currentVersion.ToString()
}
};
_futureNotifications = new List<SkyhookNotification>
{
new SkyhookNotification
{
Id = 3,
Type = SkyhookNotificationType.Notification,
Title = "Future Notification",
MinimumVersion = _nextVersion.ToString()
}
};
_urlNotifications = new List<SkyhookNotification>
{
new SkyhookNotification
{
Id = 3,
Type = SkyhookNotificationType.UrlBlacklist,
Title = "Future Notification"
},
new SkyhookNotification
{
Id = 3,
Type = SkyhookNotificationType.UrlReplace,
Title = "Future Notification"
}
};
}
private void GivenNotifications(List<SkyhookNotification> notifications)
{
Mocker.GetMock<ISkyhookNotificationProxy>()
.Setup(v => v.GetNotifications())
.Returns(notifications);
}
[Test]
public void should_not_return_expired_notifications()
{
GivenNotifications(_expiredNotifications);
Subject.GetUserNotifications().Should().BeEmpty();
}
[Test]
public void should_not_return_future_notifications()
{
GivenNotifications(_futureNotifications);
Subject.GetUserNotifications().Should().BeEmpty();
}
[Test]
public void should_return_current_notifications()
{
GivenNotifications(_currentNotifications);
Subject.GetUserNotifications().Should().HaveCount(_currentNotifications.Count);
}
[Test]
public void should_not_return_user_notifications()
{
GivenNotifications(_currentNotifications);
Subject.GetUrlNotifications().Should().BeEmpty();
}
[Test]
public void should_not_return_url_notifications()
{
GivenNotifications(_urlNotifications);
Subject.GetUserNotifications().Should().BeEmpty();
}
[Test]
public void should_return_url_notifications()
{
GivenNotifications(_urlNotifications);
Subject.GetUrlNotifications().Should().HaveCount(_urlNotifications.Count);
}
[Test]
public void should_cache_api_result()
{
GivenNotifications(_urlNotifications);
Subject.GetUrlNotifications();
Subject.GetUrlNotifications();
Mocker.GetMock<ISkyhookNotificationProxy>()
.Verify(v => v.GetNotifications(), Times.Once());
}
}
}
@@ -0,0 +1,58 @@
using System.Collections.Generic;
using System.Data;
using FluentMigrator;
using Newtonsoft.Json.Linq;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(113)]
public class consolidate_indexer_baseurl : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.WithConnection(RenameUrlToBaseUrl);
}
private void RenameUrlToBaseUrl(IDbConnection conn, IDbTransaction tran)
{
using (var cmd = conn.CreateCommand())
{
cmd.Transaction = tran;
cmd.CommandText = "SELECT Id, Settings FROM Indexers WHERE ConfigContract IN ('NewznabSettings', 'TorznabSettings', 'IPTorrentsSettings', 'OmgwtfnzbsSettings')";
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
var id = reader.GetInt32(0);
var settings = reader.GetString(1);
if (settings.IsNotNullOrWhiteSpace())
{
var jsonObject = Json.Deserialize<JObject>(settings);
if (jsonObject.Property("url") != null)
{
jsonObject.AddFirst(new JProperty("baseUrl", jsonObject["url"]));
jsonObject.Remove("url");
settings = jsonObject.ToJson();
using (var updateCmd = conn.CreateCommand())
{
updateCmd.Transaction = tran;
updateCmd.CommandText = "UPDATE Indexers SET Settings = ? WHERE Id = ?";
updateCmd.AddParameter(settings);
updateCmd.AddParameter(id);
updateCmd.ExecuteNonQuery();
}
}
}
}
}
}
}
}
}
@@ -0,0 +1,14 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(114)]
public class rename_indexer_status_id : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Rename.Column("IndexerId").OnTable("IndexerStatus").To("ProviderId");
}
}
}
@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using FluentMigrator; using FluentMigrator;
@@ -7,6 +8,7 @@ using FluentMigrator.Model;
using FluentMigrator.Runner; using FluentMigrator.Runner;
using FluentMigrator.Runner.Generators.SQLite; using FluentMigrator.Runner.Generators.SQLite;
using FluentMigrator.Runner.Processors.SQLite; using FluentMigrator.Runner.Processors.SQLite;
using System.Text.RegularExpressions;
namespace NzbDrone.Core.Datastore.Migration.Framework namespace NzbDrone.Core.Datastore.Migration.Framework
{ {
@@ -62,6 +64,46 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
ProcessAlterTable(tableDefinition); ProcessAlterTable(tableDefinition);
} }
public override void Process(RenameColumnExpression expression)
{
var tableDefinition = GetTableSchema(expression.TableName);
var oldColumnDefinitions = tableDefinition.Columns.ToList();
var columnDefinitions = tableDefinition.Columns.ToList();
var columnIndex = columnDefinitions.FindIndex(c => c.Name == expression.OldName);
if (columnIndex == -1)
{
throw new ApplicationException(string.Format("Column {0} does not exist on table {1}.", expression.OldName, expression.TableName));
}
if (columnDefinitions.Any(c => c.Name == expression.NewName))
{
throw new ApplicationException(string.Format("Column {0} already exists on table {1}.", expression.NewName, expression.TableName));
}
oldColumnDefinitions[columnIndex] = (ColumnDefinition)columnDefinitions[columnIndex].Clone();
columnDefinitions[columnIndex].Name = expression.NewName;
foreach (var index in tableDefinition.Indexes)
{
if (index.Name.StartsWith("IX_"))
{
index.Name = Regex.Replace(index.Name, "(?<=_)" + Regex.Escape(expression.OldName) + "(?=_|$)", Regex.Escape(expression.NewName));
}
foreach (var column in index.Columns)
{
if (column.Name == expression.OldName)
{
column.Name = expression.NewName;
}
}
}
ProcessAlterTable(tableDefinition, oldColumnDefinitions);
}
protected virtual TableDefinition GetTableSchema(string tableName) protected virtual TableDefinition GetTableSchema(string tableName)
{ {
var schemaDumper = new SqliteSchemaDumper(this, Announcer); var schemaDumper = new SqliteSchemaDumper(this, Announcer);
@@ -70,7 +112,7 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
return schema.Single(v => v.Name == tableName); return schema.Single(v => v.Name == tableName);
} }
protected virtual void ProcessAlterTable(TableDefinition tableDefinition) protected virtual void ProcessAlterTable(TableDefinition tableDefinition, List<ColumnDefinition> oldColumnDefinitions = null)
{ {
var tableName = tableDefinition.Name; var tableName = tableDefinition.Name;
var tempTableName = tableName + "_temp"; var tempTableName = tableName + "_temp";
@@ -83,11 +125,12 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
// What is the cleanest way to do this? Add function to Generator? // What is the cleanest way to do this? Add function to Generator?
var quoter = new SQLiteQuoter(); var quoter = new SQLiteQuoter();
var columnsToTransfer = string.Join(", ", tableDefinition.Columns.Select(c => quoter.QuoteColumnName(c.Name))); var columnsToInsert = string.Join(", ", tableDefinition.Columns.Select(c => quoter.QuoteColumnName(c.Name)));
var columnsToFetch = string.Join(", ", (oldColumnDefinitions ?? tableDefinition.Columns).Select(c => quoter.QuoteColumnName(c.Name)));
Process(new CreateTableExpression() { TableName = tempTableName, Columns = tableDefinition.Columns.ToList() }); Process(new CreateTableExpression() { TableName = tempTableName, Columns = tableDefinition.Columns.ToList() });
Process(string.Format("INSERT INTO {0} SELECT {1} FROM {2}", quoter.QuoteTableName(tempTableName), columnsToTransfer, quoter.QuoteTableName(tableName))); Process(string.Format("INSERT INTO {0} ({1}) SELECT {2} FROM {3}", quoter.QuoteTableName(tempTableName), columnsToInsert, columnsToFetch, quoter.QuoteTableName(tableName)));
Process(new DeleteTableExpression() { TableName = tableName }); Process(new DeleteTableExpression() { TableName = tableName });
@@ -119,9 +119,9 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
DeleteItemData(downloadId); DeleteItemData(downloadId);
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
return new DownloadClientStatus return new DownloadClientInfo
{ {
IsLocalhost = true, IsLocalhost = true,
OutputRootFolders = new List<OsPath> { new OsPath(Settings.WatchFolder) } OutputRootFolders = new List<OsPath> { new OsPath(Settings.WatchFolder) }
@@ -86,9 +86,9 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
DeleteItemData(downloadId); DeleteItemData(downloadId);
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
return new DownloadClientStatus return new DownloadClientInfo
{ {
IsLocalhost = true, IsLocalhost = true,
OutputRootFolders = new List<OsPath> { new OsPath(Settings.WatchFolder) } OutputRootFolders = new List<OsPath> { new OsPath(Settings.WatchFolder) }
@@ -151,7 +151,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge
_proxy.RemoveTorrent(downloadId.ToLower(), deleteData, Settings); _proxy.RemoveTorrent(downloadId.ToLower(), deleteData, Settings);
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
var config = _proxy.GetConfig(Settings); var config = _proxy.GetConfig(Settings);
@@ -162,7 +162,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge
destDir = new OsPath(config.GetValueOrDefault("move_completed_path") as string); destDir = new OsPath(config.GetValueOrDefault("move_completed_path") as string);
} }
var status = new DownloadClientStatus var status = new DownloadClientInfo
{ {
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost" IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost"
}; };
@@ -105,13 +105,13 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
return items; return items;
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
try try
{ {
var path = GetDownloadDirectory(); var path = GetDownloadDirectory();
return new DownloadClientStatus return new DownloadClientInfo
{ {
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost",
OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(path)) } OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(path)) }
@@ -130,13 +130,13 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
return finalPath; return finalPath;
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
try try
{ {
var path = GetDownloadDirectory(); var path = GetDownloadDirectory();
return new DownloadClientStatus return new DownloadClientInfo
{ {
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost",
OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(path)) } OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(path)) }
@@ -117,12 +117,12 @@ namespace NzbDrone.Core.Download.Clients.Hadouken
} }
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
var config = _proxy.GetConfig(Settings); var config = _proxy.GetConfig(Settings);
var destDir = new OsPath(config.GetValueOrDefault("bittorrent.defaultSavePath") as string); var destDir = new OsPath(config.GetValueOrDefault("bittorrent.defaultSavePath") as string);
var status = new DownloadClientStatus var status = new DownloadClientInfo
{ {
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost" IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost"
}; };
@@ -142,9 +142,9 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex
return _proxy.GetGroups(Settings); return _proxy.GetGroups(Settings);
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
var status = new DownloadClientStatus var status = new DownloadClientInfo
{ {
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost" IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost"
}; };
@@ -214,13 +214,13 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
_proxy.RemoveItem(downloadId, Settings); _proxy.RemoveItem(downloadId, Settings);
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
var config = _proxy.GetConfig(Settings); var config = _proxy.GetConfig(Settings);
var category = GetCategories(config).FirstOrDefault(v => v.Name == Settings.TvCategory); var category = GetCategories(config).FirstOrDefault(v => v.Name == Settings.TvCategory);
var status = new DownloadClientStatus var status = new DownloadClientInfo
{ {
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost" IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost"
}; };
@@ -103,9 +103,9 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
throw new NotSupportedException(); throw new NotSupportedException();
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
var status = new DownloadClientStatus var status = new DownloadClientInfo
{ {
IsLocalhost = true IsLocalhost = true
}; };
@@ -174,13 +174,13 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
_proxy.RemoveTorrent(hash.ToLower(), deleteData, Settings); _proxy.RemoveTorrent(hash.ToLower(), deleteData, Settings);
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
var config = _proxy.GetConfig(Settings); var config = _proxy.GetConfig(Settings);
var destDir = new OsPath(config.SavePath); var destDir = new OsPath(config.SavePath);
return new DownloadClientStatus return new DownloadClientInfo
{ {
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost",
OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, destDir) } OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, destDir) }
@@ -250,7 +250,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
} }
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
var config = _proxy.GetConfig(Settings); var config = _proxy.GetConfig(Settings);
var categories = GetCategories(config).ToArray(); var categories = GetCategories(config).ToArray();
@@ -262,7 +262,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
category = categories.FirstOrDefault(v => v.Name == "*"); category = categories.FirstOrDefault(v => v.Name == "*");
} }
var status = new DownloadClientStatus var status = new DownloadClientInfo
{ {
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost" IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost"
}; };
@@ -119,7 +119,7 @@ namespace NzbDrone.Core.Download.Clients.Transmission
_proxy.RemoveTorrent(downloadId.ToLower(), deleteData, Settings); _proxy.RemoveTorrent(downloadId.ToLower(), deleteData, Settings);
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
var config = _proxy.GetConfig(Settings); var config = _proxy.GetConfig(Settings);
var destDir = config.GetValueOrDefault("download-dir") as string; var destDir = config.GetValueOrDefault("download-dir") as string;
@@ -129,7 +129,7 @@ namespace NzbDrone.Core.Download.Clients.Transmission
destDir = string.Format("{0}/.{1}", destDir, Settings.TvCategory); destDir = string.Format("{0}/.{1}", destDir, Settings.TvCategory);
} }
return new DownloadClientStatus return new DownloadClientInfo
{ {
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost", IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost",
OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(destDir)) } OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(destDir)) }
@@ -156,11 +156,11 @@ namespace NzbDrone.Core.Download.Clients.RTorrent
_proxy.RemoveTorrent(downloadId, Settings); _proxy.RemoveTorrent(downloadId, Settings);
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
// XXX: This function's correctness has not been considered // XXX: This function's correctness has not been considered
var status = new DownloadClientStatus var status = new DownloadClientInfo
{ {
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost" IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost"
}; };
@@ -178,7 +178,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
_proxy.RemoveTorrent(downloadId, deleteData, Settings); _proxy.RemoveTorrent(downloadId, deleteData, Settings);
} }
public override DownloadClientStatus GetStatus() public override DownloadClientInfo GetStatus()
{ {
var config = _proxy.GetConfig(Settings); var config = _proxy.GetConfig(Settings);
@@ -199,7 +199,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
} }
} }
var status = new DownloadClientStatus var status = new DownloadClientInfo
{ {
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost" IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost"
}; };
@@ -60,7 +60,7 @@ namespace NzbDrone.Core.Download
public abstract string Download(RemoteEpisode remoteEpisode); public abstract string Download(RemoteEpisode remoteEpisode);
public abstract IEnumerable<DownloadClientItem> GetItems(); public abstract IEnumerable<DownloadClientItem> GetItems();
public abstract void RemoveItem(string downloadId, bool deleteData); public abstract void RemoveItem(string downloadId, bool deleteData);
public abstract DownloadClientStatus GetStatus(); public abstract DownloadClientInfo GetStatus();
protected virtual void DeleteItemData(string downloadId) protected virtual void DeleteItemData(string downloadId)
{ {
@@ -3,7 +3,7 @@ using NzbDrone.Common.Disk;
namespace NzbDrone.Core.Download namespace NzbDrone.Core.Download
{ {
public class DownloadClientStatus public class DownloadClientInfo
{ {
public bool IsLocalhost { get; set; } public bool IsLocalhost { get; set; }
public List<OsPath> OutputRootFolders { get; set; } public List<OsPath> OutputRootFolders { get; set; }
@@ -12,6 +12,6 @@ namespace NzbDrone.Core.Download
string Download(RemoteEpisode remoteEpisode); string Download(RemoteEpisode remoteEpisode);
IEnumerable<DownloadClientItem> GetItems(); IEnumerable<DownloadClientItem> GetItems();
void RemoveItem(string downloadId, bool deleteData); void RemoveItem(string downloadId, bool deleteData);
DownloadClientStatus GetStatus(); DownloadClientInfo GetStatus();
} }
} }
@@ -101,7 +101,7 @@ namespace NzbDrone.Core.Download.Pending
private List<ReleaseInfo> FilterBlockedIndexers(List<ReleaseInfo> releases) private List<ReleaseInfo> FilterBlockedIndexers(List<ReleaseInfo> releases)
{ {
var blockedIndexers = new HashSet<int>(_indexerStatusService.GetBlockedIndexers().Select(v => v.IndexerId)); var blockedIndexers = new HashSet<int>(_indexerStatusService.GetBlockedIndexers().Select(v => v.ProviderId));
return releases.Where(release => !blockedIndexers.Contains(release.IndexerId)).ToList(); return releases.Where(release => !blockedIndexers.Contains(release.IndexerId)).ToList();
} }
@@ -91,6 +91,6 @@ namespace NzbDrone.Core.HealthCheck.Checks
public class ImportMechanismCheckStatus public class ImportMechanismCheckStatus
{ {
public IDownloadClient DownloadClient { get; set; } public IDownloadClient DownloadClient { get; set; }
public DownloadClientStatus Status { get; set; } public DownloadClientInfo Status { get; set; }
} }
} }
@@ -21,7 +21,7 @@ namespace NzbDrone.Core.HealthCheck.Checks
var enabledIndexers = _indexerFactory.GetAvailableProviders(); var enabledIndexers = _indexerFactory.GetAvailableProviders();
var backOffIndexers = enabledIndexers.Join(_indexerStatusService.GetBlockedIndexers(), var backOffIndexers = enabledIndexers.Join(_indexerStatusService.GetBlockedIndexers(),
i => i.Definition.Id, i => i.Definition.Id,
s => s.IndexerId, s => s.ProviderId,
(i, s) => new { Indexer = i, Status = s }) (i, s) => new { Indexer = i, Status = s })
.Where(v => (v.Status.MostRecentFailure - v.Status.InitialFailure) > TimeSpan.FromHours(1)) .Where(v => (v.Status.MostRecentFailure - v.Status.InitialFailure) > TimeSpan.FromHours(1))
.ToList(); .ToList();
@@ -19,7 +19,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE Id IN ( WHERE Id IN (
SELECT IndexerStatus.Id FROM IndexerStatus SELECT IndexerStatus.Id FROM IndexerStatus
LEFT OUTER JOIN Indexers LEFT OUTER JOIN Indexers
ON IndexerStatus.IndexerId = Indexers.Id ON IndexerStatus.ProviderId = Indexers.Id
WHERE Indexers.Id IS NULL)"); WHERE Indexers.Id IS NULL)");
} }
} }
@@ -23,7 +23,7 @@ namespace NzbDrone.Core.Indexers.BitMeTv
} }
} }
public class BitMeTvSettings : IProviderConfig public class BitMeTvSettings : IIndexerSettings
{ {
private static readonly BitMeTvSettingsValidator Validator = new BitMeTvSettingsValidator(); private static readonly BitMeTvSettingsValidator Validator = new BitMeTvSettingsValidator();
@@ -49,4 +49,4 @@ namespace NzbDrone.Core.Indexers.BitMeTv
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));
} }
} }
} }
@@ -14,7 +14,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet
} }
} }
public class BroadcastheNetSettings : IProviderConfig public class BroadcastheNetSettings : IIndexerSettings
{ {
private static readonly BroadcastheNetSettingsValidator Validator = new BroadcastheNetSettingsValidator(); private static readonly BroadcastheNetSettingsValidator Validator = new BroadcastheNetSettingsValidator();
@@ -13,7 +13,7 @@ namespace NzbDrone.Core.Indexers.Fanzub
} }
} }
public class FanzubSettings : IProviderConfig public class FanzubSettings : IIndexerSettings
{ {
private static readonly FanzubSettingsValidator Validator = new FanzubSettingsValidator(); private static readonly FanzubSettingsValidator Validator = new FanzubSettingsValidator();
@@ -14,7 +14,7 @@ namespace NzbDrone.Core.Indexers.HDBits
} }
} }
public class HDBitsSettings : IProviderConfig public class HDBitsSettings : IIndexerSettings
{ {
private static readonly HDBitsSettingsValidator Validator = new HDBitsSettingsValidator(); private static readonly HDBitsSettingsValidator Validator = new HDBitsSettingsValidator();
@@ -17,7 +17,7 @@ using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers namespace NzbDrone.Core.Indexers
{ {
public abstract class HttpIndexerBase<TSettings> : IndexerBase<TSettings> public abstract class HttpIndexerBase<TSettings> : IndexerBase<TSettings>
where TSettings : IProviderConfig, new() where TSettings : IIndexerSettings, new()
{ {
protected const int MaxNumResultsPerQuery = 1000; protected const int MaxNumResultsPerQuery = 1000;
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers
{
public interface IIndexerSettings : IProviderConfig
{
string BaseUrl { get; set; }
}
}
@@ -7,7 +7,7 @@ namespace NzbDrone.Core.Indexers.IPTorrents
public class IPTorrentsRequestGenerator : IIndexerRequestGenerator public class IPTorrentsRequestGenerator : IIndexerRequestGenerator
{ {
public IPTorrentsSettings Settings { get; set; } public IPTorrentsSettings Settings { get; set; }
public virtual IndexerPageableRequestChain GetRecentRequests() public virtual IndexerPageableRequestChain GetRecentRequests()
{ {
var pageableRequests = new IndexerPageableRequestChain(); var pageableRequests = new IndexerPageableRequestChain();
@@ -44,7 +44,7 @@ namespace NzbDrone.Core.Indexers.IPTorrents
private IEnumerable<IndexerRequest> GetRssRequests() private IEnumerable<IndexerRequest> GetRssRequests()
{ {
yield return new IndexerRequest(Settings.Url, HttpAccept.Rss); yield return new IndexerRequest(Settings.BaseUrl, HttpAccept.Rss);
} }
} }
} }
@@ -11,17 +11,17 @@ namespace NzbDrone.Core.Indexers.IPTorrents
{ {
public IPTorrentsSettingsValidator() public IPTorrentsSettingsValidator()
{ {
RuleFor(c => c.Url).ValidRootUrl(); RuleFor(c => c.BaseUrl).ValidRootUrl();
RuleFor(c => c.Url).Matches(@"/rss\?.+$"); RuleFor(c => c.BaseUrl).Matches(@"/rss\?.+$");
RuleFor(c => c.Url).Matches(@"/rss\?.+;download(?:;|$)") RuleFor(c => c.BaseUrl).Matches(@"/rss\?.+;download(?:;|$)")
.WithMessage("Use Direct Download Url (;download)") .WithMessage("Use Direct Download Url (;download)")
.When(v => v.Url.IsNotNullOrWhiteSpace() && Regex.IsMatch(v.Url, @"/rss\?.+$")); .When(v => v.BaseUrl.IsNotNullOrWhiteSpace() && Regex.IsMatch(v.BaseUrl, @"/rss\?.+$"));
} }
} }
public class IPTorrentsSettings : IProviderConfig public class IPTorrentsSettings : IIndexerSettings
{ {
private static readonly IPTorrentsSettingsValidator Validator = new IPTorrentsSettingsValidator(); private static readonly IPTorrentsSettingsValidator Validator = new IPTorrentsSettingsValidator();
@@ -30,7 +30,7 @@ namespace NzbDrone.Core.Indexers.IPTorrents
} }
[FieldDefinition(0, Label = "Feed URL", HelpText = "The full RSS feed url generated by IPTorrents, using only the categories you selected (HD, SD, x264, etc ...)")] [FieldDefinition(0, Label = "Feed URL", HelpText = "The full RSS feed url generated by IPTorrents, using only the categories you selected (HD, SD, x264, etc ...)")]
public string Url { get; set; } public string BaseUrl { get; set; }
public NzbDroneValidationResult Validate() public NzbDroneValidationResult Validate()
{ {
+1 -1
View File
@@ -13,7 +13,7 @@ using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers namespace NzbDrone.Core.Indexers
{ {
public abstract class IndexerBase<TSettings> : IIndexer public abstract class IndexerBase<TSettings> : IIndexer
where TSettings : IProviderConfig, new() where TSettings : IIndexerSettings, new()
{ {
protected readonly IIndexerStatusService _indexerStatusService; protected readonly IIndexerStatusService _indexerStatusService;
protected readonly IConfigService _configService; protected readonly IConfigService _configService;
+30 -6
View File
@@ -2,7 +2,9 @@
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.Composition; using NzbDrone.Common.Composition;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.SkyhookNotifications;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers namespace NzbDrone.Core.Indexers
@@ -15,17 +17,20 @@ namespace NzbDrone.Core.Indexers
public class IndexerFactory : ProviderFactory<IIndexer, IndexerDefinition>, IIndexerFactory public class IndexerFactory : ProviderFactory<IIndexer, IndexerDefinition>, IIndexerFactory
{ {
private readonly ISubstituteIndexerUrl _substituteIndexerUrl;
private readonly IIndexerStatusService _indexerStatusService; private readonly IIndexerStatusService _indexerStatusService;
private readonly Logger _logger; private readonly Logger _logger;
public IndexerFactory(IIndexerStatusService indexerStatusService, public IndexerFactory(ISubstituteIndexerUrl replaceIndexerUrl,
IIndexerStatusService indexerStatusService,
IIndexerRepository providerRepository, IIndexerRepository providerRepository,
IEnumerable<IIndexer> providers, IEnumerable<IIndexer> providers,
IContainer container, IContainer container,
IEventAggregator eventAggregator, IEventAggregator eventAggregator,
Logger logger) Logger logger)
: base(providerRepository, providers, container, eventAggregator, logger) : base(providerRepository, providers, container, eventAggregator, logger)
{ {
_substituteIndexerUrl = replaceIndexerUrl;
_indexerStatusService = indexerStatusService; _indexerStatusService = indexerStatusService;
_logger = logger; _logger = logger;
} }
@@ -50,7 +55,7 @@ namespace NzbDrone.Core.Indexers
if (filterBlockedIndexers) if (filterBlockedIndexers)
{ {
return FilterBlockedIndexers(enabledIndexers).ToList(); return FilterBlockedIndexers(SubstituteIndexerUrls(enabledIndexers)).ToList();
} }
return enabledIndexers.ToList(); return enabledIndexers.ToList();
@@ -62,15 +67,34 @@ namespace NzbDrone.Core.Indexers
if (filterBlockedIndexers) if (filterBlockedIndexers)
{ {
return FilterBlockedIndexers(enabledIndexers).ToList(); return FilterBlockedIndexers(SubstituteIndexerUrls(enabledIndexers)).ToList();
} }
return enabledIndexers.ToList(); return enabledIndexers.ToList();
} }
private IEnumerable<IIndexer> SubstituteIndexerUrls(IEnumerable<IIndexer> indexers)
{
foreach (var indexer in indexers)
{
var settings = (IIndexerSettings)indexer.Definition.Settings;
if (settings.BaseUrl.IsNotNullOrWhiteSpace())
{
var newBaseUrl = _substituteIndexerUrl.SubstituteUrl(settings.BaseUrl);
if (newBaseUrl != settings.BaseUrl)
{
_logger.Debug("Substituted indexer {0} url {1} with {2} since services blacklisted it.", indexer.Definition.Name, settings.BaseUrl, newBaseUrl);
settings.BaseUrl = newBaseUrl;
}
}
yield return indexer;
}
}
private IEnumerable<IIndexer> FilterBlockedIndexers(IEnumerable<IIndexer> indexers) private IEnumerable<IIndexer> FilterBlockedIndexers(IEnumerable<IIndexer> indexers)
{ {
var blockedIndexers = _indexerStatusService.GetBlockedIndexers().ToDictionary(v => v.IndexerId, v => v); var blockedIndexers = _indexerStatusService.GetBlockedIndexers().ToDictionary(v => v.ProviderId, v => v);
foreach (var indexer in indexers) foreach (var indexer in indexers)
{ {
@@ -85,4 +109,4 @@ namespace NzbDrone.Core.Indexers
} }
} }
} }
} }
+1 -1
View File
@@ -6,7 +6,7 @@ namespace NzbDrone.Core.Indexers
{ {
public class IndexerStatus : ModelBase public class IndexerStatus : ModelBase
{ {
public int IndexerId { get; set; } public int ProviderId { get; set; }
public DateTime? InitialFailure { get; set; } public DateTime? InitialFailure { get; set; }
public DateTime? MostRecentFailure { get; set; } public DateTime? MostRecentFailure { get; set; }
@@ -20,7 +20,7 @@ namespace NzbDrone.Core.Indexers
public IndexerStatus FindByIndexerId(int indexerId) public IndexerStatus FindByIndexerId(int indexerId)
{ {
return Query.Where(c => c.IndexerId == indexerId).SingleOrDefault(); return Query.Where(c => c.ProviderId == indexerId).SingleOrDefault();
} }
} }
} }
@@ -57,7 +57,7 @@ namespace NzbDrone.Core.Indexers
private IndexerStatus GetIndexerStatus(int indexerId) private IndexerStatus GetIndexerStatus(int indexerId)
{ {
return _indexerStatusRepository.FindByIndexerId(indexerId) ?? new IndexerStatus { IndexerId = indexerId }; return _indexerStatusRepository.FindByIndexerId(indexerId) ?? new IndexerStatus { ProviderId = indexerId };
} }
private TimeSpan CalculateBackOffPeriod(IndexerStatus status) private TimeSpan CalculateBackOffPeriod(IndexerStatus status)
@@ -78,7 +78,7 @@ namespace NzbDrone.Core.Indexers.Newznab
private NewznabSettings GetSettings(string url, params int[] categories) private NewznabSettings GetSettings(string url, params int[] categories)
{ {
var settings = new NewznabSettings { Url = url }; var settings = new NewznabSettings { BaseUrl = url };
if (categories.Any()) if (categories.Any())
{ {
@@ -41,7 +41,7 @@ namespace NzbDrone.Core.Indexers.Newznab
{ {
var capabilities = new NewznabCapabilities(); var capabilities = new NewznabCapabilities();
var url = string.Format("{0}/api?t=caps", indexerSettings.Url.TrimEnd('/')); var url = string.Format("{0}/api?t=caps", indexerSettings.BaseUrl.TrimEnd('/'));
if (indexerSettings.ApiKey.IsNotNullOrWhiteSpace()) if (indexerSettings.ApiKey.IsNotNullOrWhiteSpace())
{ {
@@ -58,7 +58,7 @@ namespace NzbDrone.Core.Indexers.Newznab
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.Debug(ex, "Failed to get newznab api capabilities from {0}", indexerSettings.Url); _logger.Debug(ex, "Failed to get newznab api capabilities from {0}", indexerSettings.BaseUrl);
throw; throw;
} }
@@ -68,14 +68,14 @@ namespace NzbDrone.Core.Indexers.Newznab
} }
catch (XmlException ex) catch (XmlException ex)
{ {
_logger.Debug(ex, "Failed to parse newznab api capabilities for {0}.", indexerSettings.Url); _logger.Debug(ex, "Failed to parse newznab api capabilities for {0}.", indexerSettings.BaseUrl);
ex.WithData(response); ex.WithData(response);
throw; throw;
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.Error(ex, "Failed to determine newznab api capabilities for {0}, using the defaults instead till Sonarr restarts.", indexerSettings.Url); _logger.Error(ex, "Failed to determine newznab api capabilities for {0}, using the defaults instead till Sonarr restarts.", indexerSettings.BaseUrl);
} }
return capabilities; return capabilities;
@@ -249,7 +249,7 @@ namespace NzbDrone.Core.Indexers.Newznab
var categoriesQuery = string.Join(",", categories.Distinct()); var categoriesQuery = string.Join(",", categories.Distinct());
var baseUrl = string.Format("{0}/api?t={1}&cat={2}&extended=1{3}", Settings.Url.TrimEnd('/'), searchType, categoriesQuery, Settings.AdditionalParameters); var baseUrl = string.Format("{0}/api?t={1}&cat={2}&extended=1{3}", Settings.BaseUrl.TrimEnd('/'), searchType, categoriesQuery, Settings.AdditionalParameters);
if (Settings.ApiKey.IsNotNullOrWhiteSpace()) if (Settings.ApiKey.IsNotNullOrWhiteSpace())
{ {
@@ -25,12 +25,12 @@ namespace NzbDrone.Core.Indexers.Newznab
private static bool ShouldHaveApiKey(NewznabSettings settings) private static bool ShouldHaveApiKey(NewznabSettings settings)
{ {
if (settings.Url == null) if (settings.BaseUrl == null)
{ {
return false; return false;
} }
return ApiKeyWhiteList.Any(c => settings.Url.ToLowerInvariant().Contains(c)); return ApiKeyWhiteList.Any(c => settings.BaseUrl.ToLowerInvariant().Contains(c));
} }
private static readonly Regex AdditionalParametersRegex = new Regex(@"(&.+?\=.+?)+", RegexOptions.Compiled); private static readonly Regex AdditionalParametersRegex = new Regex(@"(&.+?\=.+?)+", RegexOptions.Compiled);
@@ -47,14 +47,14 @@ namespace NzbDrone.Core.Indexers.Newznab
return null; return null;
}); });
RuleFor(c => c.Url).ValidRootUrl(); RuleFor(c => c.BaseUrl).ValidRootUrl();
RuleFor(c => c.ApiKey).NotEmpty().When(ShouldHaveApiKey); RuleFor(c => c.ApiKey).NotEmpty().When(ShouldHaveApiKey);
RuleFor(c => c.AdditionalParameters).Matches(AdditionalParametersRegex) RuleFor(c => c.AdditionalParameters).Matches(AdditionalParametersRegex)
.When(c => !c.AdditionalParameters.IsNullOrWhiteSpace()); .When(c => !c.AdditionalParameters.IsNullOrWhiteSpace());
} }
} }
public class NewznabSettings : IProviderConfig public class NewznabSettings : IIndexerSettings
{ {
private static readonly NewznabSettingsValidator Validator = new NewznabSettingsValidator(); private static readonly NewznabSettingsValidator Validator = new NewznabSettingsValidator();
@@ -65,7 +65,7 @@ namespace NzbDrone.Core.Indexers.Newznab
} }
[FieldDefinition(0, Label = "URL")] [FieldDefinition(0, Label = "URL")]
public string Url { get; set; } public string BaseUrl { get; set; }
[FieldDefinition(1, Label = "API Key")] [FieldDefinition(1, Label = "API Key")]
public string ApiKey { get; set; } public string ApiKey { get; set; }
@@ -84,4 +84,4 @@ namespace NzbDrone.Core.Indexers.Newznab
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));
} }
} }
} }
@@ -14,7 +14,7 @@ namespace NzbDrone.Core.Indexers.Nyaa
} }
} }
public class NyaaSettings : IProviderConfig public class NyaaSettings : IIndexerSettings
{ {
private static readonly NyaaSettingsValidator Validator = new NyaaSettingsValidator(); private static readonly NyaaSettingsValidator Validator = new NyaaSettingsValidator();
@@ -35,4 +35,4 @@ namespace NzbDrone.Core.Indexers.Nyaa
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));
} }
} }
} }
@@ -15,7 +15,7 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
} }
} }
public class OmgwtfnzbsSettings : IProviderConfig public class OmgwtfnzbsSettings : IIndexerSettings
{ {
private static readonly OmgwtfnzbsSettingsValidator Validator = new OmgwtfnzbsSettingsValidator(); private static readonly OmgwtfnzbsSettingsValidator Validator = new OmgwtfnzbsSettingsValidator();
@@ -24,6 +24,9 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
Delay = 30; Delay = 30;
} }
// Unused since Omg has a hardcoded url.
public string BaseUrl { get; set; }
[FieldDefinition(0, Label = "Username")] [FieldDefinition(0, Label = "Username")]
public string Username { get; set; } public string Username { get; set; }
@@ -13,7 +13,7 @@ namespace NzbDrone.Core.Indexers.Rarbg
} }
} }
public class RarbgSettings : IProviderConfig public class RarbgSettings : IIndexerSettings
{ {
private static readonly RarbgSettingsValidator Validator = new RarbgSettingsValidator(); private static readonly RarbgSettingsValidator Validator = new RarbgSettingsValidator();
@@ -28,7 +28,7 @@ namespace NzbDrone.Core.Indexers.Rarbg
[FieldDefinition(1, Type = FieldType.Checkbox, Label = "Ranked Only", HelpText = "Only include ranked results.")] [FieldDefinition(1, Type = FieldType.Checkbox, Label = "Ranked Only", HelpText = "Only include ranked results.")]
public bool RankedOnly { get; set; } public bool RankedOnly { get; set; }
[FieldDefinition(2, Type = FieldType.Captcha, Label = "CAPTCHA Token", HelpText = "CAPTCHA Clearance token used to handle CloudFlare Anti-DDOS measures on shared-ip VPNs.")] [FieldDefinition(2, Type = FieldType.Captcha, Label = "CAPTCHA Token", HelpText = "CAPTCHA Clearance token used to handle CloudFlare Anti-DDOS measures on shared-ip VPNs.")]
public string CaptchaToken { get; set; } public string CaptchaToken { get; set; }
@@ -37,4 +37,4 @@ namespace NzbDrone.Core.Indexers.Rarbg
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));
} }
} }
} }
@@ -13,7 +13,7 @@ namespace NzbDrone.Core.Indexers.TorrentRss
} }
} }
public class TorrentRssIndexerSettings : IProviderConfig public class TorrentRssIndexerSettings : IIndexerSettings
{ {
private static readonly TorrentRssIndexerSettingsValidator validator = new TorrentRssIndexerSettingsValidator(); private static readonly TorrentRssIndexerSettingsValidator validator = new TorrentRssIndexerSettingsValidator();
@@ -37,4 +37,4 @@ namespace NzbDrone.Core.Indexers.TorrentRss
return new NzbDroneValidationResult(validator.Validate(this)); return new NzbDroneValidationResult(validator.Validate(this));
} }
} }
} }
@@ -14,7 +14,7 @@ namespace NzbDrone.Core.Indexers.Torrentleech
} }
} }
public class TorrentleechSettings : IProviderConfig public class TorrentleechSettings : IIndexerSettings
{ {
private static readonly TorrentleechSettingsValidator Validator = new TorrentleechSettingsValidator(); private static readonly TorrentleechSettingsValidator Validator = new TorrentleechSettingsValidator();
@@ -34,4 +34,4 @@ namespace NzbDrone.Core.Indexers.Torrentleech
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));
} }
} }
} }
@@ -66,7 +66,7 @@ namespace NzbDrone.Core.Indexers.Torznab
private TorznabSettings GetSettings(string url, params int[] categories) private TorznabSettings GetSettings(string url, params int[] categories)
{ {
var settings = new TorznabSettings { Url = url }; var settings = new TorznabSettings { BaseUrl = url };
if (categories.Any()) if (categories.Any())
{ {
@@ -17,12 +17,12 @@ namespace NzbDrone.Core.Indexers.Torznab
private static bool ShouldHaveApiKey(TorznabSettings settings) private static bool ShouldHaveApiKey(TorznabSettings settings)
{ {
if (settings.Url == null) if (settings.BaseUrl == null)
{ {
return false; return false;
} }
return ApiKeyWhiteList.Any(c => settings.Url.ToLowerInvariant().Contains(c)); return ApiKeyWhiteList.Any(c => settings.BaseUrl.ToLowerInvariant().Contains(c));
} }
private static readonly Regex AdditionalParametersRegex = new Regex(@"(&.+?\=.+?)+", RegexOptions.Compiled); private static readonly Regex AdditionalParametersRegex = new Regex(@"(&.+?\=.+?)+", RegexOptions.Compiled);
@@ -39,7 +39,7 @@ namespace NzbDrone.Core.Indexers.Torznab
return null; return null;
}); });
RuleFor(c => c.Url).ValidRootUrl(); RuleFor(c => c.BaseUrl).ValidRootUrl();
RuleFor(c => c.ApiKey).NotEmpty().When(ShouldHaveApiKey); RuleFor(c => c.ApiKey).NotEmpty().When(ShouldHaveApiKey);
RuleFor(c => c.AdditionalParameters).Matches(AdditionalParametersRegex) RuleFor(c => c.AdditionalParameters).Matches(AdditionalParametersRegex)
.When(c => !c.AdditionalParameters.IsNullOrWhiteSpace()); .When(c => !c.AdditionalParameters.IsNullOrWhiteSpace());
@@ -55,4 +55,4 @@ namespace NzbDrone.Core.Indexers.Torznab
return new NzbDroneValidationResult(Validator.Validate(this)); return new NzbDroneValidationResult(Validator.Validate(this));
} }
} }
} }
+10 -4
View File
@@ -250,6 +250,8 @@
<Compile Include="Datastore\Migration\069_quality_proper.cs" /> <Compile Include="Datastore\Migration\069_quality_proper.cs" />
<Compile Include="Datastore\Migration\070_delay_profile.cs" /> <Compile Include="Datastore\Migration\070_delay_profile.cs" />
<Compile Include="Datastore\Migration\102_add_language_to_episodeFiles_history_and_blacklist.cs" /> <Compile Include="Datastore\Migration\102_add_language_to_episodeFiles_history_and_blacklist.cs" />
<Compile Include="Datastore\Migration\113_consolidate_indexer_baseurl.cs" />
<Compile Include="Datastore\Migration\114_rename_indexer_status_id.cs" />
<Compile Include="Datastore\Migration\112_added_regex_to_scenemapping.cs" /> <Compile Include="Datastore\Migration\112_added_regex_to_scenemapping.cs" />
<Compile Include="Datastore\Migration\110_fix_extra_files_config.cs" /> <Compile Include="Datastore\Migration\110_fix_extra_files_config.cs" />
<Compile Include="Datastore\Migration\109_import_extra_files.cs" /> <Compile Include="Datastore\Migration\109_import_extra_files.cs" />
@@ -410,9 +412,7 @@
<Compile Include="Download\Clients\Nzbget\NzbgetSettings.cs" /> <Compile Include="Download\Clients\Nzbget\NzbgetSettings.cs" />
<Compile Include="Download\Clients\NzbVortex\JsonConverters\NzbVortexLoginResultTypeConverter.cs" /> <Compile Include="Download\Clients\NzbVortex\JsonConverters\NzbVortexLoginResultTypeConverter.cs" />
<Compile Include="Download\Clients\NzbVortex\JsonConverters\NzbVortexResultTypeConverter.cs" /> <Compile Include="Download\Clients\NzbVortex\JsonConverters\NzbVortexResultTypeConverter.cs" />
<Compile Include="Download\Clients\NzbVortex\NzbVortex.cs"> <Compile Include="Download\Clients\NzbVortex\NzbVortex.cs" />
<SubType>Code</SubType>
</Compile>
<Compile Include="Download\Clients\NzbVortex\NzbVortexGroup.cs" /> <Compile Include="Download\Clients\NzbVortex\NzbVortexGroup.cs" />
<Compile Include="Download\Clients\NzbVortex\NzbVortexNotLoggedInException.cs" /> <Compile Include="Download\Clients\NzbVortex\NzbVortexNotLoggedInException.cs" />
<Compile Include="Download\Clients\NzbVortex\NzbVortexAuthenticationException.cs" /> <Compile Include="Download\Clients\NzbVortex\NzbVortexAuthenticationException.cs" />
@@ -508,7 +508,7 @@
<Compile Include="Download\DownloadClientItem.cs" /> <Compile Include="Download\DownloadClientItem.cs" />
<Compile Include="Download\DownloadClientProvider.cs" /> <Compile Include="Download\DownloadClientProvider.cs" />
<Compile Include="Download\DownloadClientRepository.cs" /> <Compile Include="Download\DownloadClientRepository.cs" />
<Compile Include="Download\DownloadClientStatus.cs" /> <Compile Include="Download\DownloadClientInfo.cs" />
<Compile Include="Download\DownloadClientType.cs" /> <Compile Include="Download\DownloadClientType.cs" />
<Compile Include="Download\DownloadFailedEvent.cs" /> <Compile Include="Download\DownloadFailedEvent.cs" />
<Compile Include="Download\DownloadItemStatus.cs" /> <Compile Include="Download\DownloadItemStatus.cs" />
@@ -628,6 +628,7 @@
<Compile Include="Indexers\HDBits\HDBitsSettings.cs" /> <Compile Include="Indexers\HDBits\HDBitsSettings.cs" />
<Compile Include="Indexers\IIndexer.cs" /> <Compile Include="Indexers\IIndexer.cs" />
<Compile Include="Indexers\IIndexerRequestGenerator.cs" /> <Compile Include="Indexers\IIndexerRequestGenerator.cs" />
<Compile Include="Indexers\IIndexerSettings.cs" />
<Compile Include="Indexers\IndexerBase.cs" /> <Compile Include="Indexers\IndexerBase.cs" />
<Compile Include="Indexers\IndexerDefinition.cs" /> <Compile Include="Indexers\IndexerDefinition.cs" />
<Compile Include="Indexers\IndexerFactory.cs" /> <Compile Include="Indexers\IndexerFactory.cs" />
@@ -1062,6 +1063,11 @@
<Compile Include="SeriesStats\SeriesStatistics.cs" /> <Compile Include="SeriesStats\SeriesStatistics.cs" />
<Compile Include="SeriesStats\SeriesStatisticsRepository.cs" /> <Compile Include="SeriesStats\SeriesStatisticsRepository.cs" />
<Compile Include="SeriesStats\SeriesStatisticsService.cs" /> <Compile Include="SeriesStats\SeriesStatisticsService.cs" />
<Compile Include="SkyhookNotifications\SkyhookNotification.cs" />
<Compile Include="SkyhookNotifications\SkyhookNotificationService.cs" />
<Compile Include="SkyhookNotifications\SkyhookNotificationType.cs" />
<Compile Include="SkyhookNotifications\SkyhookNotificationProxy.cs" />
<Compile Include="SkyhookNotifications\SubstituteUrlService.cs" />
<Compile Include="Tags\Tag.cs" /> <Compile Include="Tags\Tag.cs" />
<Compile Include="Tags\TagRepository.cs" /> <Compile Include="Tags\TagRepository.cs" />
<Compile Include="Tags\TagService.cs" /> <Compile Include="Tags\TagService.cs" />
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.SkyhookNotifications
{
public class SkyhookNotification
{
public int Id { get; set; }
public string MinimumVersion { get; set; }
public string MaximumVersion { get; set; }
public SkyhookNotificationType Type { get; set; }
public string Title { get; set; }
public string Message { get; set; }
public string RegexMatch { get; set; }
public string RegexReplace { get; set; }
}
}
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
using NzbDrone.Common.Cloud;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Http;
namespace NzbDrone.Core.SkyhookNotifications
{
public interface ISkyhookNotificationProxy
{
List<SkyhookNotification> GetNotifications();
}
public class SkyhookNotificationProxy : ISkyhookNotificationProxy
{
private readonly IHttpClient _httpClient;
private readonly IHttpRequestBuilderFactory _requestBuilder;
private readonly Logger _logger;
public SkyhookNotificationProxy(IHttpClient httpClient, ISonarrCloudRequestBuilder requestBuilder, Logger logger)
{
_httpClient = httpClient;
_requestBuilder = requestBuilder.Services;
_logger = logger;
}
public List<SkyhookNotification> GetNotifications()
{
return new List<SkyhookNotification>
{
new SkyhookNotification
{
Type = SkyhookNotificationType.UrlBlacklist,
Title = "Nyaa Indexer shut down",
Message = "Official news is that Nyaa shut down and the domain will expire in a few months, therefore the indexer is forcibly disabled in Sonarr. If a substitute comes available you can update the url in the indexer settings.",
RegexMatch = @"://www\.nyaa\.se(/|$)"
}
};
/*
var notificationsRequest = _requestBuilder.Create()
.Resource("/notifications")
.AddQueryParam("version", BuildInfo.Version)
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
.Build();
try
{
var response = _httpClient.Get<List<SkyhookNotification>>(notificationsRequest);
return response.Resource;
}
catch (Exception ex)
{
_logger.Warn(ex, "Failed to get information update from {0}", notificationsRequest.Url.Host);
return new List<SkyhookNotification>();
}*/
}
}
}
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.EnvironmentInfo;
namespace NzbDrone.Core.SkyhookNotifications
{
public interface ISkyhookNotificationService
{
List<SkyhookNotification> GetUserNotifications();
List<SkyhookNotification> GetUrlNotifications();
}
public class SkyhookNotificationService : ISkyhookNotificationService
{
private readonly ISkyhookNotificationProxy _proxy;
private readonly Logger _logger;
private readonly ICached<List<SkyhookNotification>> _cache;
private readonly TimeSpan CacheExpiry = TimeSpan.FromHours(12);
public SkyhookNotificationService(ISkyhookNotificationProxy proxy, ICacheManager cacheManager, Logger logger)
{
_proxy = proxy;
_logger = logger;
_cache = cacheManager.GetCache<List<SkyhookNotification>>(GetType());
}
private List<SkyhookNotification> GetNotifications(string key)
{
var result = _cache.Find(key);
if (result == null)
{
var all = _proxy.GetNotifications().Where(FilterVersion).ToList();
var user = all.Where(v => v.Type == SkyhookNotificationType.Notification).ToList();
var url = all.Where(v => v.Type == SkyhookNotificationType.UrlBlacklist || v.Type == SkyhookNotificationType.UrlReplace).ToList();
_cache.Set("all", all, CacheExpiry);
_cache.Set("user", user, CacheExpiry);
_cache.Set("url", url, CacheExpiry);
}
return _cache.Find(key);
}
public List<SkyhookNotification> GetUserNotifications()
{
return GetNotifications("user");
}
public List<SkyhookNotification> GetUrlNotifications()
{
return GetNotifications("url");
}
private bool FilterVersion(SkyhookNotification notification)
{
if (notification.MinimumVersion != null && BuildInfo.Version < Version.Parse(notification.MinimumVersion))
{
return false;
}
if (notification.MaximumVersion != null && BuildInfo.Version > Version.Parse(notification.MaximumVersion))
{
return false;
}
return true;
}
}
}
@@ -0,0 +1,17 @@
using System;
using System.Linq;
namespace NzbDrone.Core.SkyhookNotifications
{
public enum SkyhookNotificationType
{
// Notification for the user alone.
Notification = 1,
// Indexer urls matching the RegexMatch are automatically set to temporarily disabled and never contacted.
UrlBlacklist = 2,
// Indexer urls matching the RegexMatch are replaced with RegexReplace.
UrlReplace = 3
}
}
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace NzbDrone.Core.SkyhookNotifications
{
public interface ISubstituteIndexerUrl
{
string SubstituteUrl(string baseUrl);
}
public class SubstituteUrlService : ISubstituteIndexerUrl
{
private readonly ISkyhookNotificationService _notificationService;
public SubstituteUrlService(ISkyhookNotificationService notificationService)
{
_notificationService = notificationService;
}
public string SubstituteUrl(string baseUrl)
{
foreach (var action in _notificationService.GetUrlNotifications())
{
if (action.Type == SkyhookNotificationType.UrlBlacklist)
{
if (action.RegexMatch == null) continue;
if (Regex.IsMatch(baseUrl, action.RegexMatch))
{
return null;
}
}
else if (action.Type == SkyhookNotificationType.UrlReplace)
{
if (action.RegexMatch == null) continue;
if (action.RegexReplace == null) continue;
if (Regex.IsMatch(baseUrl, action.RegexMatch))
{
return Regex.Replace(baseUrl, action.RegexMatch, action.RegexReplace);
}
}
}
return baseUrl;
}
}
}