mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-06 13:02:23 -07:00
parent
b547156d91
commit
02152d85a1
7 changed files with 70 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using DryIoc.ImTools;
|
||||||
using FizzWare.NBuilder;
|
using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
@ -17,6 +18,7 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc
|
||||||
private XbmcSettings _settings;
|
private XbmcSettings _settings;
|
||||||
private Music.Artist _artist;
|
private Music.Artist _artist;
|
||||||
private List<KodiArtist> _xbmcArtist;
|
private List<KodiArtist> _xbmcArtist;
|
||||||
|
private List<KodiSource> _xbmcSources;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
|
@ -27,14 +29,25 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc
|
||||||
_xbmcArtist = Builder<KodiArtist>.CreateListOfSize(3)
|
_xbmcArtist = Builder<KodiArtist>.CreateListOfSize(3)
|
||||||
.All()
|
.All()
|
||||||
.With(s => s.MusicbrainzArtistId = new List<string> { "0" })
|
.With(s => s.MusicbrainzArtistId = new List<string> { "0" })
|
||||||
|
.With(s => s.SourceId = new List<int> { 1 })
|
||||||
.TheFirst(1)
|
.TheFirst(1)
|
||||||
.With(s => s.MusicbrainzArtistId = new List<string> { MB_ID.ToString() })
|
.With(s => s.MusicbrainzArtistId = new List<string> { MB_ID.ToString() })
|
||||||
.Build()
|
.Build()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
_xbmcSources = Builder<KodiSource>.CreateListOfSize(1)
|
||||||
|
.All()
|
||||||
|
.With(s => s.SourceId = _xbmcArtist.First().SourceId.First())
|
||||||
|
.Build()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
Mocker.GetMock<IXbmcJsonApiProxy>()
|
Mocker.GetMock<IXbmcJsonApiProxy>()
|
||||||
.Setup(s => s.GetArtist(_settings))
|
.Setup(s => s.GetArtist(_settings))
|
||||||
.Returns(_xbmcArtist);
|
.Returns(_xbmcArtist);
|
||||||
|
|
||||||
|
Mocker.GetMock<IXbmcJsonApiProxy>()
|
||||||
|
.Setup(s => s.GetSources(_settings))
|
||||||
|
.Returns(_xbmcSources);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GivenMatchingMusicbrainzId()
|
private void GivenMatchingMusicbrainzId()
|
||||||
|
@ -77,7 +90,7 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc
|
||||||
{
|
{
|
||||||
GivenMatchingMusicbrainzId();
|
GivenMatchingMusicbrainzId();
|
||||||
|
|
||||||
Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcArtist.First().File);
|
Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcSources.First().File);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -85,7 +98,7 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc
|
||||||
{
|
{
|
||||||
GivenMatchingTitle();
|
GivenMatchingTitle();
|
||||||
|
|
||||||
Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcArtist.First().File);
|
Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcSources.First().File);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,6 @@ namespace NzbDrone.Core.Notifications.Xbmc.Model
|
||||||
public int ArtistId { get; set; }
|
public int ArtistId { get; set; }
|
||||||
public string Label { get; set; }
|
public string Label { get; set; }
|
||||||
public List<string> MusicbrainzArtistId { 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 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
||||||
void CleanLibrary(XbmcSettings settings);
|
void CleanLibrary(XbmcSettings settings);
|
||||||
List<ActivePlayer> GetActivePlayers(XbmcSettings settings);
|
List<ActivePlayer> GetActivePlayers(XbmcSettings settings);
|
||||||
List<KodiArtist> GetArtist(XbmcSettings settings);
|
List<KodiArtist> GetArtist(XbmcSettings settings);
|
||||||
|
List<KodiSource> GetSources(XbmcSettings settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class XbmcJsonApiProxy : IXbmcJsonApiProxy
|
public class XbmcJsonApiProxy : IXbmcJsonApiProxy
|
||||||
|
@ -68,11 +69,18 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
||||||
|
|
||||||
public List<KodiArtist> GetArtist(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;
|
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)
|
private string ProcessRequest(XbmcSettings settings, string method, params object[] parameters)
|
||||||
{
|
{
|
||||||
var url = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, "jsonrpc");
|
var url = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, "jsonrpc");
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Linq;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Core.Music;
|
using NzbDrone.Core.Music;
|
||||||
|
using NzbDrone.Core.Notifications.Xbmc.Model;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Notifications.Xbmc
|
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 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)
|
private void UpdateLibrary(XbmcSettings settings, Artist artist)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue