diff --git a/src/NzbDrone.Core.Test/NotificationTests/Xbmc/GetArtistPathFixture.cs b/src/NzbDrone.Core.Test/NotificationTests/Xbmc/GetArtistPathFixture.cs index 4340555e5..8a15cf60c 100644 --- a/src/NzbDrone.Core.Test/NotificationTests/Xbmc/GetArtistPathFixture.cs +++ b/src/NzbDrone.Core.Test/NotificationTests/Xbmc/GetArtistPathFixture.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using DryIoc.ImTools; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; @@ -17,6 +18,7 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc private XbmcSettings _settings; private Music.Artist _artist; private List _xbmcArtist; + private List _xbmcSources; [SetUp] public void Setup() @@ -27,14 +29,25 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc _xbmcArtist = Builder.CreateListOfSize(3) .All() .With(s => s.MusicbrainzArtistId = new List { "0" }) + .With(s => s.SourceId = new List { 1 }) .TheFirst(1) .With(s => s.MusicbrainzArtistId = new List { MB_ID.ToString() }) .Build() .ToList(); + _xbmcSources = Builder.CreateListOfSize(1) + .All() + .With(s => s.SourceId = _xbmcArtist.First().SourceId.First()) + .Build() + .ToList(); + Mocker.GetMock() .Setup(s => s.GetArtist(_settings)) .Returns(_xbmcArtist); + + Mocker.GetMock() + .Setup(s => s.GetSources(_settings)) + .Returns(_xbmcSources); } private void GivenMatchingMusicbrainzId() @@ -77,7 +90,7 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc { GivenMatchingMusicbrainzId(); - Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcArtist.First().File); + Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcSources.First().File); } [Test] @@ -85,7 +98,7 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc { GivenMatchingTitle(); - Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcArtist.First().File); + Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcSources.First().File); } } } diff --git a/src/NzbDrone.Core/Notifications/Xbmc/Model/KodiArtist.cs b/src/NzbDrone.Core/Notifications/Xbmc/Model/KodiArtist.cs index 1e86c7c9d..cba1719f7 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/Model/KodiArtist.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/Model/KodiArtist.cs @@ -7,6 +7,6 @@ namespace NzbDrone.Core.Notifications.Xbmc.Model public int ArtistId { get; set; } public string Label { get; set; } public List MusicbrainzArtistId { get; set; } - public string File { get; set; } + public List SourceId { get; set; } } } diff --git a/src/NzbDrone.Core/Notifications/Xbmc/Model/KodiSource.cs b/src/NzbDrone.Core/Notifications/Xbmc/Model/KodiSource.cs new file mode 100644 index 000000000..0c45e406d --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Xbmc/Model/KodiSource.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace NzbDrone.Core.Notifications.Xbmc.Model +{ + public class KodiSource + { + public int SourceId { get; set; } + public string File { get; set; } + } +} diff --git a/src/NzbDrone.Core/Notifications/Xbmc/Model/SourceResponse.cs b/src/NzbDrone.Core/Notifications/Xbmc/Model/SourceResponse.cs new file mode 100644 index 000000000..d8c6a3601 --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Xbmc/Model/SourceResponse.cs @@ -0,0 +1,9 @@ +namespace NzbDrone.Core.Notifications.Xbmc.Model +{ + public class SourceResponse + { + public string Id { get; set; } + public string JsonRpc { get; set; } + public SourceResult Result { get; set; } + } +} diff --git a/src/NzbDrone.Core/Notifications/Xbmc/Model/SourceResult.cs b/src/NzbDrone.Core/Notifications/Xbmc/Model/SourceResult.cs new file mode 100644 index 000000000..8c2c3c866 --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Xbmc/Model/SourceResult.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace NzbDrone.Core.Notifications.Xbmc.Model +{ + public class SourceResult + { + public Dictionary Limits { get; set; } + public List Sources; + + public SourceResult() + { + Sources = new List(); + } + } +} diff --git a/src/NzbDrone.Core/Notifications/Xbmc/XbmcJsonApiProxy.cs b/src/NzbDrone.Core/Notifications/Xbmc/XbmcJsonApiProxy.cs index f130199ba..b2bd6895e 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/XbmcJsonApiProxy.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/XbmcJsonApiProxy.cs @@ -15,6 +15,7 @@ namespace NzbDrone.Core.Notifications.Xbmc void CleanLibrary(XbmcSettings settings); List GetActivePlayers(XbmcSettings settings); List GetArtist(XbmcSettings settings); + List GetSources(XbmcSettings settings); } public class XbmcJsonApiProxy : IXbmcJsonApiProxy @@ -68,11 +69,18 @@ namespace NzbDrone.Core.Notifications.Xbmc public List GetArtist(XbmcSettings settings) { - var response = ProcessRequest(settings, "AudioLibrary.GetArtists", new List { "properties", "musicbrainzartistid" }); + var response = ProcessRequest(settings, "AudioLibrary.GetArtists", true, new List { "sourceid", "musicbrainzartistid" }); return Json.Deserialize(response).Result.Artists; } + public List GetSources(XbmcSettings settings) + { + var response = ProcessRequest(settings, "AudioLibrary.GetSources", new List { "file" }); + + return Json.Deserialize(response).Result.Sources; + } + private string ProcessRequest(XbmcSettings settings, string method, params object[] parameters) { var url = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, "jsonrpc"); diff --git a/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs b/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs index 334837b95..7756b35fc 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs @@ -3,6 +3,7 @@ using System.Linq; using FluentValidation.Results; using NLog; using NzbDrone.Core.Music; +using NzbDrone.Core.Notifications.Xbmc.Model; namespace NzbDrone.Core.Notifications.Xbmc { @@ -70,7 +71,16 @@ namespace NzbDrone.Core.Notifications.Xbmc return musicBrainzId == artist.Metadata.Value.ForeignArtistId || s.Label == artist.Name; }); - return matchingArtist?.File; + KodiSource matchingSource = null; + + if (matchingArtist != null && matchingArtist.SourceId.Any()) + { + var allSources = _proxy.GetSources(settings); + + matchingSource = allSources.FirstOrDefault(s => s.SourceId == matchingArtist.SourceId.FirstOrDefault()); + } + + return matchingSource?.File; } private void UpdateLibrary(XbmcSettings settings, Artist artist)