1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-03-05 13:20:20 -05: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

View File

@@ -44,7 +44,7 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests
{
Mocker.GetMock<IIndexerStatusService>()
.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();

View File

@@ -40,7 +40,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
{
_blockedIndexers.Add(new IndexerStatus
{
IndexerId = id,
ProviderId = id,
InitialFailure = DateTime.UtcNow.AddHours(-failureHours),
MostRecentFailure = DateTime.UtcNow.AddHours(-0.1),
EscalationLevel = 5,

View File

@@ -28,7 +28,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
public void should_delete_orphaned_indexerstatus()
{
var status = Builder<IndexerStatus>.CreateNew()
.With(h => h.IndexerId = _indexer.Id)
.With(h => h.ProviderId = _indexer.Id)
.BuildNew();
Db.Insert(status);
@@ -42,13 +42,13 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
GivenIndexer();
var status = Builder<IndexerStatus>.CreateNew()
.With(h => h.IndexerId = _indexer.Id)
.With(h => h.ProviderId = _indexer.Id)
.BuildNew();
Db.Insert(status);
Subject.Clean();
AllStoredModels.Should().HaveCount(1);
AllStoredModels.Should().Contain(h => h.IndexerId == _indexer.Id);
AllStoredModels.Should().Contain(h => h.ProviderId == _indexer.Id);
}
}
}

View File

@@ -20,7 +20,7 @@ namespace NzbDrone.Core.Test.IndexerTests.IPTorrentsTests
Subject.Definition = new IndexerDefinition()
{
Name = "IPTorrents",
Settings = new IPTorrentsSettings() { Url = "http://fake.com/" }
Settings = new IPTorrentsSettings() { BaseUrl = "http://fake.com/" }
};
}

View File

@@ -21,7 +21,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
{
_settings = new NewznabSettings()
{
Url = "http://indxer.local"
BaseUrl = "http://indxer.local"
};
_caps = ReadAllText("Files/Indexers/Newznab/newznab_caps.xml");

View File

@@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
Name = "Newznab",
Settings = new NewznabSettings()
{
Url = "http://indexer.local/",
BaseUrl = "http://indexer.local/",
Categories = new int[] { 1 }
}
};

View File

@@ -20,10 +20,10 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
{
Subject.Settings = new NewznabSettings()
{
Url = "http://127.0.0.1:1234/",
Categories = new [] { 1, 2 },
AnimeCategories = new [] { 3, 4 },
ApiKey = "abcd",
BaseUrl = "http://127.0.0.1:1234/",
Categories = new [] { 1, 2 },
AnimeCategories = new [] { 3, 4 },
ApiKey = "abcd",
};
_singleEpisodeSearchCriteria = new SingleEpisodeSearchCriteria
@@ -84,7 +84,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
page.Url.FullUri.Should().Contain("&cat=3,4&");
}
[Test]
public void should_use_mode_search_for_anime()
{

View File

@@ -15,12 +15,12 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
var setting = new NewznabSettings()
{
ApiKey = "",
Url = url
BaseUrl = url
};
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
{
ApiKey = "",
Url = url
BaseUrl = url
};
setting.Validate().IsValid.Should().BeFalse();
setting.Validate().Errors.Should().NotContain(c => c.PropertyName == "ApiKey");
setting.Validate().Errors.Should().Contain(c => c.PropertyName == "Url");
setting.Validate().Errors.Should().NotContain(c => c.PropertyName == nameof(NewznabSettings.ApiKey));
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()
{
ApiKey = "",
Url = url
BaseUrl = url
};
setting.Validate().IsValid.Should().BeTrue();
}
}
}
}

View File

@@ -1,14 +1,17 @@
using System;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Test.IndexerTests
{
public class TestIndexerSettings : IProviderConfig
public class TestIndexerSettings : IIndexerSettings
{
public NzbDroneValidationResult Validate()
{
throw new NotImplementedException();
}
public string BaseUrl { get; set; }
}
}

View File

@@ -25,7 +25,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorznabTests
Name = "Torznab",
Settings = new TorznabSettings()
{
Url = "http://indexer.local/",
BaseUrl = "http://indexer.local/",
Categories = new int[] { 1 }
}
};
@@ -44,7 +44,7 @@ namespace NzbDrone.Core.Test.IndexerTests.TorznabTests
Mocker.GetMock<IHttpClient>()
.Setup(o => o.Execute(It.Is<HttpRequest>(v => v.Method == HttpMethod.GET)))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), recentFeed));
var releases = Subject.FetchRecent();
releases.Should().HaveCount(5);

View File

@@ -366,6 +366,7 @@
<Compile Include="Qualities\QualityModelComparerFixture.cs" />
<Compile Include="RootFolderTests\RootFolderServiceFixture.cs" />
<Compile Include="SeriesStatsTests\SeriesStatisticsFixture.cs" />
<Compile Include="SkyhookNotifications\SkyhookNotificationServiceFixture.cs" />
<Compile Include="ThingiProvider\ProviderBaseFixture.cs" />
<Compile Include="ThingiProviderTests\NullConfigFixture.cs" />
<Compile Include="TvTests\EpisodeServiceTests\FindEpisodeByTitleFixture.cs" />

View File

@@ -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());
}
}
}

View File

@@ -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();
}
}
}
}
}
}
}
}
}

View File

@@ -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");
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using FluentMigrator;
@@ -7,6 +8,7 @@ using FluentMigrator.Model;
using FluentMigrator.Runner;
using FluentMigrator.Runner.Generators.SQLite;
using FluentMigrator.Runner.Processors.SQLite;
using System.Text.RegularExpressions;
namespace NzbDrone.Core.Datastore.Migration.Framework
{
@@ -62,6 +64,46 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
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)
{
var schemaDumper = new SqliteSchemaDumper(this, Announcer);
@@ -70,7 +112,7 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
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 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?
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(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 });

View File

@@ -119,9 +119,9 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
DeleteItemData(downloadId);
}
public override DownloadClientStatus GetStatus()
public override DownloadClientInfo GetStatus()
{
return new DownloadClientStatus
return new DownloadClientInfo
{
IsLocalhost = true,
OutputRootFolders = new List<OsPath> { new OsPath(Settings.WatchFolder) }

View File

@@ -86,9 +86,9 @@ namespace NzbDrone.Core.Download.Clients.Blackhole
DeleteItemData(downloadId);
}
public override DownloadClientStatus GetStatus()
public override DownloadClientInfo GetStatus()
{
return new DownloadClientStatus
return new DownloadClientInfo
{
IsLocalhost = true,
OutputRootFolders = new List<OsPath> { new OsPath(Settings.WatchFolder) }

View File

@@ -151,7 +151,7 @@ namespace NzbDrone.Core.Download.Clients.Deluge
_proxy.RemoveTorrent(downloadId.ToLower(), deleteData, Settings);
}
public override DownloadClientStatus GetStatus()
public override DownloadClientInfo GetStatus()
{
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);
}
var status = new DownloadClientStatus
var status = new DownloadClientInfo
{
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost"
};

View File

@@ -105,13 +105,13 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
return items;
}
public override DownloadClientStatus GetStatus()
public override DownloadClientInfo GetStatus()
{
try
{
var path = GetDownloadDirectory();
return new DownloadClientStatus
return new DownloadClientInfo
{
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost",
OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(path)) }

View File

@@ -130,13 +130,13 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
return finalPath;
}
public override DownloadClientStatus GetStatus()
public override DownloadClientInfo GetStatus()
{
try
{
var path = GetDownloadDirectory();
return new DownloadClientStatus
return new DownloadClientInfo
{
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost",
OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(path)) }

View File

@@ -117,12 +117,12 @@ namespace NzbDrone.Core.Download.Clients.Hadouken
}
}
public override DownloadClientStatus GetStatus()
public override DownloadClientInfo GetStatus()
{
var config = _proxy.GetConfig(Settings);
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"
};

View File

@@ -142,9 +142,9 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex
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"
};

View File

@@ -214,13 +214,13 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
_proxy.RemoveItem(downloadId, Settings);
}
public override DownloadClientStatus GetStatus()
public override DownloadClientInfo GetStatus()
{
var config = _proxy.GetConfig(Settings);
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"
};

View File

@@ -103,9 +103,9 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic
throw new NotSupportedException();
}
public override DownloadClientStatus GetStatus()
public override DownloadClientInfo GetStatus()
{
var status = new DownloadClientStatus
var status = new DownloadClientInfo
{
IsLocalhost = true
};

View File

@@ -174,13 +174,13 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
_proxy.RemoveTorrent(hash.ToLower(), deleteData, Settings);
}
public override DownloadClientStatus GetStatus()
public override DownloadClientInfo GetStatus()
{
var config = _proxy.GetConfig(Settings);
var destDir = new OsPath(config.SavePath);
return new DownloadClientStatus
return new DownloadClientInfo
{
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost",
OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, destDir) }

View File

@@ -250,7 +250,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
}
}
public override DownloadClientStatus GetStatus()
public override DownloadClientInfo GetStatus()
{
var config = _proxy.GetConfig(Settings);
var categories = GetCategories(config).ToArray();
@@ -262,7 +262,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
category = categories.FirstOrDefault(v => v.Name == "*");
}
var status = new DownloadClientStatus
var status = new DownloadClientInfo
{
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost"
};

View File

@@ -119,7 +119,7 @@ namespace NzbDrone.Core.Download.Clients.Transmission
_proxy.RemoveTorrent(downloadId.ToLower(), deleteData, Settings);
}
public override DownloadClientStatus GetStatus()
public override DownloadClientInfo GetStatus()
{
var config = _proxy.GetConfig(Settings);
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);
}
return new DownloadClientStatus
return new DownloadClientInfo
{
IsLocalhost = Settings.Host == "127.0.0.1" || Settings.Host == "localhost",
OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Host, new OsPath(destDir)) }

View File

@@ -156,11 +156,11 @@ namespace NzbDrone.Core.Download.Clients.RTorrent
_proxy.RemoveTorrent(downloadId, Settings);
}
public override DownloadClientStatus GetStatus()
public override DownloadClientInfo GetStatus()
{
// 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"
};

View File

@@ -178,7 +178,7 @@ namespace NzbDrone.Core.Download.Clients.UTorrent
_proxy.RemoveTorrent(downloadId, deleteData, Settings);
}
public override DownloadClientStatus GetStatus()
public override DownloadClientInfo GetStatus()
{
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"
};

View File

@@ -60,7 +60,7 @@ namespace NzbDrone.Core.Download
public abstract string Download(RemoteEpisode remoteEpisode);
public abstract IEnumerable<DownloadClientItem> GetItems();
public abstract void RemoveItem(string downloadId, bool deleteData);
public abstract DownloadClientStatus GetStatus();
public abstract DownloadClientInfo GetStatus();
protected virtual void DeleteItemData(string downloadId)
{

View File

@@ -3,7 +3,7 @@ using NzbDrone.Common.Disk;
namespace NzbDrone.Core.Download
{
public class DownloadClientStatus
public class DownloadClientInfo
{
public bool IsLocalhost { get; set; }
public List<OsPath> OutputRootFolders { get; set; }

View File

@@ -12,6 +12,6 @@ namespace NzbDrone.Core.Download
string Download(RemoteEpisode remoteEpisode);
IEnumerable<DownloadClientItem> GetItems();
void RemoveItem(string downloadId, bool deleteData);
DownloadClientStatus GetStatus();
DownloadClientInfo GetStatus();
}
}

View File

@@ -101,7 +101,7 @@ namespace NzbDrone.Core.Download.Pending
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();
}

View File

@@ -91,6 +91,6 @@ namespace NzbDrone.Core.HealthCheck.Checks
public class ImportMechanismCheckStatus
{
public IDownloadClient DownloadClient { get; set; }
public DownloadClientStatus Status { get; set; }
public DownloadClientInfo Status { get; set; }
}
}

View File

@@ -21,7 +21,7 @@ namespace NzbDrone.Core.HealthCheck.Checks
var enabledIndexers = _indexerFactory.GetAvailableProviders();
var backOffIndexers = enabledIndexers.Join(_indexerStatusService.GetBlockedIndexers(),
i => i.Definition.Id,
s => s.IndexerId,
s => s.ProviderId,
(i, s) => new { Indexer = i, Status = s })
.Where(v => (v.Status.MostRecentFailure - v.Status.InitialFailure) > TimeSpan.FromHours(1))
.ToList();

View File

@@ -19,7 +19,7 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
WHERE Id IN (
SELECT IndexerStatus.Id FROM IndexerStatus
LEFT OUTER JOIN Indexers
ON IndexerStatus.IndexerId = Indexers.Id
ON IndexerStatus.ProviderId = Indexers.Id
WHERE Indexers.Id IS NULL)");
}
}

View File

@@ -23,7 +23,7 @@ namespace NzbDrone.Core.Indexers.BitMeTv
}
}
public class BitMeTvSettings : IProviderConfig
public class BitMeTvSettings : IIndexerSettings
{
private static readonly BitMeTvSettingsValidator Validator = new BitMeTvSettingsValidator();
@@ -49,4 +49,4 @@ namespace NzbDrone.Core.Indexers.BitMeTv
return new NzbDroneValidationResult(Validator.Validate(this));
}
}
}
}

View File

@@ -14,7 +14,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet
}
}
public class BroadcastheNetSettings : IProviderConfig
public class BroadcastheNetSettings : IIndexerSettings
{
private static readonly BroadcastheNetSettingsValidator Validator = new BroadcastheNetSettingsValidator();

View File

@@ -13,7 +13,7 @@ namespace NzbDrone.Core.Indexers.Fanzub
}
}
public class FanzubSettings : IProviderConfig
public class FanzubSettings : IIndexerSettings
{
private static readonly FanzubSettingsValidator Validator = new FanzubSettingsValidator();

View File

@@ -14,7 +14,7 @@ namespace NzbDrone.Core.Indexers.HDBits
}
}
public class HDBitsSettings : IProviderConfig
public class HDBitsSettings : IIndexerSettings
{
private static readonly HDBitsSettingsValidator Validator = new HDBitsSettingsValidator();

View File

@@ -17,7 +17,7 @@ using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers
{
public abstract class HttpIndexerBase<TSettings> : IndexerBase<TSettings>
where TSettings : IProviderConfig, new()
where TSettings : IIndexerSettings, new()
{
protected const int MaxNumResultsPerQuery = 1000;

View File

@@ -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; }
}
}

View File

@@ -7,7 +7,7 @@ namespace NzbDrone.Core.Indexers.IPTorrents
public class IPTorrentsRequestGenerator : IIndexerRequestGenerator
{
public IPTorrentsSettings Settings { get; set; }
public virtual IndexerPageableRequestChain GetRecentRequests()
{
var pageableRequests = new IndexerPageableRequestChain();
@@ -44,7 +44,7 @@ namespace NzbDrone.Core.Indexers.IPTorrents
private IEnumerable<IndexerRequest> GetRssRequests()
{
yield return new IndexerRequest(Settings.Url, HttpAccept.Rss);
yield return new IndexerRequest(Settings.BaseUrl, HttpAccept.Rss);
}
}
}

View File

@@ -11,17 +11,17 @@ namespace NzbDrone.Core.Indexers.IPTorrents
{
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)")
.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();
@@ -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 ...)")]
public string Url { get; set; }
public string BaseUrl { get; set; }
public NzbDroneValidationResult Validate()
{

View File

@@ -13,7 +13,7 @@ using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers
{
public abstract class IndexerBase<TSettings> : IIndexer
where TSettings : IProviderConfig, new()
where TSettings : IIndexerSettings, new()
{
protected readonly IIndexerStatusService _indexerStatusService;
protected readonly IConfigService _configService;

View File

@@ -2,7 +2,9 @@
using System.Linq;
using NLog;
using NzbDrone.Common.Composition;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.SkyhookNotifications;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers
@@ -15,17 +17,20 @@ namespace NzbDrone.Core.Indexers
public class IndexerFactory : ProviderFactory<IIndexer, IndexerDefinition>, IIndexerFactory
{
private readonly ISubstituteIndexerUrl _substituteIndexerUrl;
private readonly IIndexerStatusService _indexerStatusService;
private readonly Logger _logger;
public IndexerFactory(IIndexerStatusService indexerStatusService,
public IndexerFactory(ISubstituteIndexerUrl replaceIndexerUrl,
IIndexerStatusService indexerStatusService,
IIndexerRepository providerRepository,
IEnumerable<IIndexer> providers,
IContainer container,
IContainer container,
IEventAggregator eventAggregator,
Logger logger)
: base(providerRepository, providers, container, eventAggregator, logger)
{
_substituteIndexerUrl = replaceIndexerUrl;
_indexerStatusService = indexerStatusService;
_logger = logger;
}
@@ -50,7 +55,7 @@ namespace NzbDrone.Core.Indexers
if (filterBlockedIndexers)
{
return FilterBlockedIndexers(enabledIndexers).ToList();
return FilterBlockedIndexers(SubstituteIndexerUrls(enabledIndexers)).ToList();
}
return enabledIndexers.ToList();
@@ -62,15 +67,34 @@ namespace NzbDrone.Core.Indexers
if (filterBlockedIndexers)
{
return FilterBlockedIndexers(enabledIndexers).ToList();
return FilterBlockedIndexers(SubstituteIndexerUrls(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)
{
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)
{
@@ -85,4 +109,4 @@ namespace NzbDrone.Core.Indexers
}
}
}
}
}

View File

@@ -6,7 +6,7 @@ namespace NzbDrone.Core.Indexers
{
public class IndexerStatus : ModelBase
{
public int IndexerId { get; set; }
public int ProviderId { get; set; }
public DateTime? InitialFailure { get; set; }
public DateTime? MostRecentFailure { get; set; }

View File

@@ -20,7 +20,7 @@ namespace NzbDrone.Core.Indexers
public IndexerStatus FindByIndexerId(int indexerId)
{
return Query.Where(c => c.IndexerId == indexerId).SingleOrDefault();
return Query.Where(c => c.ProviderId == indexerId).SingleOrDefault();
}
}
}

View File

@@ -57,7 +57,7 @@ namespace NzbDrone.Core.Indexers
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)

View File

@@ -78,7 +78,7 @@ namespace NzbDrone.Core.Indexers.Newznab
private NewznabSettings GetSettings(string url, params int[] categories)
{
var settings = new NewznabSettings { Url = url };
var settings = new NewznabSettings { BaseUrl = url };
if (categories.Any())
{

View File

@@ -41,7 +41,7 @@ namespace NzbDrone.Core.Indexers.Newznab
{
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())
{
@@ -58,7 +58,7 @@ namespace NzbDrone.Core.Indexers.Newznab
}
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;
}
@@ -68,14 +68,14 @@ namespace NzbDrone.Core.Indexers.Newznab
}
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);
throw;
}
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;

View File

@@ -249,7 +249,7 @@ namespace NzbDrone.Core.Indexers.Newznab
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())
{

View File

@@ -25,12 +25,12 @@ namespace NzbDrone.Core.Indexers.Newznab
private static bool ShouldHaveApiKey(NewznabSettings settings)
{
if (settings.Url == null)
if (settings.BaseUrl == null)
{
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);
@@ -47,14 +47,14 @@ namespace NzbDrone.Core.Indexers.Newznab
return null;
});
RuleFor(c => c.Url).ValidRootUrl();
RuleFor(c => c.BaseUrl).ValidRootUrl();
RuleFor(c => c.ApiKey).NotEmpty().When(ShouldHaveApiKey);
RuleFor(c => c.AdditionalParameters).Matches(AdditionalParametersRegex)
.When(c => !c.AdditionalParameters.IsNullOrWhiteSpace());
}
}
public class NewznabSettings : IProviderConfig
public class NewznabSettings : IIndexerSettings
{
private static readonly NewznabSettingsValidator Validator = new NewznabSettingsValidator();
@@ -65,7 +65,7 @@ namespace NzbDrone.Core.Indexers.Newznab
}
[FieldDefinition(0, Label = "URL")]
public string Url { get; set; }
public string BaseUrl { get; set; }
[FieldDefinition(1, Label = "API Key")]
public string ApiKey { get; set; }
@@ -84,4 +84,4 @@ namespace NzbDrone.Core.Indexers.Newznab
return new NzbDroneValidationResult(Validator.Validate(this));
}
}
}
}

View File

@@ -14,7 +14,7 @@ namespace NzbDrone.Core.Indexers.Nyaa
}
}
public class NyaaSettings : IProviderConfig
public class NyaaSettings : IIndexerSettings
{
private static readonly NyaaSettingsValidator Validator = new NyaaSettingsValidator();
@@ -35,4 +35,4 @@ namespace NzbDrone.Core.Indexers.Nyaa
return new NzbDroneValidationResult(Validator.Validate(this));
}
}
}
}

View File

@@ -15,7 +15,7 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
}
}
public class OmgwtfnzbsSettings : IProviderConfig
public class OmgwtfnzbsSettings : IIndexerSettings
{
private static readonly OmgwtfnzbsSettingsValidator Validator = new OmgwtfnzbsSettingsValidator();
@@ -24,6 +24,9 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
Delay = 30;
}
// Unused since Omg has a hardcoded url.
public string BaseUrl { get; set; }
[FieldDefinition(0, Label = "Username")]
public string Username { get; set; }

View File

@@ -13,7 +13,7 @@ namespace NzbDrone.Core.Indexers.Rarbg
}
}
public class RarbgSettings : IProviderConfig
public class RarbgSettings : IIndexerSettings
{
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.")]
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.")]
public string CaptchaToken { get; set; }
@@ -37,4 +37,4 @@ namespace NzbDrone.Core.Indexers.Rarbg
return new NzbDroneValidationResult(Validator.Validate(this));
}
}
}
}

View File

@@ -13,7 +13,7 @@ namespace NzbDrone.Core.Indexers.TorrentRss
}
}
public class TorrentRssIndexerSettings : IProviderConfig
public class TorrentRssIndexerSettings : IIndexerSettings
{
private static readonly TorrentRssIndexerSettingsValidator validator = new TorrentRssIndexerSettingsValidator();
@@ -37,4 +37,4 @@ namespace NzbDrone.Core.Indexers.TorrentRss
return new NzbDroneValidationResult(validator.Validate(this));
}
}
}
}

View File

@@ -14,7 +14,7 @@ namespace NzbDrone.Core.Indexers.Torrentleech
}
}
public class TorrentleechSettings : IProviderConfig
public class TorrentleechSettings : IIndexerSettings
{
private static readonly TorrentleechSettingsValidator Validator = new TorrentleechSettingsValidator();
@@ -34,4 +34,4 @@ namespace NzbDrone.Core.Indexers.Torrentleech
return new NzbDroneValidationResult(Validator.Validate(this));
}
}
}
}

View File

@@ -66,7 +66,7 @@ namespace NzbDrone.Core.Indexers.Torznab
private TorznabSettings GetSettings(string url, params int[] categories)
{
var settings = new TorznabSettings { Url = url };
var settings = new TorznabSettings { BaseUrl = url };
if (categories.Any())
{

View File

@@ -17,12 +17,12 @@ namespace NzbDrone.Core.Indexers.Torznab
private static bool ShouldHaveApiKey(TorznabSettings settings)
{
if (settings.Url == null)
if (settings.BaseUrl == null)
{
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);
@@ -39,7 +39,7 @@ namespace NzbDrone.Core.Indexers.Torznab
return null;
});
RuleFor(c => c.Url).ValidRootUrl();
RuleFor(c => c.BaseUrl).ValidRootUrl();
RuleFor(c => c.ApiKey).NotEmpty().When(ShouldHaveApiKey);
RuleFor(c => c.AdditionalParameters).Matches(AdditionalParametersRegex)
.When(c => !c.AdditionalParameters.IsNullOrWhiteSpace());
@@ -55,4 +55,4 @@ namespace NzbDrone.Core.Indexers.Torznab
return new NzbDroneValidationResult(Validator.Validate(this));
}
}
}
}

View File

@@ -250,6 +250,8 @@
<Compile Include="Datastore\Migration\069_quality_proper.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\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\110_fix_extra_files_config.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\NzbVortex\JsonConverters\NzbVortexLoginResultTypeConverter.cs" />
<Compile Include="Download\Clients\NzbVortex\JsonConverters\NzbVortexResultTypeConverter.cs" />
<Compile Include="Download\Clients\NzbVortex\NzbVortex.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Download\Clients\NzbVortex\NzbVortex.cs" />
<Compile Include="Download\Clients\NzbVortex\NzbVortexGroup.cs" />
<Compile Include="Download\Clients\NzbVortex\NzbVortexNotLoggedInException.cs" />
<Compile Include="Download\Clients\NzbVortex\NzbVortexAuthenticationException.cs" />
@@ -508,7 +508,7 @@
<Compile Include="Download\DownloadClientItem.cs" />
<Compile Include="Download\DownloadClientProvider.cs" />
<Compile Include="Download\DownloadClientRepository.cs" />
<Compile Include="Download\DownloadClientStatus.cs" />
<Compile Include="Download\DownloadClientInfo.cs" />
<Compile Include="Download\DownloadClientType.cs" />
<Compile Include="Download\DownloadFailedEvent.cs" />
<Compile Include="Download\DownloadItemStatus.cs" />
@@ -628,6 +628,7 @@
<Compile Include="Indexers\HDBits\HDBitsSettings.cs" />
<Compile Include="Indexers\IIndexer.cs" />
<Compile Include="Indexers\IIndexerRequestGenerator.cs" />
<Compile Include="Indexers\IIndexerSettings.cs" />
<Compile Include="Indexers\IndexerBase.cs" />
<Compile Include="Indexers\IndexerDefinition.cs" />
<Compile Include="Indexers\IndexerFactory.cs" />
@@ -1062,6 +1063,11 @@
<Compile Include="SeriesStats\SeriesStatistics.cs" />
<Compile Include="SeriesStats\SeriesStatisticsRepository.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\TagRepository.cs" />
<Compile Include="Tags\TagService.cs" />

View File

@@ -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; }
}
}

View File

@@ -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>();
}*/
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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
}
}

View File

@@ -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;
}
}
}