Replaced Url with BaseUrl in most indexers.

Taloth Saldono 8 years ago
parent 2dbf095fd5
commit 7b0e40d5d0

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

@ -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,7 +49,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
var setting = new NewznabSettings() var setting = new NewznabSettings()
{ {
ApiKey = "", ApiKey = "",
Url = url BaseUrl = url
}; };

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

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

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

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

@ -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()
{ {

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

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

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

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

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

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

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

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

Loading…
Cancel
Save