mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-25 07:12:40 +00:00
parent
b547156d91
commit
02152d85a1
7 changed files with 70 additions and 5 deletions
|
@ -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 @@ public class GetArtistPathFixture : CoreTest<XbmcService>
|
|||
private XbmcSettings _settings;
|
||||
private Music.Artist _artist;
|
||||
private List<KodiArtist> _xbmcArtist;
|
||||
private List<KodiSource> _xbmcSources;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
|
@ -27,14 +29,25 @@ public void Setup()
|
|||
_xbmcArtist = Builder<KodiArtist>.CreateListOfSize(3)
|
||||
.All()
|
||||
.With(s => s.MusicbrainzArtistId = new List<string> { "0" })
|
||||
.With(s => s.SourceId = new List<int> { 1 })
|
||||
.TheFirst(1)
|
||||
.With(s => s.MusicbrainzArtistId = new List<string> { MB_ID.ToString() })
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
_xbmcSources = Builder<KodiSource>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(s => s.SourceId = _xbmcArtist.First().SourceId.First())
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Mocker.GetMock<IXbmcJsonApiProxy>()
|
||||
.Setup(s => s.GetArtist(_settings))
|
||||
.Returns(_xbmcArtist);
|
||||
|
||||
Mocker.GetMock<IXbmcJsonApiProxy>()
|
||||
.Setup(s => s.GetSources(_settings))
|
||||
.Returns(_xbmcSources);
|
||||
}
|
||||
|
||||
private void GivenMatchingMusicbrainzId()
|
||||
|
@ -77,7 +90,7 @@ public void should_return_path_when_musicbrainzId_matches()
|
|||
{
|
||||
GivenMatchingMusicbrainzId();
|
||||
|
||||
Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcArtist.First().File);
|
||||
Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcSources.First().File);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -85,7 +98,7 @@ public void should_return_path_when_title_matches()
|
|||
{
|
||||
GivenMatchingTitle();
|
||||
|
||||
Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcArtist.First().File);
|
||||
Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcSources.First().File);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ public class KodiArtist
|
|||
public int ArtistId { get; set; }
|
||||
public string Label { get; set; }
|
||||
public List<string> MusicbrainzArtistId { get; set; }
|
||||
public string File { get; set; }
|
||||
public List<int> SourceId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
10
src/NzbDrone.Core/Notifications/Xbmc/Model/KodiSource.cs
Normal file
10
src/NzbDrone.Core/Notifications/Xbmc/Model/KodiSource.cs
Normal file
|
@ -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; }
|
||||
}
|
||||
}
|
|
@ -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; }
|
||||
}
|
||||
}
|
15
src/NzbDrone.Core/Notifications/Xbmc/Model/SourceResult.cs
Normal file
15
src/NzbDrone.Core/Notifications/Xbmc/Model/SourceResult.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Xbmc.Model
|
||||
{
|
||||
public class SourceResult
|
||||
{
|
||||
public Dictionary<string, int> Limits { get; set; }
|
||||
public List<KodiSource> Sources;
|
||||
|
||||
public SourceResult()
|
||||
{
|
||||
Sources = new List<KodiSource>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ public interface IXbmcJsonApiProxy
|
|||
void CleanLibrary(XbmcSettings settings);
|
||||
List<ActivePlayer> GetActivePlayers(XbmcSettings settings);
|
||||
List<KodiArtist> GetArtist(XbmcSettings settings);
|
||||
List<KodiSource> GetSources(XbmcSettings settings);
|
||||
}
|
||||
|
||||
public class XbmcJsonApiProxy : IXbmcJsonApiProxy
|
||||
|
@ -68,11 +69,18 @@ public List<ActivePlayer> GetActivePlayers(XbmcSettings settings)
|
|||
|
||||
public List<KodiArtist> GetArtist(XbmcSettings settings)
|
||||
{
|
||||
var response = ProcessRequest(settings, "AudioLibrary.GetArtists", new List<string> { "properties", "musicbrainzartistid" });
|
||||
var response = ProcessRequest(settings, "AudioLibrary.GetArtists", true, new List<string> { "sourceid", "musicbrainzartistid" });
|
||||
|
||||
return Json.Deserialize<ArtistResponse>(response).Result.Artists;
|
||||
}
|
||||
|
||||
public List<KodiSource> GetSources(XbmcSettings settings)
|
||||
{
|
||||
var response = ProcessRequest(settings, "AudioLibrary.GetSources", new List<string> { "file" });
|
||||
|
||||
return Json.Deserialize<SourceResponse>(response).Result.Sources;
|
||||
}
|
||||
|
||||
private string ProcessRequest(XbmcSettings settings, string method, params object[] parameters)
|
||||
{
|
||||
var url = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, "jsonrpc");
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Notifications.Xbmc.Model;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Xbmc
|
||||
{
|
||||
|
@ -70,7 +71,16 @@ public string GetArtistPath(XbmcSettings settings, Artist artist)
|
|||
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)
|
||||
|
|
Loading…
Reference in a new issue