Fixed: Lidarr Lists use correct metadata server (#800)

pull/808/head
Qstick 6 years ago committed by GitHub
parent 35c19dac5f
commit add32ff9f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,51 @@
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Configuration;
using NzbDrone.Common.Cloud;
using NzbDrone.Common.Http;
namespace NzbDrone.Core.Test.MetadataSource
{
[TestFixture]
public class MetadataRequestBuilderFixture : CoreTest<MetadataRequestBuilder>
{
[SetUp]
public void Setup()
{
Mocker.GetMock<IConfigService>()
.Setup(s => s.MetadataSource)
.Returns("");
Mocker.GetMock<ILidarrCloudRequestBuilder>()
.Setup(s => s.Search)
.Returns(new HttpRequestBuilder("https://api.lidarr.audio/api/v0.4/{route}").CreateFactory());
}
private void WithCustomProvider()
{
Mocker.GetMock<IConfigService>()
.Setup(s => s.MetadataSource)
.Returns("http://api.lidarr.audio/api/testing/");
}
[TestCase]
public void should_use_user_definied_if_not_blank()
{
WithCustomProvider();
var details = Subject.GetRequestBuilder().Create();
details.BaseUrl.ToString().Should().Contain("testing");
}
[TestCase]
public void should_use_default_if_config_blank()
{
var details = Subject.GetRequestBuilder().Create();
details.BaseUrl.ToString().Should().Contain("v0.4");
}
}
}

@ -311,6 +311,7 @@
<Compile Include="MediaFiles\ImportApprovedTracksFixture.cs" />
<Compile Include="MediaFiles\MediaFileRepositoryFixture.cs" />
<Compile Include="Messaging\Commands\CommandQueueManagerFixture.cs" />
<Compile Include="MetadataSource\MetadataRequestBuilderFixture.cs" />
<Compile Include="MetadataSource\SkyHook\SkyHookProxySearchFixture.cs" />
<Compile Include="MetadataSource\SearchArtistComparerFixture.cs" />
<Compile Include="MetadataSource\SkyHook\SkyHookProxyFixture.cs" />

@ -4,6 +4,7 @@ using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Parser;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.MetadataSource;
namespace NzbDrone.Core.ImportLists.LidarrLists
{
@ -13,10 +14,12 @@ namespace NzbDrone.Core.ImportLists.LidarrLists
public override int PageSize => 10;
public LidarrLists(IHttpClient httpClient, IImportListStatusService importListStatusService, IConfigService configService, IParsingService parsingService, Logger logger)
private readonly IMetadataRequestBuilder _requestBuilder;
public LidarrLists(IHttpClient httpClient, IImportListStatusService importListStatusService, IConfigService configService, IParsingService parsingService, IMetadataRequestBuilder requestBuilder, Logger logger)
: base(httpClient, importListStatusService, configService, parsingService, logger)
{
_requestBuilder = requestBuilder;
}
public override IEnumerable<ProviderDefinition> DefaultDefinitions
@ -29,7 +32,6 @@ namespace NzbDrone.Core.ImportLists.LidarrLists
yield return GetDefinition("Apple Music New Albums", GetSettings("apple-music/album/new"));
yield return GetDefinition("Billboard Top Albums", GetSettings("billboard/album/top"));
yield return GetDefinition("Billboard Top Artists", GetSettings("billboard/artist/top"));
yield return GetDefinition("Last.fm Top Albums", GetSettings("lastfm/album/top"));
yield return GetDefinition("Last.fm Top Artists", GetSettings("lastfm/artist/top"));
}
}
@ -54,7 +56,7 @@ namespace NzbDrone.Core.ImportLists.LidarrLists
public override IImportListRequestGenerator GetRequestGenerator()
{
return new LidarrListsRequestGenerator { Settings = Settings, PageSize = PageSize };
return new LidarrListsRequestGenerator(_requestBuilder) { Settings = Settings };
}
public override IParseImportListResponse GetParser()

@ -1,5 +1,5 @@
using System.Collections.Generic;
using NzbDrone.Common.Http;
using NzbDrone.Core.MetadataSource;
namespace NzbDrone.Core.ImportLists.LidarrLists
{
@ -7,13 +7,11 @@ namespace NzbDrone.Core.ImportLists.LidarrLists
{
public LidarrListsSettings Settings { get; set; }
public int MaxPages { get; set; }
public int PageSize { get; set; }
private readonly IMetadataRequestBuilder _requestBulder;
public LidarrListsRequestGenerator()
public LidarrListsRequestGenerator(IMetadataRequestBuilder requestBuilder)
{
MaxPages = 1;
PageSize = 10;
_requestBulder = requestBuilder;
}
public virtual ImportListPageableRequestChain GetListItems()
@ -27,8 +25,12 @@ namespace NzbDrone.Core.ImportLists.LidarrLists
private IEnumerable<ImportListRequest> GetPagedRequests()
{
yield return new ImportListRequest(string.Format("{0}{1}", Settings.BaseUrl, Settings.ListId), HttpAccept.Json);
}
var request = _requestBulder.GetRequestBuilder()
.Create()
.SetSegment("route", "chart/" + Settings.ListId)
.Build();
yield return new ImportListRequest(request);
}
}
}

@ -8,7 +8,6 @@ namespace NzbDrone.Core.ImportLists.LidarrLists
{
public LidarrListsSettingsValidator()
{
RuleFor(c => c.BaseUrl).ValidRootUrl();
}
}
@ -18,7 +17,7 @@ namespace NzbDrone.Core.ImportLists.LidarrLists
public LidarrListsSettings()
{
BaseUrl = "https://api.lidarr.audio/api/v0.3/chart/";
BaseUrl = "";
}
public string BaseUrl { get; set; }

@ -0,0 +1,37 @@
using NzbDrone.Common.Cloud;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration;
namespace NzbDrone.Core.MetadataSource
{
public interface IMetadataRequestBuilder
{
IHttpRequestBuilderFactory GetRequestBuilder();
}
public class MetadataRequestBuilder : IMetadataRequestBuilder
{
private readonly IConfigService _configService;
private readonly ILidarrCloudRequestBuilder _defaultRequestFactory;
public MetadataRequestBuilder(IConfigService configService, ILidarrCloudRequestBuilder defaultRequestBuilder)
{
_configService = configService;
_defaultRequestFactory = defaultRequestBuilder;
}
public IHttpRequestBuilderFactory GetRequestBuilder()
{
if (_configService.MetadataSource.IsNotNullOrWhiteSpace())
{
return new HttpRequestBuilder(_configService.MetadataSource.TrimEnd("/") + "/{route}").CreateFactory();
}
else
{
return _defaultRequestFactory.Search;
}
}
}
}

@ -21,17 +21,15 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
private readonly Logger _logger;
private readonly IArtistService _artistService;
private readonly IAlbumService _albumService;
private readonly IHttpRequestBuilderFactory _requestBuilder;
private readonly IMetadataRequestBuilder _requestBuilder;
private readonly IConfigService _configService;
private readonly IMetadataProfileService _metadataProfileService;
private static readonly List<string> nonAudioMedia = new List<string> { "DVD", "DVD-Video", "Blu-ray", "HD-DVD", "VCD", "SVCD", "UMD", "VHS" };
private static readonly List<string> skippedTracks = new List<string> { "[data track]" };
private IHttpRequestBuilderFactory _customerRequestBuilder;
public SkyHookProxy(IHttpClient httpClient,
ILidarrCloudRequestBuilder requestBuilder,
IMetadataRequestBuilder requestBuilder,
IArtistService artistService,
IAlbumService albumService,
Logger logger,
@ -41,7 +39,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
_httpClient = httpClient;
_configService = configService;
_metadataProfileService = metadataProfileService;
_requestBuilder = requestBuilder.Search;
_requestBuilder = requestBuilder;
_artistService = artistService;
_albumService = albumService;
_logger = logger;
@ -52,15 +50,13 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
_logger.Debug("Getting Artist with LidarrAPI.MetadataID of {0}", foreignArtistId);
SetCustomProvider();
var metadataProfile = _metadataProfileService.Exists(metadataProfileId) ? _metadataProfileService.Get(metadataProfileId) : _metadataProfileService.All().First();
var primaryTypes = metadataProfile.PrimaryAlbumTypes.Where(s => s.Allowed).Select(s => s.PrimaryAlbumType.Name);
var secondaryTypes = metadataProfile.SecondaryAlbumTypes.Where(s => s.Allowed).Select(s => s.SecondaryAlbumType.Name);
var releaseStatuses = metadataProfile.ReleaseStatuses.Where(s => s.Allowed).Select(s => s.ReleaseStatus.Name);
var httpRequest = _customerRequestBuilder.Create()
var httpRequest = _requestBuilder.GetRequestBuilder().Create()
.SetSegment("route", "artist/" + foreignArtistId)
.AddQueryParam("primTypes", string.Join("|", primaryTypes))
.AddQueryParam("secTypes", string.Join("|", secondaryTypes))
@ -102,9 +98,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
{
_logger.Debug("Getting Album with LidarrAPI.MetadataID of {0}", foreignAlbumId);
SetCustomProvider();
var httpRequest = _customerRequestBuilder.Create()
var httpRequest = _requestBuilder.GetRequestBuilder().Create()
.SetSegment("route", "album/" + foreignAlbumId)
.Build();
@ -173,9 +167,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
}
}
SetCustomProvider();
var httpRequest = _customerRequestBuilder.Create()
var httpRequest = _requestBuilder.GetRequestBuilder().Create()
.SetSegment("route", "search")
.AddQueryParam("type", "artist")
.AddQueryParam("query", title.ToLower().Trim())
@ -244,9 +236,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
}
}
SetCustomProvider();
var httpRequest = _customerRequestBuilder.Create()
var httpRequest = _requestBuilder.GetRequestBuilder().Create()
.SetSegment("route", "search")
.AddQueryParam("type", "album")
.AddQueryParam("query", title.ToLower().Trim())
@ -508,17 +498,5 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
return SecondaryAlbumType.Studio;
}
}
private void SetCustomProvider()
{
if (_configService.MetadataSource.IsNotNullOrWhiteSpace())
{
_customerRequestBuilder = new HttpRequestBuilder(_configService.MetadataSource.TrimEnd("/") + "/{route}").CreateFactory();
}
else
{
_customerRequestBuilder = _requestBuilder;
}
}
}
}

@ -716,6 +716,7 @@
<Compile Include="Languages\Language.cs" />
<Compile Include="Languages\LanguageComparer.cs" />
<Compile Include="Languages\LanguagesBelowCutoff.cs" />
<Compile Include="MetadataSource\IMetadataRequestBuilder.cs" />
<Compile Include="Notifications\Discord\Discord.cs" />
<Compile Include="Notifications\Discord\DiscordColors.cs" />
<Compile Include="Notifications\Discord\DiscordException.cs" />

Loading…
Cancel
Save