Added: Functionality to XBMC and Plex to update indivdual titles. Also: Notification Cleanup (#2240)

pull/2111/merge
fhscholl 7 years ago committed by Leonardo Galli
parent 32b1f75eb3
commit c7c423b13d

@ -19,29 +19,29 @@ namespace NzbDrone.Core.Test.NotificationTests
[SetUp]
public void SetUp()
{
_movie = new Movie()
_movie = new Movie
{
Path = @"C:\Test\".AsOsAgnostic()
};
_upgrade = new DownloadMessage()
_upgrade = new DownloadMessage
{
Movie = _movie,
MovieFile = new MovieFile
{
RelativePath = "file1.S01E01E02.mkv"
RelativePath = "moviefile1.mkv"
},
OldMovieFiles = new List<MovieFile>
{
new MovieFile
{
RelativePath = "file1.S01E01.mkv"
RelativePath = "oldmoviefile1.mkv"
},
new MovieFile
{
RelativePath = "file1.S01E02.mkv"
RelativePath = "oldmoviefile2.mkv"
}
}
};
@ -63,37 +63,37 @@ namespace NzbDrone.Core.Test.NotificationTests
Subject.OnMovieRename(_movie);
Mocker.GetMock<ISynologyIndexerProxy>()
.Verify(v => v.UpdateFolder(_movie.Path), Times.Never());
.Verify(v => v.UpdateFolder(_movie.Path), Times.Never());
}
[Test]
public void should_remove_old_episodes_on_upgrade()
public void should_remove_old_movie_on_upgrade()
{
Subject.OnDownload(_upgrade);
Mocker.GetMock<ISynologyIndexerProxy>()
.Verify(v => v.DeleteFile(@"C:\Test\file1.S01E01.mkv".AsOsAgnostic()), Times.Once());
.Verify(v => v.DeleteFile(@"C:\Test\oldmoviefile1.mkv".AsOsAgnostic()), Times.Once());
Mocker.GetMock<ISynologyIndexerProxy>()
.Verify(v => v.DeleteFile(@"C:\Test\file1.S01E02.mkv".AsOsAgnostic()), Times.Once());
.Verify(v => v.DeleteFile(@"C:\Test\oldmoviefile2.mkv".AsOsAgnostic()), Times.Once());
}
[Test]
public void should_add_new_episode_on_upgrade()
public void should_add_new_movie_on_upgrade()
{
Subject.OnDownload(_upgrade);
Mocker.GetMock<ISynologyIndexerProxy>()
.Verify(v => v.AddFile(@"C:\Test\file1.S01E01E02.mkv".AsOsAgnostic()), Times.Once());
.Verify(v => v.AddFile(@"C:\Test\moviefile1.mkv".AsOsAgnostic()), Times.Once());
}
[Test]
public void should_update_entire_series_folder_on_rename()
public void should_update_entire_movie_folder_on_rename()
{
Subject.OnMovieRename(_movie);
Mocker.GetMock<ISynologyIndexerProxy>()
.Verify(v => v.UpdateFolder(@"C:\Test\".AsOsAgnostic()), Times.Once());
.Verify(v => v.UpdateFolder(@"C:\Test\".AsOsAgnostic()), Times.Once());
}
}
}

@ -1,70 +0,0 @@
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Http;
using NzbDrone.Core.Notifications.Xbmc;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
{
[TestFixture]
public class ActivePlayersFixture : CoreTest<HttpApiProvider>
{
private XbmcSettings _settings;
private string _expectedUrl;
private void WithNoActivePlayers()
{
Mocker.GetMock<IHttpProvider>()
.Setup(s => s.DownloadString(_expectedUrl, _settings.Username, _settings.Password))
.Returns("<html><li>Filename:[Nothing Playing]</html>");
}
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>Time:00:06<li>Duration:21:35<li>Percentage:0<li>File size:183182590<li>Changed:True</html>";
Mocker.GetMock<IHttpProvider>()
.Setup(s => s.DownloadString(_expectedUrl, _settings.Username, _settings.Password))
.Returns(activePlayers);
}
[SetUp]
public void Setup()
{
_settings = new XbmcSettings
{
Host = "localhost",
Port = 8080,
Username = "xbmc",
Password = "xbmc",
AlwaysUpdate = false,
CleanLibrary = false,
UpdateLibrary = true
};
_expectedUrl = string.Format("http://{0}/xbmcCmds/xbmcHttp?command={1}", _settings.Address, "getcurrentlyplaying");
}
[Test]
public void _should_be_empty_when_no_active_players()
{
WithNoActivePlayers();
Subject.GetActivePlayers(_settings).Should().BeEmpty();
}
[Test]
public void should_have_active_video_player()
{
WithVideoPlayerActive();
var result = Subject.GetActivePlayers(_settings);
result.Should().HaveCount(1);
result.First().Type.Should().Be("video");
}
}
}

@ -1,35 +0,0 @@
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Notifications.Xbmc;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
{
[TestFixture]
public class CheckForErrorFixture : CoreTest<HttpApiProvider>
{
[Test]
public void should_be_true_when_the_response_contains_an_error()
{
const string response = "html><li>Error:Unknown command</html>";
Subject.CheckForError(response).Should().BeTrue();
}
[Test]
public void JsonError_true_empty_response()
{
var response = string.Empty;
Subject.CheckForError(response).Should().BeTrue();
}
[Test]
public void JsonError_false()
{
const string response = "html><li>Filename:[Nothing Playing]</html>";
Subject.CheckForError(response).Should().BeFalse();
}
}
}

@ -1,94 +0,0 @@
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Http;
using NzbDrone.Core.Notifications.Xbmc;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
{
[TestFixture]
public class GetSeriesPathFixture : CoreTest<HttpApiProvider>
{
private XbmcSettings _settings;
private Series _series;
[SetUp]
public void Setup()
{
_settings = new XbmcSettings
{
Host = "localhost",
Port = 8080,
Username = "xbmc",
Password = "xbmc",
AlwaysUpdate = false,
CleanLibrary = false,
UpdateLibrary = true
};
_series = new Series
{
TvdbId = 79488,
Title = "30 Rock"
};
const string setResponseUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=SetResponseFormat(webheader;false;webfooter;false;header;<xml>;footer;</xml>;opentag;<tag>;closetag;</tag>;closefinaltag;false)";
const string resetResponseUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=SetResponseFormat()";
Mocker.GetMock<IHttpProvider>()
.Setup(s => s.DownloadString(setResponseUrl, _settings.Username, _settings.Password))
.Returns("<xml><tag>OK</xml>");
Mocker.GetMock<IHttpProvider>()
.Setup(s => s.DownloadString(resetResponseUrl, _settings.Username, _settings.Password))
.Returns(@"<html>
<li>OK
</html>");
}
[Test]
public void should_get_series_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)");
Mocker.GetMock<IHttpProvider>()
.Setup(s => s.DownloadString(query, _settings.Username, _settings.Password))
.Returns(queryResult);
Subject.GetSeriesPath(_settings, _series)
.Should().Be("smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/");
}
[Test]
public void should_get_null_for_series_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)");
Mocker.GetMock<IHttpProvider>()
.Setup(s => s.DownloadString(query, _settings.Username, _settings.Password))
.Returns(queryResult);
Subject.GetSeriesPath(_settings, _series)
.Should().BeNull();
}
[Test]
public void should_get_series_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)");
Mocker.GetMock<IHttpProvider>()
.Setup(s => s.DownloadString(query, _settings.Username, _settings.Password))
.Returns(queryResult);
Subject.GetSeriesPath(_settings, _series)
.Should().Be("smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/");
}
}
}

@ -1,75 +0,0 @@
using FizzWare.NBuilder;
using NUnit.Framework;
using NzbDrone.Common.Http;
using NzbDrone.Core.Notifications.Xbmc;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Http
{
[TestFixture]
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 Series _fakeSeries;
[SetUp]
public void Setup()
{
_settings = new XbmcSettings
{
Host = "localhost",
Port = 8080,
Username = "xbmc",
Password = "xbmc",
AlwaysUpdate = false,
CleanLibrary = false,
UpdateLibrary = true
};
_fakeSeries = Builder<Series>.CreateNew()
.With(s => s.TvdbId = 79488)
.With(s => s.Title = "30 Rock")
.Build();
}
private void WithSeriesPath()
{
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>");
}
private void WithoutSeriesPath()
{
Mocker.GetMock<IHttpProvider>()
.Setup(s => s.DownloadString(_seriesQueryUrl, _settings.Username, _settings.Password))
.Returns("<xml></xml>");
}
[Test]
public void should_update_using_series_path()
{
WithSeriesPath();
const string url = "http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video,smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/))";
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadString(url, _settings.Username, _settings.Password));
Subject.Update(_settings, _fakeSeries);
Mocker.VerifyAllMocks();
}
[Test]
public void should_update_all_paths_when_series_path_not_found()
{
WithoutSeriesPath();
const string url = "http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video))";
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadString(url, _settings.Username, _settings.Password));
Subject.Update(_settings, _fakeSeries);
Mocker.VerifyAllMocks();
}
}
}

@ -0,0 +1,91 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Notifications.Xbmc;
using NzbDrone.Core.Notifications.Xbmc.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
{
[TestFixture]
public class GetMoviePathFixture : CoreTest<JsonApiProvider>
{
private const string IMDB_ID = "tt67890";
private XbmcSettings _settings;
private Movie _movie;
private List<XbmcMovie> _xbmcMovies;
[SetUp]
public void Setup()
{
_settings = Builder<XbmcSettings>.CreateNew()
.Build();
_xbmcMovies = Builder<XbmcMovie>.CreateListOfSize(3)
.All()
.With(s => s.ImdbNumber = "tt00000")
.TheFirst(1)
.With(s => s.ImdbNumber = IMDB_ID)
.Build()
.ToList();
Mocker.GetMock<IXbmcJsonApiProxy>()
.Setup(s => s.GetMovies(_settings))
.Returns(_xbmcMovies);
}
private void GivenMatchingImdbId()
{
_movie = new Movie
{
ImdbId = IMDB_ID,
Title = "Movie"
};
}
private void GivenMatchingTitle()
{
_movie = new Movie
{
ImdbId = "tt01000",
Title = _xbmcMovies.First().Label
};
}
private void GivenMatchingMovie()
{
_movie = new Movie
{
ImdbId = "tt01000",
Title = "Does not exist"
};
}
[Test]
public void should_return_null_when_movie_is_not_found()
{
GivenMatchingMovie();
Subject.GetMoviePath(_settings, _movie).Should().BeNull();
}
[Test]
public void should_return_path_when_tvdbId_matches()
{
GivenMatchingImdbId();
Subject.GetMoviePath(_settings, _movie).Should().Be(_xbmcMovies.First().File);
}
[Test]
public void should_return_path_when_title_matches()
{
GivenMatchingTitle();
Subject.GetMoviePath(_settings, _movie).Should().Be(_xbmcMovies.First().File);
}
}
}

@ -1,106 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Notifications.Xbmc;
using NzbDrone.Core.Notifications.Xbmc.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
{
[TestFixture]
public class GetSeriesPathFixture : CoreTest<JsonApiProvider>
{
private const int TVDB_ID = 5;
private XbmcSettings _settings;
private Series _series;
private List<TvShow> _xbmcSeries;
[SetUp]
public void Setup()
{
_settings = Builder<XbmcSettings>.CreateNew()
.Build();
_xbmcSeries = Builder<TvShow>.CreateListOfSize(3)
.All()
.With(s => s.ImdbNumber = "0")
.TheFirst(1)
.With(s => s.ImdbNumber = TVDB_ID.ToString())
.Build()
.ToList();
Mocker.GetMock<IXbmcJsonApiProxy>()
.Setup(s => s.GetSeries(_settings))
.Returns(_xbmcSeries);
}
private void GivenMatchingTvdbId()
{
_series = new Series
{
TvdbId = TVDB_ID,
Title = "TV Show"
};
}
private void GivenMatchingTitle()
{
_series = new Series
{
TvdbId = 1000,
Title = _xbmcSeries.First().Label
};
}
private void GivenMatchingSeries()
{
_series = new Series
{
TvdbId = 1000,
Title = "Does not exist"
};
}
[Test]
public void should_return_null_when_series_is_not_found()
{
GivenMatchingSeries();
Subject.GetSeriesPath(_settings, _series).Should().BeNull();
}
[Test]
public void should_return_path_when_tvdbId_matches()
{
GivenMatchingTvdbId();
Subject.GetSeriesPath(_settings, _series).Should().Be(_xbmcSeries.First().File);
}
[Test]
public void should_return_path_when_title_matches()
{
GivenMatchingTitle();
Subject.GetSeriesPath(_settings, _series).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 = TVDB_ID.ToString();
Mocker.GetMock<IXbmcJsonApiProxy>()
.Setup(s => s.GetSeries(_settings))
.Returns(_xbmcSeries);
Subject.GetSeriesPath(_settings, _series).Should().NotBeNull();
}
}
}

@ -1,68 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Notifications.Xbmc;
using NzbDrone.Core.Notifications.Xbmc.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
{
[TestFixture]
public class UpdateFixture : CoreTest<JsonApiProvider>
{
private const int TVDB_ID = 5;
private XbmcSettings _settings;
private List<TvShow> _xbmcSeries;
[SetUp]
public void Setup()
{
_settings = Builder<XbmcSettings>.CreateNew()
.Build();
_xbmcSeries = Builder<TvShow>.CreateListOfSize(3)
.TheFirst(1)
.With(s => s.ImdbNumber = TVDB_ID.ToString())
.Build()
.ToList();
Mocker.GetMock<IXbmcJsonApiProxy>()
.Setup(s => s.GetSeries(_settings))
.Returns(_xbmcSeries);
Mocker.GetMock<IXbmcJsonApiProxy>()
.Setup(s => s.GetActivePlayers(_settings))
.Returns(new List<ActivePlayer>());
}
[Test]
public void should_update_using_series_path()
{
var series = Builder<Series>.CreateNew()
.With(s => s.TvdbId = TVDB_ID)
.Build();
Subject.Update(_settings, series);
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()
{
var fakeSeries = Builder<Series>.CreateNew()
.With(s => s.TvdbId = 1000)
.With(s => s.Title = "Not 30 Rock")
.Build();
Subject.Update(_settings, fakeSeries);
Mocker.GetMock<IXbmcJsonApiProxy>()
.Verify(v => v.UpdateLibrary(_settings, null), Times.Once());
}
}
}

@ -0,0 +1,68 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Notifications.Xbmc;
using NzbDrone.Core.Notifications.Xbmc.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.NotificationTests.Xbmc.Json
{
[TestFixture]
public class UpdateMovieFixture : CoreTest<JsonApiProvider>
{
private const string IMDB_ID = "tt67890";
private XbmcSettings _settings;
private List<XbmcMovie> _xbmcMovies;
[SetUp]
public void Setup()
{
_settings = Builder<XbmcSettings>.CreateNew()
.Build();
_xbmcMovies = Builder<XbmcMovie>.CreateListOfSize(3)
.TheFirst(1)
.With(s => s.ImdbNumber = IMDB_ID)
.Build()
.ToList();
Mocker.GetMock<IXbmcJsonApiProxy>()
.Setup(s => s.GetMovies(_settings))
.Returns(_xbmcMovies);
Mocker.GetMock<IXbmcJsonApiProxy>()
.Setup(s => s.GetActivePlayers(_settings))
.Returns(new List<ActivePlayer>());
}
[Test]
public void should_update_using_movie_path()
{
var movie = Builder<Movie>.CreateNew()
.With(s => s.ImdbId = IMDB_ID)
.Build();
Subject.UpdateMovie(_settings, movie);
Mocker.GetMock<IXbmcJsonApiProxy>()
.Verify(v => v.UpdateLibrary(_settings, It.IsAny<string>()), Times.Once());
}
[Test]
public void should_update_all_paths_when_movie_path_not_found()
{
var fakeMovie = Builder<Movie>.CreateNew()
.With(s => s.ImdbId = "tt01000")
.With(s => s.Title = "Not A Real Movie")
.Build();
Subject.UpdateMovie(_settings, fakeMovie);
Mocker.GetMock<IXbmcJsonApiProxy>()
.Verify(v => v.UpdateLibrary(_settings, null), Times.Once());
}
}
}

@ -41,8 +41,8 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc
private void GivenOldFiles()
{
_downloadMessage.OldMovieFiles = Builder<MovieFile>.CreateListOfSize(1)
.Build()
.ToList();
.Build()
.ToList();
Subject.Definition.Settings = new XbmcSettings
{
@ -52,7 +52,7 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc
}
[Test]
public void should_not_clean_if_no_episode_was_replaced()
public void should_not_clean_if_no_movie_was_replaced()
{
Subject.OnDownload(_downloadMessage);
@ -60,7 +60,7 @@ namespace NzbDrone.Core.Test.NotificationTests.Xbmc
}
[Test]
public void should_clean_if_episode_was_replaced()
public void should_clean_if_movie_was_replaced()
{
GivenOldFiles();
Subject.OnDownload(_downloadMessage);

@ -317,12 +317,6 @@
<Compile Include="Metadata\Consumers\Wdtv\FindMetadataFileFixture.cs" />
<Compile Include="NotificationTests\PlexClientServiceTest.cs" />
<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\UpdateFixture.cs" />
<Compile Include="NotificationTests\Xbmc\Json\GetSeriesPathFixture.cs" />
<Compile Include="NotificationTests\Xbmc\Json\UpdateFixture.cs" />
<Compile Include="NotificationTests\Xbmc\OnDownloadFixture.cs" />
<Compile Include="OrganizerTests\BuildFilePathFixture.cs" />
<Compile Include="OrganizerTests\GetSeasonFolderFixture.cs" />
@ -395,6 +389,8 @@
<None Include="Files\Indexers\PTP\imdbsearch.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Compile Include="NotificationTests\Xbmc\Json\GetMoviePathFixture.cs" />
<Compile Include="NotificationTests\Xbmc\Json\UpdateMovieFixture.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Marr.Data\Marr.Data.csproj">

@ -34,10 +34,6 @@ namespace NzbDrone.Core.Notifications.Boxcar
{
}
public override void OnRename(Series series)
{
}
public override string Name => "Boxcar";
public override bool SupportsOnRename => false;

@ -96,10 +96,6 @@ namespace NzbDrone.Core.Notifications.CustomScript
ExecuteScript(environmentVariables);
}
public override void OnRename(Series series)
{
}
public override string Name => "Custom Script";
public override ValidationResult Test()

@ -7,10 +7,7 @@ namespace NzbDrone.Core.Notifications
public class DownloadMessage
{
public string Message { get; set; }
public Series Series { get; set; }
public Movie Movie { get; set; }
public EpisodeFile EpisodeFile { get; set; }
public List<EpisodeFile> OldFiles { get; set; }
public MovieFile MovieFile { get; set; }
public List<MovieFile> OldMovieFiles { get; set; }
public string SourcePath { get; set; }

@ -36,10 +36,6 @@ namespace NzbDrone.Core.Notifications.Email
{
}
public override void OnRename(Series series)
{
}
public override string Name => "Email";
public override bool SupportsOnRename => false;

@ -7,10 +7,8 @@ namespace NzbDrone.Core.Notifications
public class GrabMessage
{
public string Message { get; set; }
public Series Series { get; set; }
public Movie Movie { get; set; }
public RemoteMovie RemoteMovie { get; set; }
public RemoteEpisode Episode { get; set; }
public QualityModel Quality { get; set; }
public override string ToString()

@ -34,10 +34,6 @@ namespace NzbDrone.Core.Notifications.Growl
{
}
public override void OnRename(Series series)
{
}
public override string Name => "Growl";
public override bool SupportsOnRename => false;

@ -133,8 +133,8 @@ namespace NzbDrone.Core.Notifications.Growl
{
var notificationTypes = new List<NotificationType>();
notificationTypes.Add(new NotificationType("TEST", "Test"));
notificationTypes.Add(new NotificationType("GRAB", "Episode Grabbed"));
notificationTypes.Add(new NotificationType("DOWNLOAD", "Episode Complete"));
notificationTypes.Add(new NotificationType("GRAB", "Movie Grabbed"));
notificationTypes.Add(new NotificationType("DOWNLOAD", "Movie Complete"));
return notificationTypes.ToArray();
}

@ -9,7 +9,6 @@ namespace NzbDrone.Core.Notifications
void OnGrab(GrabMessage grabMessage);
void OnDownload(DownloadMessage message);
void OnRename(Series series);
void OnMovieRename(Movie movie);
bool SupportsOnGrab { get; }
bool SupportsOnDownload { get; }

@ -34,10 +34,6 @@ namespace NzbDrone.Core.Notifications.Join
{
}
public override void OnRename(Series series)
{
}
public override string Name => "Join";
public override bool SupportsOnRename => false;

@ -49,14 +49,6 @@ namespace NzbDrone.Core.Notifications.MediaBrowser
}
}
public override void OnRename(Series series)
{
if (Settings.UpdateLibrary)
{
_mediaBrowserService.Update(Settings, series);
}
}
public override string Name => "Emby (Media Browser)";
public override ValidationResult Test()

@ -31,16 +31,6 @@ namespace NzbDrone.Core.Notifications.MediaBrowser
ProcessRequest(request, settings);
}
public void Update(MediaBrowserSettings settings, int tvdbId)
{
var path = string.Format("/Library/Series/Updated?tvdbid={0}", tvdbId);
var request = BuildRequest(path, settings);
request.Headers.Add("Content-Length", "0");
ProcessRequest(request, settings);
}
public void UpdateMovies(MediaBrowserSettings settings, string imdbid)
{
var path = string.Format("/Library/Movies/Updated?ImdbId={0}", imdbid);

@ -10,7 +10,6 @@ namespace NzbDrone.Core.Notifications.MediaBrowser
public interface IMediaBrowserService
{
void Notify(MediaBrowserSettings settings, string title, string message);
void Update(MediaBrowserSettings settings, Series series);
void UpdateMovies(MediaBrowserSettings settings, Movie movie);
ValidationFailure Test(MediaBrowserSettings settings);
}
@ -31,12 +30,6 @@ namespace NzbDrone.Core.Notifications.MediaBrowser
_proxy.Notify(settings, title, message);
}
public void Update(MediaBrowserSettings settings, Series series)
{
_proxy.Update(settings, series.TvdbId);
}
public void UpdateMovies(MediaBrowserSettings settings, Movie movie)
{
_proxy.UpdateMovies(settings, movie.ImdbId);

@ -26,7 +26,6 @@ namespace NzbDrone.Core.Notifications
public abstract void OnGrab(GrabMessage grabMessage);
public abstract void OnDownload(DownloadMessage message);
public abstract void OnRename(Series series);
public abstract void OnMovieRename(Movie movie);
public virtual bool SupportsOnGrab => true;

@ -30,47 +30,6 @@ namespace NzbDrone.Core.Notifications
_logger = logger;
}
private string GetMessage(Series series, List<Episode> episodes, QualityModel quality)
{
var qualityString = quality.Quality.ToString();
if (quality.Revision.Version > 1)
{
if (series.SeriesType == SeriesTypes.Anime)
{
qualityString += " v" + quality.Revision.Version;
}
else
{
qualityString += " Proper";
}
}
if (series.SeriesType == SeriesTypes.Daily)
{
var episode = episodes.First();
return string.Format("{0} - {1} - {2} [{3}]",
series.Title,
episode.AirDate,
episode.Title,
qualityString);
}
var episodeNumbers = string.Concat(episodes.Select(e => e.EpisodeNumber)
.Select(i => string.Format("x{0:00}", i)));
var episodeTitles = string.Join(" + ", episodes.Select(e => e.Title));
return string.Format("{0} - {1}{2} - {3} [{4}]",
series.Title,
episodes.First().SeasonNumber,
episodeNumbers,
episodeTitles,
qualityString);
}
private string GetMessage(Movie movie, QualityModel quality)
{
var qualityString = quality.Quality.ToString();
@ -100,7 +59,7 @@ namespace NzbDrone.Core.Notifications
if (notificationDefinition.Tags.Intersect(movie.Tags).Any())
{
_logger.Debug("Notification and series have one or more matching tags.");
_logger.Debug("Notification and movie have one or more matching tags.");
return true;
}
@ -109,49 +68,9 @@ namespace NzbDrone.Core.Notifications
return false;
}
private bool ShouldHandleSeries(ProviderDefinition definition, Series series)
{
var notificationDefinition = (NotificationDefinition) definition;
if (notificationDefinition.Tags.Empty())
{
_logger.Debug("No tags set for this notification.");
return true;
}
if (notificationDefinition.Tags.Intersect(series.Tags).Any())
{
_logger.Debug("Notification and series have one or more matching tags.");
return true;
}
//TODO: this message could be more clear
_logger.Debug("{0} does not have any tags that match {1}'s tags", notificationDefinition.Name, series.Title);
return false;
}
public void Handle(EpisodeGrabbedEvent message)
{
var grabMessage = new GrabMessage {
Message = GetMessage(message.Episode.Series, message.Episode.Episodes, message.Episode.ParsedEpisodeInfo.Quality),
Series = message.Episode.Series,
Quality = message.Episode.ParsedEpisodeInfo.Quality,
Episode = message.Episode
};
foreach (var notification in _notificationFactory.OnGrabEnabled())
{
try
{
if (!ShouldHandleSeries(notification.Definition, message.Episode.Series)) continue;
notification.OnGrab(grabMessage);
}
catch (Exception ex)
{
_logger.Error(ex, "Unable to send OnGrab notification to: " + notification.Definition.Name);
}
}
throw new NotImplementedException("Remove Series/Season/Episode");
}
public void Handle(MovieGrabbedEvent message)
@ -159,9 +78,7 @@ namespace NzbDrone.Core.Notifications
var grabMessage = new GrabMessage
{
Message = GetMessage(message.Movie.Movie, message.Movie.ParsedMovieInfo.Quality),
Series = null,
Quality = message.Movie.ParsedMovieInfo.Quality,
Episode = null,
Movie = message.Movie.Movie,
RemoteMovie = message.Movie
};
@ -183,42 +100,15 @@ namespace NzbDrone.Core.Notifications
public void Handle(EpisodeDownloadedEvent message)
{
var downloadMessage = new DownloadMessage();
downloadMessage.Message = GetMessage(message.Episode.Series, message.Episode.Episodes, message.Episode.Quality);
downloadMessage.Series = message.Episode.Series;
downloadMessage.EpisodeFile = message.EpisodeFile;
downloadMessage.OldFiles = message.OldFiles;
downloadMessage.SourcePath = message.Episode.Path;
foreach (var notification in _notificationFactory.OnDownloadEnabled())
{
try
{
if (ShouldHandleSeries(notification.Definition, message.Episode.Series))
{
if (downloadMessage.OldFiles.Empty() || ((NotificationDefinition)notification.Definition).OnUpgrade)
{
notification.OnDownload(downloadMessage);
}
}
}
catch (Exception ex)
{
_logger.Warn(ex, "Unable to send OnDownload notification to: " + notification.Definition.Name);
}
}
throw new NotImplementedException("Remove Series/Season/Episode");
}
public void Handle(MovieDownloadedEvent message)
{
var downloadMessage = new DownloadMessage();
downloadMessage.Message = GetMessage(message.Movie.Movie, message.Movie.Quality);
downloadMessage.Series = null;
downloadMessage.EpisodeFile = null;
downloadMessage.MovieFile = message.MovieFile;
downloadMessage.Movie = message.Movie.Movie;
downloadMessage.OldFiles = null;
downloadMessage.OldMovieFiles = message.OldFiles;
downloadMessage.SourcePath = message.Movie.Path;
downloadMessage.DownloadId = message.DownloadId;
@ -245,21 +135,7 @@ namespace NzbDrone.Core.Notifications
public void Handle(SeriesRenamedEvent message)
{
foreach (var notification in _notificationFactory.OnRenameEnabled())
{
try
{
if (ShouldHandleSeries(notification.Definition, message.Series))
{
notification.OnRename(message.Series);
}
}
catch (Exception ex)
{
_logger.Warn(ex, "Unable to send OnRename notification to: " + notification.Definition.Name);
}
}
throw new NotImplementedException("Remove Series/Season/Episode");
}
public void Handle(MovieRenamedEvent message)

@ -35,10 +35,6 @@ namespace NzbDrone.Core.Notifications.NotifyMyAndroid
{
}
public override void OnRename(Series series)
{
}
public override string Name => "Notify My Android";
public override bool SupportsOnRename => false;

@ -32,10 +32,6 @@ namespace NzbDrone.Core.Notifications.Plex
{
}
public override void OnRename(Series series)
{
}
public override string Name => "Plex Media Center";
public override bool SupportsOnRename => false;

@ -39,11 +39,6 @@ namespace NzbDrone.Core.Notifications.Plex
{
}
public override void OnRename(Series series)
{
}
public override string Name => "Plex Home Theater";
public override bool SupportsOnRename => false;

@ -30,11 +30,6 @@ namespace NzbDrone.Core.Notifications.Plex
UpdateIfEnabled(movie);
}
public override void OnRename(Series series)
{
//UpdateIfEnabled(movie);
}
private void UpdateIfEnabled(Movie movie)
{
if (Settings.UpdateLibrary)

@ -19,10 +19,10 @@ namespace NzbDrone.Core.Notifications.Plex
List<PlexSection> GetTvSections(PlexServerSettings settings);
List<PlexSection> GetMovieSections(PlexServerSettings settings);
void Update(int sectionId, PlexServerSettings settings);
void UpdateSeries(int metadataId, PlexServerSettings settings);
void UpdateItem(int metadataId, PlexServerSettings settings);
string Version(PlexServerSettings settings);
List<PlexPreference> Preferences(PlexServerSettings settings);
int? GetMetadataId(int sectionId, int tvdbId, string language, PlexServerSettings settings);
int? GetMetadataId(int sectionId, string imdbId, string language, PlexServerSettings settings);
}
public class PlexServerProxy : IPlexServerProxy
@ -109,14 +109,14 @@ namespace NzbDrone.Core.Notifications.Plex
CheckForError(response, settings);
}
public void UpdateSeries(int metadataId, PlexServerSettings settings)
public void UpdateItem(int metadataId, PlexServerSettings settings)
{
var resource = string.Format("library/metadata/{0}/refresh", metadataId);
var request = GetPlexServerRequest(resource, Method.PUT, settings);
var client = GetPlexServerClient(settings);
var response = client.Execute(request);
_logger.Trace("Update Series response: {0}", response.Content);
_logger.Trace("Update Item response: {0}", response.Content);
CheckForError(response, settings);
}
@ -160,9 +160,9 @@ namespace NzbDrone.Core.Notifications.Plex
.Preferences;
}
public int? GetMetadataId(int sectionId, int tvdbId, string language, PlexServerSettings settings)
public int? GetMetadataId(int sectionId, string imdbId, string language, PlexServerSettings settings)
{
var guid = string.Format("com.plexapp.agents.thetvdb://{0}?lang={1}", tvdbId, language);
var guid = string.Format("com.plexapp.agents.imdb://{0}?lang={1}", imdbId, language);
var resource = string.Format("library/sections/{0}/all?guid={1}", sectionId, System.Web.HttpUtility.UrlEncode(guid));
var request = GetPlexServerRequest(resource, Method.GET, settings);
var client = GetPlexServerClient(settings);

@ -13,7 +13,6 @@ namespace NzbDrone.Core.Notifications.Plex
{
public interface IPlexServerService
{
void UpdateLibrary(Series series, PlexServerSettings settings);
void UpdateMovieSections(Movie movie, PlexServerSettings settings);
ValidationFailure Test(PlexServerSettings settings);
}
@ -33,7 +32,7 @@ namespace NzbDrone.Core.Notifications.Plex
_logger = logger;
}
public void UpdateLibrary(Series series, PlexServerSettings settings)
public void UpdateMovieSections(Movie movie, PlexServerSettings settings)
{
try
{
@ -47,7 +46,7 @@ namespace NzbDrone.Core.Notifications.Plex
if (partialUpdates)
{
UpdatePartialSection(series, sections, settings);
UpdatePartialSection(movie, sections, settings);
}
else
@ -56,38 +55,6 @@ namespace NzbDrone.Core.Notifications.Plex
}
}
catch(Exception ex)
{
_logger.Warn(ex, "Failed to Update Plex host: " + settings.Host);
throw;
}
}
public void UpdateMovieSections(Movie movie, PlexServerSettings settings)
{
try
{
_logger.Debug("Sending Update Request to Plex Server");
var version = _versionCache.Get(settings.Host, () => GetVersion(settings), TimeSpan.FromHours(2));
ValidateVersion(version);
var sections = GetSections(settings);
var partialUpdates = _partialUpdateCache.Get(settings.Host, () => PartialUpdatesAllowed(settings, version), TimeSpan.FromHours(2));
// TODO: Investiate partial updates later, for now just update all movie sections...
//if (partialUpdates)
//{
// UpdatePartialSection(series, sections, settings);
//}
//else
//{
sections.ForEach(s => UpdateSection(s.Id, settings));
//}
}
catch (Exception ex)
{
_logger.Warn(ex, "Failed to Update Plex host: " + settings.Host);
@ -163,18 +130,18 @@ namespace NzbDrone.Core.Notifications.Plex
_plexServerProxy.Update(sectionId, settings);
}
private void UpdatePartialSection(Series series, List<PlexSection> sections, PlexServerSettings settings)
private void UpdatePartialSection(Movie movie, List<PlexSection> sections, PlexServerSettings settings)
{
var partiallyUpdated = false;
foreach (var section in sections)
{
var metadataId = GetMetadataId(section.Id, series, section.Language, settings);
var metadataId = GetMetadataId(section.Id, movie, section.Language, settings);
if (metadataId.HasValue)
{
_logger.Debug("Updating Plex host: {0}, Section: {1}, Series: {2}", settings.Host, section.Id, series);
_plexServerProxy.UpdateSeries(metadataId.Value, settings);
_logger.Debug("Updating Plex host: {0}, Section: {1}, Movie: {2}", settings.Host, section.Id, movie);
_plexServerProxy.UpdateItem(metadataId.Value, settings);
partiallyUpdated = true;
}
@ -188,11 +155,11 @@ namespace NzbDrone.Core.Notifications.Plex
}
}
private int? GetMetadataId(int sectionId, Series series, string language, PlexServerSettings settings)
private int? GetMetadataId(int sectionId, Movie movie, string language, PlexServerSettings settings)
{
_logger.Debug("Getting metadata from Plex host: {0} for series: {1}", settings.Host, series);
_logger.Debug("Getting metadata from Plex host: {0} for movie: {1}", settings.Host, movie);
return _plexServerProxy.GetMetadataId(sectionId, series.TvdbId, language, settings);
return _plexServerProxy.GetMetadataId(sectionId, movie.ImdbId, language, settings);
}
public ValidationFailure Test(PlexServerSettings settings)

@ -35,10 +35,6 @@ namespace NzbDrone.Core.Notifications.Prowl
{
}
public override void OnRename(Series series)
{
}
public override string Name => "Prowl";
public override bool SupportsOnRename => false;

@ -33,10 +33,6 @@ namespace NzbDrone.Core.Notifications.PushBullet
public override void OnMovieRename(Movie movie)
{
}
public override void OnRename(Series series)
{
}
public override string Name => "Pushbullet";

@ -34,10 +34,6 @@ namespace NzbDrone.Core.Notifications.Pushalot
{
}
public override void OnRename(Series series)
{
}
public override string Name => "Pushalot";
public override bool SupportsOnRename => false;

@ -34,10 +34,6 @@ namespace NzbDrone.Core.Notifications.Pushover
{
}
public override void OnRename(Series series)
{
}
public override string Name => "Pushover";
public override bool SupportsOnRename => false;

@ -78,21 +78,6 @@ namespace NzbDrone.Core.Notifications.Slack
_proxy.SendPayload(payload, Settings);
}
public override void OnRename(Series series)
{
var attachments = new List<Attachment>
{
new Attachment
{
Title = series.Title,
}
};
var payload = CreatePayload("Renamed", attachments);
_proxy.SendPayload(payload, Settings);
}
public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();

@ -50,14 +50,6 @@ namespace NzbDrone.Core.Notifications.Synology
}
}
public override void OnRename(Series series)
{
if (Settings.UpdateLibrary)
{
_indexerProxy.UpdateFolder(series.Path);
}
}
public override string Name => "Synology Indexer";
public override ValidationResult Test()

@ -34,10 +34,6 @@ namespace NzbDrone.Core.Notifications.Telegram
{
}
public override void OnRename(Series series)
{
}
public override string Name => "Telegram";
public override bool SupportsOnRename => false;

@ -33,10 +33,6 @@ namespace NzbDrone.Core.Notifications.Twitter
{
}
public override void OnRename(Series series)
{
}
public override object RequestAction(string action, IDictionary<string, string> query)
{
if (action == "startOAuth")

@ -61,10 +61,6 @@ namespace NzbDrone.Core.Notifications.Webhook
_proxy.SendWebhook(payload, Settings);
}
public override void OnRename(Series series)
{
}
public override string Name => "Webhook";
public override ValidationResult Test()

@ -1,6 +1,8 @@
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Rest;
using System;
using System.Text;
namespace NzbDrone.Core.Notifications.Webhook
{
@ -30,6 +32,13 @@ namespace NzbDrone.Core.Notifications.Webhook
request.Headers.ContentType = "application/json";
request.SetContent(body.ToJson());
if (!String.IsNullOrEmpty(settings.Username) || !String.IsNullOrEmpty(settings.Password))
{
var authInfo = settings.Username + ":" + settings.Password;
authInfo = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(authInfo));
request.Headers.Set("Authorization", "Basic " + authInfo);
}
_httpClient.Execute(request);
}
catch (RestException ex)

@ -29,6 +29,12 @@ namespace NzbDrone.Core.Notifications.Webhook
[FieldDefinition(1, Label = "Method", Type = FieldType.Select, SelectOptions = typeof(WebhookMethod), HelpText = "Which HTTP method to use submit to the Webservice")]
public int Method { get; set; }
[FieldDefinition(2, Label = "Username")]
public string Username { get; set; }
[FieldDefinition(3, Label = "Password", Type = FieldType.Password)]
public string Password { get; set; }
public NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));

@ -1,236 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using NLog;
using NzbDrone.Common.Http;
using NzbDrone.Core.Notifications.Xbmc.Model;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Notifications.Xbmc
{
public class HttpApiProvider : IApiProvider
{
private readonly IHttpProvider _httpProvider;
private readonly Logger _logger;
public HttpApiProvider(IHttpProvider httpProvider, Logger logger)
{
_httpProvider = httpProvider;
_logger = logger;
}
public bool CanHandle(XbmcVersion version)
{
return version < new XbmcVersion(5);
}
public void Notify(XbmcSettings settings, string title, string message)
{
var notification = string.Format("Notification({0},{1},{2},{3})", title, message, settings.DisplayTime * 1000, "https://raw.github.com/Radarr/Radarr/develop/Logo/64.png");
var command = BuildExecBuiltInCommand(notification);
SendCommand(settings, command);
}
public void Update(XbmcSettings settings, Series series)
{
if (!settings.AlwaysUpdate)
{
_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")))
{
_logger.Debug("Video is currently playing, skipping library update");
return;
}
}
UpdateLibrary(settings, series);
}
public void UpdateMovie(XbmcSettings settings, Movie movie)
{
if (!settings.AlwaysUpdate)
{
_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")))
{
_logger.Debug("Video is currently playing, skipping library update");
return;
}
}
UpdateMovieLibrary(settings, movie);
}
public void Clean(XbmcSettings settings)
{
const string cleanVideoLibrary = "CleanLibrary(video)";
var command = BuildExecBuiltInCommand(cleanVideoLibrary);
SendCommand(settings, command);
}
internal List<ActivePlayer> GetActivePlayers(XbmcSettings settings)
{
try
{
var result = new List<ActivePlayer>();
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"));
return result;
}
catch (Exception ex)
{
_logger.Debug(ex, ex.Message);
}
return new List<ActivePlayer>();
}
internal string GetSeriesPath(XbmcSettings settings, Series series)
{
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",
series.TvdbId);
var command = string.Format("QueryVideoDatabase({0})", query);
const string setResponseCommand =
"SetResponseFormat(webheader;false;webfooter;false;header;<xml>;footer;</xml>;opentag;<tag>;closetag;</tag>;closefinaltag;false)";
const string resetResponseCommand = "SetResponseFormat()";
SendCommand(settings, setResponseCommand);
var response = SendCommand(settings, command);
SendCommand(settings, resetResponseCommand);
if (string.IsNullOrEmpty(response))
return string.Empty;
var xDoc = XDocument.Load(new StringReader(response.Replace("&", "&amp;")));
var xml = xDoc.Descendants("xml").Select(x => x).FirstOrDefault();
if (xml == null)
return null;
var field = xml.Descendants("field").FirstOrDefault();
if (field == null)
return null;
return field.Value;
}
internal bool CheckForError(string response)
{
_logger.Debug("Looking for error in response: {0}", response);
if (string.IsNullOrWhiteSpace(response))
{
_logger.Debug("Invalid response from XBMC, the response is not valid JSON");
return true;
}
var errorIndex = response.IndexOf("Error", StringComparison.InvariantCultureIgnoreCase);
if (errorIndex > -1)
{
var errorMessage = response.Substring(errorIndex + 6);
errorMessage = errorMessage.Substring(0, errorMessage.IndexOfAny(new char[] { '<', ';' }));
_logger.Debug("Error found in response: {0}", errorMessage);
return true;
}
return false;
}
private void UpdateLibrary(XbmcSettings settings, Series series)
{
try
{
_logger.Debug("Sending Update DB Request to XBMC Host: {0}", settings.Address);
var xbmcSeriesPath = GetSeriesPath(settings, series);
//If the path is found update it, else update the whole library
if (!string.IsNullOrEmpty(xbmcSeriesPath))
{
_logger.Debug("Updating series [{0}] on XBMC host: {1}", series, settings.Address);
var command = BuildExecBuiltInCommand(string.Format("UpdateLibrary(video,{0})", xbmcSeriesPath));
SendCommand(settings, command);
}
else
{
//Update the entire library
_logger.Debug("Series [{0}] doesn't exist on XBMC host: {1}, Updating Entire Library", series, settings.Address);
var command = BuildExecBuiltInCommand("UpdateLibrary(video)");
SendCommand(settings, command);
}
}
catch (Exception ex)
{
_logger.Debug(ex, ex.Message);
}
}
private void UpdateMovieLibrary(XbmcSettings settings, Movie movie)
{
try
{
//_logger.Debug("Sending Update DB Request to XBMC Host: {0}", settings.Address);
//var xbmcSeriesPath = GetSeriesPath(settings, series);
////If the path is found update it, else update the whole library
//if (!string.IsNullOrEmpty(xbmcSeriesPath))
//{
// _logger.Debug("Updating series [{0}] on XBMC host: {1}", series, settings.Address);
// var command = BuildExecBuiltInCommand(string.Format("UpdateLibrary(video,{0})", xbmcSeriesPath));
// SendCommand(settings, command);
//}
//else
//{
//Update the entire library
_logger.Debug("Series [{0}] doesn't exist on XBMC host: {1}, Updating Entire Library", movie, settings.Address);
var command = BuildExecBuiltInCommand("UpdateLibrary(video)");
SendCommand(settings, command);
//}
}
catch (Exception ex)
{
_logger.Debug(ex, ex.Message);
}
}
private string SendCommand(XbmcSettings settings, string command)
{
var url = string.Format("http://{0}/xbmcCmds/xbmcHttp?command={1}", settings.Address, command);
if (!string.IsNullOrEmpty(settings.Username))
{
return _httpProvider.DownloadString(url, settings.Username, settings.Password);
}
return _httpProvider.DownloadString(url);
}
private string BuildExecBuiltInCommand(string command)
{
return string.Format("ExecBuiltIn({0})", command);
}
}
}

@ -6,7 +6,6 @@ namespace NzbDrone.Core.Notifications.Xbmc
public interface IApiProvider
{
void Notify(XbmcSettings settings, string title, string message);
void Update(XbmcSettings settings, Series series);
void UpdateMovie(XbmcSettings settings, Movie movie);
void Clean(XbmcSettings settings);
bool CanHandle(XbmcVersion version);

@ -28,23 +28,6 @@ namespace NzbDrone.Core.Notifications.Xbmc
_proxy.Notify(settings, title, message);
}
public void Update(XbmcSettings settings, Series series)
{
if (!settings.AlwaysUpdate)
{
_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")))
{
_logger.Debug("Video is currently playing, skipping library update");
return;
}
}
UpdateLibrary(settings, series);
}
public void UpdateMovie(XbmcSettings settings, Movie movie)
{
if (!settings.AlwaysUpdate)
@ -73,65 +56,45 @@ namespace NzbDrone.Core.Notifications.Xbmc
return _proxy.GetActivePlayers(settings);
}
public string GetSeriesPath(XbmcSettings settings, Series series)
public string GetMoviePath(XbmcSettings settings, Movie movie)
{
var allSeries = _proxy.GetSeries(settings);
var allMovies = _proxy.GetMovies(settings);
if (!allSeries.Any())
if (!allMovies.Any())
{
_logger.Debug("No TV shows returned from XBMC");
_logger.Debug("No Movies returned from XBMC");
return null;
}
var matchingSeries = allSeries.FirstOrDefault(s =>
var matchingMovies = allMovies.FirstOrDefault(s =>
{
var tvdbId = 0;
int.TryParse(s.ImdbNumber, out tvdbId);
return s.ImdbNumber == movie.ImdbId || s.Label == movie.Title;
return tvdbId == series.TvdbId || s.Label == series.Title;
});
if (matchingSeries != null) return matchingSeries.File;
if (matchingMovies != null) return matchingMovies.File;
return null;
}
private void UpdateLibrary(XbmcSettings settings, Series series)
private void UpdateMovieLibrary(XbmcSettings settings, Movie movie)
{
try
{
var seriesPath = GetSeriesPath(settings, series);
var moviePath = GetMoviePath(settings, movie);
if (seriesPath != null)
if (moviePath != null)
{
_logger.Debug("Updating series {0} (Path: {1}) on XBMC host: {2}", series, seriesPath, settings.Address);
_logger.Debug("Updating movie {0} (Path: {1}) on XBMC host: {2}", movie, moviePath, settings.Address);
}
else
{
_logger.Debug("Series {0} doesn't exist on XBMC host: {1}, Updating Entire Library", series,
_logger.Debug("Movie {0} doesn't exist on XBMC host: {1}, Updating Entire Library", movie,
settings.Address);
}
var response = _proxy.UpdateLibrary(settings, seriesPath);
if (!response.Equals("OK", StringComparison.InvariantCultureIgnoreCase))
{
_logger.Debug("Failed to update library for: {0}", settings.Address);
}
}
catch (Exception ex)
{
_logger.Debug(ex, ex.Message);
}
}
private void UpdateMovieLibrary(XbmcSettings settings, Movie movie)
{
try
{
var response = _proxy.UpdateLibrary(settings, null);
var response = _proxy.UpdateLibrary(settings, moviePath);
if (!response.Equals("OK", StringComparison.InvariantCultureIgnoreCase))
{

@ -1,9 +1,9 @@
namespace NzbDrone.Core.Notifications.Xbmc.Model
{
public class TvShowResponse
public class MovieResponse
{
public string Id { get; set; }
public string JsonRpc { get; set; }
public TvShowResult Result { get; set; }
public MovieResult Result { get; set; }
}
}

@ -2,14 +2,14 @@
namespace NzbDrone.Core.Notifications.Xbmc.Model
{
public class TvShowResult
public class MovieResult
{
public Dictionary<string, int> Limits { get; set; }
public List<TvShow> TvShows;
public List<XbmcMovie> Movies;
public TvShowResult()
public MovieResult()
{
TvShows = new List<TvShow>();
Movies = new List<XbmcMovie>();
}
}
}

@ -1,8 +1,8 @@
namespace NzbDrone.Core.Notifications.Xbmc.Model
{
public class TvShow
public class XbmcMovie
{
public int TvShowId { get; set; }
public int movieId { get; set; }
public string Label { get; set; }
public string ImdbNumber { get; set; }
public string File { get; set; }

@ -41,11 +41,6 @@ namespace NzbDrone.Core.Notifications.Xbmc
UpdateAndCleanMovie(movie);
}
public override void OnRename(Series series)
{
UpdateAndClean(series);
}
public override string Name => "Kodi (XBMC)";
public override ValidationResult Test()
@ -73,27 +68,6 @@ namespace NzbDrone.Core.Notifications.Xbmc
}
}
private void UpdateAndClean(Series series, bool clean = true)
{
try
{
if (Settings.UpdateLibrary)
{
_xbmcService.Update(Settings, series);
}
if (clean && Settings.CleanLibrary)
{
_xbmcService.Clean(Settings);
}
}
catch (SocketException ex)
{
var logMessage = string.Format("Unable to connect to XBMC Host: {0}:{1}", Settings.Host, Settings.Port);
_logger.Debug(ex, logMessage);
}
}
private void UpdateAndCleanMovie(Movie movie, bool clean = true)
{
try

@ -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> GetSeries(XbmcSettings settings);
List<XbmcMovie> GetMovies(XbmcSettings settings);
}
public class XbmcJsonApiProxy : IXbmcJsonApiProxy
@ -79,15 +79,15 @@ namespace NzbDrone.Core.Notifications.Xbmc
return Json.Deserialize<ActivePlayersEdenResult>(response).Result;
}
public List<TvShow> GetSeries(XbmcSettings settings)
public List<XbmcMovie> GetMovies(XbmcSettings settings)
{
var request = new RestRequest();
var parameters = new Dictionary<string, object>();
parameters.Add("properties", new[] { "file", "imdbnumber" });
var response = ProcessRequest(request, settings, "VideoLibrary.GetTvShows", parameters);
var response = ProcessRequest(request, settings, "VideoLibrary.GetMovies", parameters);
return Json.Deserialize<TvShowResponse>(response).Result.TvShows;
return Json.Deserialize<MovieResponse>(response).Result.Movies;
}
private string ProcessRequest(IRestRequest request, XbmcSettings settings, string method, Dictionary<string, object> parameters = null)

@ -14,7 +14,6 @@ namespace NzbDrone.Core.Notifications.Xbmc
public interface IXbmcService
{
void Notify(XbmcSettings settings, string title, string message);
void Update(XbmcSettings settings, Series series);
void UpdateMovie(XbmcSettings settings, Movie movie);
void Clean(XbmcSettings settings);
ValidationFailure Test(XbmcSettings settings, string message);
@ -46,12 +45,6 @@ namespace NzbDrone.Core.Notifications.Xbmc
provider.Notify(settings, title, message);
}
public void Update(XbmcSettings settings, Series series)
{
var provider = GetApiProvider(settings);
provider.Update(settings, series);
}
public void UpdateMovie(XbmcSettings settings, Movie movie)
{
var provider = GetApiProvider(settings);

@ -1091,7 +1091,6 @@
<Compile Include="Notifications\Pushover\PushoverService.cs" />
<Compile Include="Notifications\Pushover\PushoverSettings.cs" />
<Compile Include="Notifications\Xbmc\XbmcJsonException.cs" />
<Compile Include="Notifications\Xbmc\HttpApiProvider.cs" />
<Compile Include="Notifications\Xbmc\IApiProvider.cs" />
<Compile Include="Notifications\Xbmc\InvalidXbmcVersionException.cs" />
<Compile Include="Notifications\Xbmc\JsonApiProvider.cs" />
@ -1099,9 +1098,6 @@
<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\VersionResult.cs" />
<Compile Include="Notifications\Xbmc\Model\XbmcJsonResult.cs" />
<Compile Include="Notifications\Xbmc\Model\XbmcVersion.cs" />
@ -1307,6 +1303,9 @@
<Compile Include="MetadataSource\RadarrAPI\RadarrResources.cs" />
<Compile Include="MetadataSource\RadarrAPI\RadarrAPIClient.cs" />
<Compile Include="Datastore\Migration\139_fix_indexer_baseurl.cs" />
<Compile Include="Notifications\Xbmc\Model\XbmcMovie.cs" />
<Compile Include="Notifications\Xbmc\Model\MovieResponse.cs" />
<Compile Include="Notifications\Xbmc\Model\MovieResult.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">

@ -11,4 +11,4 @@
<package id="RestSharp" version="105.2.3" targetFramework="net40" />
<package id="TinyTwitter" version="1.1.1" targetFramework="net40" />
<package id="xmlrpcnet" version="2.5.0" targetFramework="net40" />
</packages>
</packages>

Loading…
Cancel
Save