From f812302aa5ae827b14af46fbfe98f9b58d27ee53 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 7 Oct 2017 17:37:18 -0400 Subject: [PATCH] More Work on Album Filtering per Artist --- .../AddNewArtist/AddNewArtistModalContent.js | 22 ------------------- .../src/Store/Reducers/addArtistReducers.js | 4 ++-- src/Lidarr.Api.V3/Artist/ArtistResource.cs | 4 ++-- .../SkyHook/SkyHookProxyFixture.cs | 10 +++------ .../MusicTests/AddArtistFixture.cs | 16 +++++++------- .../MusicTests/RefreshArtistServiceFixture.cs | 6 ++--- .../121_update_types_existing_artist.cs | 14 ++++++++++++ .../MetadataSource/IProvideArtistInfo.cs | 4 ++-- .../MetadataSource/SkyHook/SkyHookProxy.cs | 8 +++---- src/NzbDrone.Core/Music/AddArtistService.cs | 2 +- src/NzbDrone.Core/Music/Artist.cs | 4 ++-- .../Music/RefreshArtistService.cs | 2 +- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 13 files changed, 43 insertions(+), 54 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/121_update_types_existing_artist.cs diff --git a/frontend/src/AddArtist/AddNewArtist/AddNewArtistModalContent.js b/frontend/src/AddArtist/AddNewArtist/AddNewArtistModalContent.js index e97824564..4edf965f6 100644 --- a/frontend/src/AddArtist/AddNewArtist/AddNewArtistModalContent.js +++ b/frontend/src/AddArtist/AddNewArtist/AddNewArtistModalContent.js @@ -167,28 +167,6 @@ class AddNewArtistModalContent extends Component { /> - - Primary Album Types - - - - - - Secondary Album Types - - - - Tags diff --git a/frontend/src/Store/Reducers/addArtistReducers.js b/frontend/src/Store/Reducers/addArtistReducers.js index fc1d0aa61..9070b100d 100644 --- a/frontend/src/Store/Reducers/addArtistReducers.js +++ b/frontend/src/Store/Reducers/addArtistReducers.js @@ -23,8 +23,8 @@ export const defaultState = { qualityProfileId: 0, languageProfileId: 0, seriesType: 'standard', - primaryAlbumTypes: 'Studio, Single', - secondaryAlbumTypes: '', + primaryAlbumTypes: ['Album'], + secondaryAlbumTypes: ['Studio'], albumFolder: true, tags: [] } diff --git a/src/Lidarr.Api.V3/Artist/ArtistResource.cs b/src/Lidarr.Api.V3/Artist/ArtistResource.cs index 96e53b7e1..2ac1f42c4 100644 --- a/src/Lidarr.Api.V3/Artist/ArtistResource.cs +++ b/src/Lidarr.Api.V3/Artist/ArtistResource.cs @@ -29,8 +29,8 @@ namespace Lidarr.Api.V3.Artist public string Overview { get; set; } public string ArtistType { get; set; } public string Disambiguation { get; set; } - public string PrimaryAlbumTypes { get; set; } - public string SecondaryAlbumTypes { get; set; } + public List PrimaryAlbumTypes { get; set; } + public List SecondaryAlbumTypes { get; set; } public List Links { get; set; } public int? AlbumCount { get; set; } diff --git a/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxyFixture.cs b/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxyFixture.cs index 67cd315b2..b8b2128ff 100644 --- a/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxyFixture.cs +++ b/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxyFixture.cs @@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook [TestCase("66c662b6-6e2f-4930-8610-912e24c63ed1", "AC/DC")] public void should_be_able_to_get_artist_detail(string mbId, string name) { - var details = Subject.GetArtistInfo(mbId); + var details = Subject.GetArtistInfo(mbId, new List { "Album" }, new List { "Studio" }); ValidateArtist(details.Item1); ValidateAlbums(details.Item2); @@ -37,13 +37,13 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook [Test] public void getting_details_of_invalid_artist() { - Assert.Throws(() => Subject.GetArtistInfo("aaaaaa-aaa-aaaa-aaaa")); + Assert.Throws(() => Subject.GetArtistInfo("aaaaaa-aaa-aaaa-aaaa", new List { "Album" }, new List { "Studio" })); } [Test] public void should_not_have_period_at_start_of_name_slug() { - var details = Subject.GetArtistInfo("f59c5520-5f46-4d2c-b2c4-822eabf53419"); + var details = Subject.GetArtistInfo("b6db95cd-88d9-492f-bbf6-a34e0e89b2e5", new List { "Album" }, new List { "Studio" }); details.Item1.NameSlug.Should().Be("dothack"); } @@ -65,10 +65,6 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook { albums.Should().NotBeEmpty(); - var episodeGroup = albums.GroupBy(e => e.AlbumType + e.Title); - episodeGroup.Should().OnlyContain(c => c.Count() == 1); - - foreach (var episode in albums) { ValidateAlbum(episode); diff --git a/src/NzbDrone.Core.Test/MusicTests/AddArtistFixture.cs b/src/NzbDrone.Core.Test/MusicTests/AddArtistFixture.cs index ac90ed5d0..98edf35ca 100644 --- a/src/NzbDrone.Core.Test/MusicTests/AddArtistFixture.cs +++ b/src/NzbDrone.Core.Test/MusicTests/AddArtistFixture.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using FizzWare.NBuilder; @@ -33,7 +33,7 @@ namespace NzbDrone.Core.Test.MusicTests private void GivenValidArtist(string lidarrId) { Mocker.GetMock() - .Setup(s => s.GetArtistInfo(lidarrId)) + .Setup(s => s.GetArtistInfo(lidarrId, It.IsAny>(), It.IsAny>())) .Returns(new Tuple>(_fakeArtist, new List())); } @@ -53,7 +53,7 @@ namespace NzbDrone.Core.Test.MusicTests { var newArtist = new Artist { - ForeignArtistId = "123456", + ForeignArtistId = "ce09ea31-3d4a-4487-a797-e315175457a0", RootFolderPath = @"C:\Test\Music" }; @@ -70,7 +70,7 @@ namespace NzbDrone.Core.Test.MusicTests { var newArtist = new Artist { - ForeignArtistId = "123456", + ForeignArtistId = "ce09ea31-3d4a-4487-a797-e315175457a0", RootFolderPath = @"C:\Test\Music" }; @@ -87,7 +87,7 @@ namespace NzbDrone.Core.Test.MusicTests { var newArtist = new Artist { - ForeignArtistId = "123456", + ForeignArtistId = "ce09ea31-3d4a-4487-a797-e315175457a0", Path = @"C:\Test\Music\Name1" }; @@ -108,12 +108,12 @@ namespace NzbDrone.Core.Test.MusicTests { var newArtist = new Artist { - ForeignArtistId = "123456", + ForeignArtistId = "ce09ea31-3d4a-4487-a797-e315175457a0", Path = @"C:\Test\Music\Name1" }; Mocker.GetMock() - .Setup(s => s.GetArtistInfo(newArtist.ForeignArtistId)) + .Setup(s => s.GetArtistInfo(newArtist.ForeignArtistId, newArtist.PrimaryAlbumTypes, newArtist.SecondaryAlbumTypes)) .Throws(new ArtistNotFoundException(newArtist.ForeignArtistId)); Mocker.GetMock() @@ -128,4 +128,4 @@ namespace NzbDrone.Core.Test.MusicTests ExceptionVerification.ExpectedErrors(1); } } -} \ No newline at end of file +} diff --git a/src/NzbDrone.Core.Test/MusicTests/RefreshArtistServiceFixture.cs b/src/NzbDrone.Core.Test/MusicTests/RefreshArtistServiceFixture.cs index 20dc7d223..77b1febe5 100644 --- a/src/NzbDrone.Core.Test/MusicTests/RefreshArtistServiceFixture.cs +++ b/src/NzbDrone.Core.Test/MusicTests/RefreshArtistServiceFixture.cs @@ -38,14 +38,14 @@ namespace NzbDrone.Core.Test.MusicTests .Returns(_artist); Mocker.GetMock() - .Setup(s => s.GetArtistInfo(It.IsAny())) - .Callback(p => { throw new ArtistNotFoundException(p); }); + .Setup(s => s.GetArtistInfo(It.IsAny(), It.IsAny>(), It.IsAny>())) + .Callback(() => { throw new ArtistNotFoundException(_artist.ForeignArtistId); }); } private void GivenNewArtistInfo(Artist artist) { Mocker.GetMock() - .Setup(s => s.GetArtistInfo(_artist.ForeignArtistId)) + .Setup(s => s.GetArtistInfo(_artist.ForeignArtistId, _artist.PrimaryAlbumTypes, _artist.SecondaryAlbumTypes)) .Returns(new Tuple>(artist, new List())); } diff --git a/src/NzbDrone.Core/Datastore/Migration/121_update_types_existing_artist.cs b/src/NzbDrone.Core/Datastore/Migration/121_update_types_existing_artist.cs new file mode 100644 index 000000000..b4eb7da33 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/121_update_types_existing_artist.cs @@ -0,0 +1,14 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(121)] + public class update_types_existing_artist : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Execute.Sql("UPDATE Artists SET PrimaryAlbumTypes = '[]', SecondaryAlbumTypes = '[]'"); + } + } +} diff --git a/src/NzbDrone.Core/MetadataSource/IProvideArtistInfo.cs b/src/NzbDrone.Core/MetadataSource/IProvideArtistInfo.cs index 48240cbc6..f4f67652d 100644 --- a/src/NzbDrone.Core/MetadataSource/IProvideArtistInfo.cs +++ b/src/NzbDrone.Core/MetadataSource/IProvideArtistInfo.cs @@ -1,4 +1,4 @@ -using NzbDrone.Core.Music; +using NzbDrone.Core.Music; using System; using System.Collections.Generic; @@ -6,6 +6,6 @@ namespace NzbDrone.Core.MetadataSource { public interface IProvideArtistInfo { - Tuple> GetArtistInfo(string lidarrId); + Tuple> GetArtistInfo(string lidarrId, List primaryAlbumTypes, List secondaryAlbumTypes); } } diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index a8642e486..924d92dc5 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -37,7 +37,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook _logger = logger; } - public Tuple> GetArtistInfo(string foreignArtistId) + public Tuple> GetArtistInfo(string foreignArtistId, List primaryAlbumTypes, List secondaryAlbumTypes) { _logger.Debug("Getting Artist with LidarrAPI.MetadataID of {0}", foreignArtistId); @@ -46,10 +46,10 @@ namespace NzbDrone.Core.MetadataSource.SkyHook var httpRequest = customerRequestBuilder.Create() .SetSegment("route", "artists/" + foreignArtistId) + .AddQueryParam("primTypes", string.Join("|",primaryAlbumTypes)) + .AddQueryParam("secTypes", string.Join("|", secondaryAlbumTypes)) .Build(); - - httpRequest.AllowAutoRedirect = true; httpRequest.SuppressHttpError = true; @@ -92,7 +92,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook try { - return new List { GetArtistInfo(slug).Item1 }; + return new List { GetArtistInfo(slug, new List{"Album"}, new List{"Studio"}).Item1 }; } catch (ArtistNotFoundException) { diff --git a/src/NzbDrone.Core/Music/AddArtistService.cs b/src/NzbDrone.Core/Music/AddArtistService.cs index 5cfbe6c68..a6450411a 100644 --- a/src/NzbDrone.Core/Music/AddArtistService.cs +++ b/src/NzbDrone.Core/Music/AddArtistService.cs @@ -86,7 +86,7 @@ namespace NzbDrone.Core.Music try { - tuple = _artistInfo.GetArtistInfo(newArtist.ForeignArtistId); + tuple = _artistInfo.GetArtistInfo(newArtist.ForeignArtistId, newArtist.PrimaryAlbumTypes, newArtist.SecondaryAlbumTypes); } catch (ArtistNotFoundException) { diff --git a/src/NzbDrone.Core/Music/Artist.cs b/src/NzbDrone.Core/Music/Artist.cs index c6c28b93b..bd7be5695 100644 --- a/src/NzbDrone.Core/Music/Artist.cs +++ b/src/NzbDrone.Core/Music/Artist.cs @@ -36,8 +36,8 @@ namespace NzbDrone.Core.Music public string Overview { get; set; } public string Disambiguation { get; set; } public string ArtistType { get; set; } - public string PrimaryAlbumTypes { get; set; } - public string SecondaryAlbumTypes { get; set; } + public List PrimaryAlbumTypes { get; set; } + public List SecondaryAlbumTypes { get; set; } public bool Monitored { get; set; } public bool AlbumFolder { get; set; } public DateTime? LastInfoSync { get; set; } diff --git a/src/NzbDrone.Core/Music/RefreshArtistService.cs b/src/NzbDrone.Core/Music/RefreshArtistService.cs index 65372b82d..d765e1e61 100644 --- a/src/NzbDrone.Core/Music/RefreshArtistService.cs +++ b/src/NzbDrone.Core/Music/RefreshArtistService.cs @@ -54,7 +54,7 @@ namespace NzbDrone.Core.Music try { - tuple = _artistInfo.GetArtistInfo(artist.ForeignArtistId); + tuple = _artistInfo.GetArtistInfo(artist.ForeignArtistId, artist.PrimaryAlbumTypes, artist.SecondaryAlbumTypes); } catch (ArtistNotFoundException) { diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 653b7342d..9262da949 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -252,6 +252,7 @@ +