1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 15:32:31 +01:00

Replaced Url with BaseUrl in most indexers.

This commit is contained in:
Taloth Saldono 2017-05-06 21:50:33 +02:00
parent 2dbf095fd5
commit 7b0e40d5d0
29 changed files with 139 additions and 60 deletions

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

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

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

@ -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,7 @@
<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\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" />
@ -628,6 +629,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" />