mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 10:47:08 -07:00
Fixed: Kodi(XBMC) notifications don't update correct Library (#158)
* Fixed: Kodi(XBMC) notifications don't update correct Library * fixup! MbId and Artist Names in Test
This commit is contained in:
parent
d08d89929a
commit
e780555d28
17 changed files with 144 additions and 160 deletions
|
@ -1,4 +1,4 @@
|
|||
using System.Linq;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
|
@ -23,7 +23,7 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
|
|||
private void WithVideoPlayerActive()
|
||||
{
|
||||
var activePlayers = @"<html><li>Filename:C:\Test\TV\2 Broke Girls\Season 01\2 Broke Girls - S01E01 - Pilot [SDTV].avi" +
|
||||
"<li>PlayStatus:Playing<li>VideoNo:0<li>Type:Video<li>Thumb:special://masterprofile/Thumbnails/Video/a/auto-a664d5a2.tbn" +
|
||||
"<li>PlayStatus:Playing<li>VideoNo:0<li>Type:Audio<li>Thumb:special://masterprofile/Thumbnails/Video/a/auto-a664d5a2.tbn" +
|
||||
"<li>Time:00:06<li>Duration:21:35<li>Percentage:0<li>File size:183182590<li>Changed:True</html>";
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
|
@ -57,14 +57,14 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void should_have_active_video_player()
|
||||
public void should_have_active_audio_player()
|
||||
{
|
||||
WithVideoPlayerActive();
|
||||
|
||||
var result = Subject.GetActivePlayers(_settings);
|
||||
|
||||
result.Should().HaveCount(1);
|
||||
result.First().Type.Should().Be("video");
|
||||
result.First().Type.Should().Be("audio");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ using NzbDrone.Core.Music;
|
|||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
|
||||
{
|
||||
[TestFixture]
|
||||
public class GetSeriesPathFixture : CoreTest<HttpApiProvider>
|
||||
public class GetArtistPathFixture : CoreTest<HttpApiProvider>
|
||||
{
|
||||
private XbmcSettings _settings;
|
||||
private Artist _artist;
|
||||
|
@ -29,8 +29,8 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
|
|||
|
||||
_artist = new Artist
|
||||
{
|
||||
ForeignArtistId = "123d45d-d154f5d-1f5d1-5df18d5",
|
||||
Name = "30 Rock"
|
||||
ForeignArtistId = "9f4e41c3-2648-428e-b8c7-dc10465b49ac",
|
||||
Name = "Shawn Desman"
|
||||
};
|
||||
|
||||
const string setResponseUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=SetResponseFormat(webheader;false;webfooter;false;header;<xml>;footer;</xml>;opentag;<tag>;closetag;</tag>;closefinaltag;false)";
|
||||
|
@ -48,47 +48,47 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_series_path()
|
||||
public void should_get_artist_path()
|
||||
{
|
||||
const string queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/</field></record></xml>";
|
||||
var query = string.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)");
|
||||
const string queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/Music/Shawn Desman/</field></record></xml>";
|
||||
var query = string.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryMusicDatabase(select path.strPath from path, artist, artistlinkpath where artist.c12 = 9f4e41c3-2648-428e-b8c7-dc10465b49ac and artistlinkpath.idArtist = artist.idArtist and artistlinkpath.idPath = path.idPath)");
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(query, _settings.Username, _settings.Password))
|
||||
.Returns(queryResult);
|
||||
|
||||
Subject.GetSeriesPath(_settings, _artist)
|
||||
.Should().Be("smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/");
|
||||
Subject.GetArtistPath(_settings, _artist)
|
||||
.Should().Be("smb://xbmc:xbmc@HOMESERVER/Music/Shawn Desman/");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_null_for_series_path()
|
||||
public void should_get_null_for_artist_path()
|
||||
{
|
||||
const string queryResult = @"<xml></xml>";
|
||||
var query = string.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)");
|
||||
var query = string.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryMusicDatabase(select path.strPath from path, artist, artistlinkpath where artist.c12 = 9f4e41c3-2648-428e-b8c7-dc10465b49ac and artistlinkpath.idArtist = artist.idArtist and artistlinkpath.idPath = path.idPath)");
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(query, _settings.Username, _settings.Password))
|
||||
.Returns(queryResult);
|
||||
|
||||
|
||||
Subject.GetSeriesPath(_settings, _artist)
|
||||
Subject.GetArtistPath(_settings, _artist)
|
||||
.Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_series_path_with_special_characters_in_it()
|
||||
public void should_get_artist_path_with_special_characters_in_it()
|
||||
{
|
||||
const string queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/</field></record></xml>";
|
||||
var query = string.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)");
|
||||
const string queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/Music/-wumpscut-/</field></record></xml>";
|
||||
var query = string.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryMusicDatabase(select path.strPath from path, artist, artistlinkpath where artist.c12 = 9f4e41c3-2648-428e-b8c7-dc10465b49ac and artistlinkpath.idArtist = artist.idArtist and artistlinkpath.idPath = path.idPath)");
|
||||
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(query, _settings.Username, _settings.Password))
|
||||
.Returns(queryResult);
|
||||
|
||||
|
||||
Subject.GetSeriesPath(_settings, _artist)
|
||||
.Should().Be("smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/");
|
||||
Subject.GetArtistPath(_settings, _artist)
|
||||
.Should().Be("smb://xbmc:xbmc@HOMESERVER/Music/-wumpscut-/");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,8 +11,8 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
|
|||
public class UpdateFixture : CoreTest<HttpApiProvider>
|
||||
{
|
||||
private XbmcSettings _settings;
|
||||
private string _seriesQueryUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)";
|
||||
private Artist _fakeSeries;
|
||||
private string _artistQueryUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryMusicDatabase(select path.strPath from path, artist, artistlinkpath where artist.c12 = 9f4e41c3-2648-428e-b8c7-dc10465b49ac and artistlinkpath.idArtist = artist.idArtist and artistlinkpath.idPath = path.idPath)";
|
||||
private Artist _fakeArtist;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
|
@ -28,47 +28,47 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
|
|||
UpdateLibrary = true
|
||||
};
|
||||
|
||||
_fakeSeries = Builder<Artist>.CreateNew()
|
||||
.With(s => s.ForeignArtistId = "79488")
|
||||
.With(s => s.Name = "30 Rock")
|
||||
_fakeArtist = Builder<Artist>.CreateNew()
|
||||
.With(s => s.ForeignArtistId = "9f4e41c3-2648-428e-b8c7-dc10465b49ac")
|
||||
.With(s => s.Name = "Shawn Desman")
|
||||
.Build();
|
||||
}
|
||||
|
||||
private void WithSeriesPath()
|
||||
private void WithArtistPath()
|
||||
{
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(_seriesQueryUrl, _settings.Username, _settings.Password))
|
||||
.Returns("<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/</field></record></xml>");
|
||||
.Setup(s => s.DownloadString(_artistQueryUrl, _settings.Username, _settings.Password))
|
||||
.Returns("<xml><record><field>smb://xbmc:xbmc@HOMESERVER/Music/Shawn Desman/</field></record></xml>");
|
||||
}
|
||||
|
||||
private void WithoutSeriesPath()
|
||||
private void WithoutArtistPath()
|
||||
{
|
||||
Mocker.GetMock<IHttpProvider>()
|
||||
.Setup(s => s.DownloadString(_seriesQueryUrl, _settings.Username, _settings.Password))
|
||||
.Setup(s => s.DownloadString(_artistQueryUrl, _settings.Username, _settings.Password))
|
||||
.Returns("<xml></xml>");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_using_series_path()
|
||||
public void should_update_using_artist_path()
|
||||
{
|
||||
WithSeriesPath();
|
||||
const string url = "http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video,smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/))";
|
||||
WithArtistPath();
|
||||
const string url = "http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(music,smb://xbmc:xbmc@HOMESERVER/Music/Shawn Desman/))";
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadString(url, _settings.Username, _settings.Password));
|
||||
|
||||
Subject.Update(_settings, _fakeSeries);
|
||||
Subject.Update(_settings, _fakeArtist);
|
||||
Mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_all_paths_when_series_path_not_found()
|
||||
public void should_update_all_paths_when_artist_path_not_found()
|
||||
{
|
||||
WithoutSeriesPath();
|
||||
const string url = "http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video))";
|
||||
WithoutArtistPath();
|
||||
const string url = "http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(music))";
|
||||
|
||||
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadString(url, _settings.Username, _settings.Password));
|
||||
|
||||
Subject.Update(_settings, _fakeSeries);
|
||||
Subject.Update(_settings, _fakeArtist);
|
||||
Mocker.VerifyAllMocks();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,12 @@ using NzbDrone.Core.Music;
|
|||
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
|
||||
{
|
||||
[TestFixture]
|
||||
public class GetSeriesPathFixture : CoreTest<JsonApiProvider>
|
||||
public class GetArtistPathFixture : CoreTest<JsonApiProvider>
|
||||
{
|
||||
private const string MB_ID = "5";
|
||||
private const string MB_ID = "9f4e41c3-2648-428e-b8c7-dc10465b49ac";
|
||||
private XbmcSettings _settings;
|
||||
private Artist _artist;
|
||||
private List<TvShow> _xbmcSeries;
|
||||
private Music.Artist _artist;
|
||||
private List<KodiArtist> _xbmcArtist;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
|
@ -24,25 +24,25 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
|
|||
_settings = Builder<XbmcSettings>.CreateNew()
|
||||
.Build();
|
||||
|
||||
_xbmcSeries = Builder<TvShow>.CreateListOfSize(3)
|
||||
_xbmcArtist = Builder<KodiArtist>.CreateListOfSize(3)
|
||||
.All()
|
||||
.With(s => s.ImdbNumber = "0")
|
||||
.With(s => s.MusicbrainzArtistId = new List<string>{"0"})
|
||||
.TheFirst(1)
|
||||
.With(s => s.ImdbNumber = MB_ID.ToString())
|
||||
.With(s => s.MusicbrainzArtistId = new List<string> {MB_ID.ToString()})
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Mocker.GetMock<IXbmcJsonApiProxy>()
|
||||
.Setup(s => s.GetArtist(_settings))
|
||||
.Returns(_xbmcSeries);
|
||||
.Returns(_xbmcArtist);
|
||||
}
|
||||
|
||||
private void GivenMatchingTvdbId()
|
||||
private void GivenMatchingMusicbrainzId()
|
||||
{
|
||||
_artist = new Artist
|
||||
{
|
||||
ForeignArtistId = MB_ID,
|
||||
Name = "TV Show"
|
||||
Name = "Artist"
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -51,11 +51,11 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
|
|||
_artist = new Artist
|
||||
{
|
||||
ForeignArtistId = "1000",
|
||||
Name = _xbmcSeries.First().Label
|
||||
Name = _xbmcArtist.First().Label
|
||||
};
|
||||
}
|
||||
|
||||
private void GivenMatchingSeries()
|
||||
private void GivenMatchingArtist()
|
||||
{
|
||||
_artist = new Artist
|
||||
{
|
||||
|
@ -65,19 +65,19 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_null_when_series_is_not_found()
|
||||
public void should_return_null_when_artist_is_not_found()
|
||||
{
|
||||
GivenMatchingSeries();
|
||||
GivenMatchingArtist();
|
||||
|
||||
Subject.GetSeriesPath(_settings, _artist).Should().BeNull();
|
||||
Subject.GetArtistPath(_settings, _artist).Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_path_when_tvdbId_matches()
|
||||
public void should_return_path_when_musicbrainzId_matches()
|
||||
{
|
||||
GivenMatchingTvdbId();
|
||||
GivenMatchingMusicbrainzId();
|
||||
|
||||
Subject.GetSeriesPath(_settings, _artist).Should().Be(_xbmcSeries.First().File);
|
||||
Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcArtist.First().File);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -85,22 +85,7 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
|
|||
{
|
||||
GivenMatchingTitle();
|
||||
|
||||
Subject.GetSeriesPath(_settings, _artist).Should().Be(_xbmcSeries.First().File);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_throw_when_imdb_number_is_not_a_number()
|
||||
{
|
||||
GivenMatchingTvdbId();
|
||||
|
||||
_xbmcSeries.ForEach(s => s.ImdbNumber = "tt12345");
|
||||
_xbmcSeries.Last().ImdbNumber = MB_ID.ToString();
|
||||
|
||||
Mocker.GetMock<IXbmcJsonApiProxy>()
|
||||
.Setup(s => s.GetArtist(_settings))
|
||||
.Returns(_xbmcSeries);
|
||||
|
||||
Subject.GetSeriesPath(_settings, _artist).Should().NotBeNull();
|
||||
Subject.GetArtistPath(_settings, _artist).Should().Be(_xbmcArtist.First().File);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,9 +13,9 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
|
|||
[TestFixture]
|
||||
public class UpdateFixture : CoreTest<JsonApiProvider>
|
||||
{
|
||||
private const string MB_ID = "5";
|
||||
private const string MB_ID = "9f4e41c3-2648-428e-b8c7-dc10465b49ac";
|
||||
private XbmcSettings _settings;
|
||||
private List<TvShow> _xbmcArtist;
|
||||
private List<KodiArtist> _xbmcArtist;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
|
@ -23,9 +23,9 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
|
|||
_settings = Builder<XbmcSettings>.CreateNew()
|
||||
.Build();
|
||||
|
||||
_xbmcArtist = Builder<TvShow>.CreateListOfSize(3)
|
||||
_xbmcArtist = Builder<KodiArtist>.CreateListOfSize(3)
|
||||
.TheFirst(1)
|
||||
.With(s => s.ImdbNumber = MB_ID.ToString())
|
||||
.With(s => s.MusicbrainzArtistId = new List<string> { MB_ID.ToString()})
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
|
@ -39,27 +39,27 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_using_series_path()
|
||||
public void should_update_using_artist_path()
|
||||
{
|
||||
var series = Builder<Artist>.CreateNew()
|
||||
var artist = Builder<Music.Artist>.CreateNew()
|
||||
.With(s => s.ForeignArtistId = MB_ID)
|
||||
.Build();
|
||||
|
||||
Subject.Update(_settings, series);
|
||||
Subject.Update(_settings, artist);
|
||||
|
||||
Mocker.GetMock<IXbmcJsonApiProxy>()
|
||||
.Verify(v => v.UpdateLibrary(_settings, It.IsAny<string>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_all_paths_when_series_path_not_found()
|
||||
public void should_update_all_paths_when_artist_path_not_found()
|
||||
{
|
||||
var fakeSeries = Builder<Artist>.CreateNew()
|
||||
.With(s => s.ForeignArtistId = "1000")
|
||||
.With(s => s.Name = "Not 30 Rock")
|
||||
var fakeArtist = Builder<Artist>.CreateNew()
|
||||
.With(s => s.ForeignArtistId = "9f4e41c3-2648-428e-b8c7-dc10465b49ad")
|
||||
.With(s => s.Name = "Not Shawn Desman")
|
||||
.Build();
|
||||
|
||||
Subject.Update(_settings, fakeSeries);
|
||||
Subject.Update(_settings, fakeArtist);
|
||||
|
||||
Mocker.GetMock<IXbmcJsonApiProxy>()
|
||||
.Verify(v => v.UpdateLibrary(_settings, null), Times.Once());
|
||||
|
|
|
@ -305,9 +305,9 @@
|
|||
<Compile Include="NotificationTests\ProwlProviderTest.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Http\ActivePlayersFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Http\CheckForErrorFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Http\GetSeriesPathFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Http\GetArtistPathFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Http\UpdateFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Json\GetSeriesPathFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Json\GetArtistPathFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\Json\UpdateFixture.cs" />
|
||||
<Compile Include="NotificationTests\Xbmc\OnDownloadFixture.cs" />
|
||||
<Compile Include="OrganizerTests\BuildFilePathFixture.cs" />
|
||||
|
|
|
@ -41,9 +41,9 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
_logger.Debug("Determining if there are any active players on XBMC host: {0}", settings.Address);
|
||||
var activePlayers = GetActivePlayers(settings);
|
||||
|
||||
if (activePlayers.Any(a => a.Type.Equals("video")))
|
||||
if (activePlayers.Any(a => a.Type.Equals("audio")))
|
||||
{
|
||||
_logger.Debug("Video is currently playing, skipping library update");
|
||||
_logger.Debug("Audio is currently playing, skipping library update");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -53,8 +53,8 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
|
||||
public void Clean(XbmcSettings settings)
|
||||
{
|
||||
const string cleanVideoLibrary = "CleanLibrary(video)";
|
||||
var command = BuildExecBuiltInCommand(cleanVideoLibrary);
|
||||
const string cleanMusicLibrary = "CleanLibrary(music)";
|
||||
var command = BuildExecBuiltInCommand(cleanMusicLibrary);
|
||||
|
||||
SendCommand(settings, command);
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
var response = SendCommand(settings, "getcurrentlyplaying");
|
||||
|
||||
if (response.Contains("<li>Filename:[Nothing Playing]")) return new List<ActivePlayer>();
|
||||
if (response.Contains("<li>Type:Video")) result.Add(new ActivePlayer(1, "video"));
|
||||
if (response.Contains("<li>Type:Audio")) result.Add(new ActivePlayer(1, "audio"));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -80,13 +80,13 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
return new List<ActivePlayer>();
|
||||
}
|
||||
|
||||
internal string GetSeriesPath(XbmcSettings settings, Artist artist)
|
||||
internal string GetArtistPath(XbmcSettings settings, Artist artist)
|
||||
{
|
||||
var query =
|
||||
string.Format(
|
||||
"select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = {0} and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath",
|
||||
"select path.strPath from path, artist, artistlinkpath where artist.c12 = {0} and artistlinkpath.idArtist = artist.idArtist and artistlinkpath.idPath = path.idPath",
|
||||
artist.ForeignArtistId);
|
||||
var command = string.Format("QueryVideoDatabase({0})", query);
|
||||
var command = string.Format("QueryMusicDatabase({0})", query);
|
||||
|
||||
const string setResponseCommand =
|
||||
"SetResponseFormat(webheader;false;webfooter;false;header;<xml>;footer;</xml>;opentag;<tag>;closetag;</tag>;closefinaltag;false)";
|
||||
|
@ -142,13 +142,13 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
try
|
||||
{
|
||||
_logger.Debug("Sending Update DB Request to XBMC Host: {0}", settings.Address);
|
||||
var xbmcSeriesPath = GetSeriesPath(settings, artist);
|
||||
var xbmcArtistPath = GetArtistPath(settings, artist);
|
||||
|
||||
//If the path is found update it, else update the whole library
|
||||
if (!string.IsNullOrEmpty(xbmcSeriesPath))
|
||||
if (!string.IsNullOrEmpty(xbmcArtistPath))
|
||||
{
|
||||
_logger.Debug("Updating artist [{0}] on XBMC host: {1}", artist, settings.Address);
|
||||
var command = BuildExecBuiltInCommand(string.Format("UpdateLibrary(video,{0})", xbmcSeriesPath));
|
||||
var command = BuildExecBuiltInCommand(string.Format("UpdateLibrary(music,{0})", xbmcArtistPath));
|
||||
SendCommand(settings, command);
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
{
|
||||
//Update the entire library
|
||||
_logger.Debug("Artist [{0}] doesn't exist on XBMC host: {1}, Updating Entire Library", artist, settings.Address);
|
||||
var command = BuildExecBuiltInCommand("UpdateLibrary(video)");
|
||||
var command = BuildExecBuiltInCommand("UpdateLibrary(music)");
|
||||
SendCommand(settings, command);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,9 +35,9 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
_logger.Debug("Determining if there are any active players on XBMC host: {0}", settings.Address);
|
||||
var activePlayers = _proxy.GetActivePlayers(settings);
|
||||
|
||||
if (activePlayers.Any(a => a.Type.Equals("video")))
|
||||
if (activePlayers.Any(a => a.Type.Equals("audio")))
|
||||
{
|
||||
_logger.Debug("Video is currently playing, skipping library update");
|
||||
_logger.Debug("Audio is currently playing, skipping library update");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -55,38 +55,35 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
return _proxy.GetActivePlayers(settings);
|
||||
}
|
||||
|
||||
public string GetSeriesPath(XbmcSettings settings, Artist artist)
|
||||
public string GetArtistPath(XbmcSettings settings, Artist artist)
|
||||
{
|
||||
var allSeries = _proxy.GetArtist(settings);
|
||||
var allArtists = _proxy.GetArtist(settings);
|
||||
|
||||
if (!allSeries.Any())
|
||||
if (!allArtists.Any())
|
||||
{
|
||||
_logger.Debug("No Artists returned from XBMC");
|
||||
return null;
|
||||
}
|
||||
|
||||
var matchingSeries = allSeries.FirstOrDefault(s =>
|
||||
var matchingArtist = allArtists.FirstOrDefault(s =>
|
||||
{
|
||||
var tvdbId = "0";
|
||||
//int.TryParse(s.ImdbNumber, out tvdbId);
|
||||
var musicBrainzId = s.MusicbrainzArtistId.FirstOrDefault();
|
||||
|
||||
return tvdbId == artist.ForeignArtistId || s.Label == artist.Name;
|
||||
return musicBrainzId == artist.ForeignArtistId || s.Label == artist.Name;
|
||||
});
|
||||
|
||||
if (matchingSeries != null) return matchingSeries.File;
|
||||
|
||||
return null;
|
||||
return matchingArtist?.File;
|
||||
}
|
||||
|
||||
private void UpdateLibrary(XbmcSettings settings, Artist artist)
|
||||
{
|
||||
try
|
||||
{
|
||||
var seriesPath = GetSeriesPath(settings, artist);
|
||||
var artistPath = GetArtistPath(settings, artist);
|
||||
|
||||
if (seriesPath != null)
|
||||
if (artistPath != null)
|
||||
{
|
||||
_logger.Debug("Updating artist {0} (Path: {1}) on XBMC host: {2}", artist, seriesPath, settings.Address);
|
||||
_logger.Debug("Updating artist {0} (Path: {1}) on XBMC host: {2}", artist, artistPath, settings.Address);
|
||||
}
|
||||
|
||||
else
|
||||
|
@ -95,7 +92,7 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
settings.Address);
|
||||
}
|
||||
|
||||
var response = _proxy.UpdateLibrary(settings, seriesPath);
|
||||
var response = _proxy.UpdateLibrary(settings, artistPath);
|
||||
|
||||
if (!response.Equals("OK", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
namespace NzbDrone.Core.Notifications.Xbmc.Model
|
||||
{
|
||||
public class ArtistResponse
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string JsonRpc { get; set; }
|
||||
public ArtistResult Result { get; set; }
|
||||
}
|
||||
}
|
15
src/NzbDrone.Core/Notifications/Xbmc/Model/ArtistResult.cs
Normal file
15
src/NzbDrone.Core/Notifications/Xbmc/Model/ArtistResult.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Xbmc.Model
|
||||
{
|
||||
public class ArtistResult
|
||||
{
|
||||
public Dictionary<string, int> Limits { get; set; }
|
||||
public List<KodiArtist> Artists;
|
||||
|
||||
public ArtistResult()
|
||||
{
|
||||
Artists = new List<KodiArtist>();
|
||||
}
|
||||
}
|
||||
}
|
12
src/NzbDrone.Core/Notifications/Xbmc/Model/KodiArtist.cs
Normal file
12
src/NzbDrone.Core/Notifications/Xbmc/Model/KodiArtist.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Xbmc.Model
|
||||
{
|
||||
public class KodiArtist
|
||||
{
|
||||
public int ArtistId { get; set; }
|
||||
public string Label { get; set; }
|
||||
public List<string> MusicbrainzArtistId { get; set; }
|
||||
public string File { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
namespace NzbDrone.Core.Notifications.Xbmc.Model
|
||||
{
|
||||
public class TvShow
|
||||
{
|
||||
public int TvShowId { get; set; }
|
||||
public string Label { get; set; }
|
||||
public string ImdbNumber { get; set; }
|
||||
public string File { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
namespace NzbDrone.Core.Notifications.Xbmc.Model
|
||||
{
|
||||
public class TvShowResponse
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string JsonRpc { get; set; }
|
||||
public TvShowResult Result { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Xbmc.Model
|
||||
{
|
||||
public class TvShowResult
|
||||
{
|
||||
public Dictionary<string, int> Limits { get; set; }
|
||||
public List<TvShow> TvShows;
|
||||
|
||||
public TvShowResult()
|
||||
{
|
||||
TvShows = new List<TvShow>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
string UpdateLibrary(XbmcSettings settings, string path);
|
||||
void CleanLibrary(XbmcSettings settings);
|
||||
List<ActivePlayer> GetActivePlayers(XbmcSettings settings);
|
||||
List<TvShow> GetArtist(XbmcSettings settings);
|
||||
List<KodiArtist> GetArtist(XbmcSettings settings);
|
||||
}
|
||||
|
||||
public class XbmcJsonApiProxy : IXbmcJsonApiProxy
|
||||
|
@ -58,7 +58,7 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
parameters = null;
|
||||
}
|
||||
|
||||
var response = ProcessRequest(request, settings, "VideoLibrary.Scan", parameters);
|
||||
var response = ProcessRequest(request, settings, "AudioLibrary.Scan", parameters);
|
||||
|
||||
return Json.Deserialize<XbmcJsonResult<string>>(response).Result;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
{
|
||||
var request = new RestRequest();
|
||||
|
||||
ProcessRequest(request, settings, "VideoLibrary.Clean");
|
||||
ProcessRequest(request, settings, "AudioLibrary.Clean");
|
||||
}
|
||||
|
||||
public List<ActivePlayer> GetActivePlayers(XbmcSettings settings)
|
||||
|
@ -79,15 +79,15 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
return Json.Deserialize<ActivePlayersEdenResult>(response).Result;
|
||||
}
|
||||
|
||||
public List<TvShow> GetArtist(XbmcSettings settings)
|
||||
public List<KodiArtist> GetArtist(XbmcSettings settings)
|
||||
{
|
||||
var request = new RestRequest();
|
||||
var parameters = new Dictionary<string, object>();
|
||||
parameters.Add("properties", new[] { "file", "imdbnumber" });
|
||||
parameters.Add("properties", new[] { "musicbrainzartistid" }); //TODO: Figure out why AudioLibrary doesnt list file location like videoLibray
|
||||
|
||||
var response = ProcessRequest(request, settings, "VideoLibrary.GetTvShows", parameters);
|
||||
var response = ProcessRequest(request, settings, "AudioLibrary.GetArtists", parameters);
|
||||
|
||||
return Json.Deserialize<TvShowResponse>(response).Result.TvShows;
|
||||
return Json.Deserialize<ArtistResponse>(response).Result.Artists;
|
||||
}
|
||||
|
||||
private string ProcessRequest(IRestRequest request, XbmcSettings settings, string method, Dictionary<string, object> parameters = null)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.ComponentModel;
|
||||
using System.ComponentModel;
|
||||
using FluentValidation;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Core.Annotations;
|
||||
|
@ -51,7 +51,7 @@ namespace NzbDrone.Core.Notifications.Xbmc
|
|||
[FieldDefinition(7, Label = "Clean Library", HelpText = "Clean Library after update?", Type = FieldType.Checkbox)]
|
||||
public bool CleanLibrary { get; set; }
|
||||
|
||||
[FieldDefinition(8, Label = "Always Update", HelpText = "Update Library even when a video is playing?", Type = FieldType.Checkbox)]
|
||||
[FieldDefinition(8, Label = "Always Update", HelpText = "Update Library even when a file is playing?", Type = FieldType.Checkbox)]
|
||||
public bool AlwaysUpdate { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
|
|
|
@ -968,9 +968,9 @@
|
|||
<Compile Include="Notifications\Xbmc\Model\ActivePlayersDharmaResult.cs" />
|
||||
<Compile Include="Notifications\Xbmc\Model\ActivePlayersEdenResult.cs" />
|
||||
<Compile Include="Notifications\Xbmc\Model\ErrorResult.cs" />
|
||||
<Compile Include="Notifications\Xbmc\Model\TvShow.cs" />
|
||||
<Compile Include="Notifications\Xbmc\Model\TvShowResponse.cs" />
|
||||
<Compile Include="Notifications\Xbmc\Model\TvShowResult.cs" />
|
||||
<Compile Include="Notifications\Xbmc\Model\KodiArtist.cs" />
|
||||
<Compile Include="Notifications\Xbmc\Model\ArtistResponse.cs" />
|
||||
<Compile Include="Notifications\Xbmc\Model\ArtistResult.cs" />
|
||||
<Compile Include="Notifications\Xbmc\Model\VersionResult.cs" />
|
||||
<Compile Include="Notifications\Xbmc\Model\XbmcJsonResult.cs" />
|
||||
<Compile Include="Notifications\Xbmc\Model\XbmcVersion.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue