From 00541e6cc1881a57c47d12fd33e071c8a1efde88 Mon Sep 17 00:00:00 2001 From: vertigo235 Date: Fri, 27 Jan 2017 12:01:18 -0600 Subject: [PATCH] More Notification Updates (#482) * Custom Script: Add Movie_Path * Add Emby Update Support * Notifications: Maybe add Kodi / XBMC Update Support --- .../CustomScript/CustomScript.cs | 1 + .../MediaBrowser/MediaBrowser.cs | 8 ++- .../MediaBrowser/MediaBrowserProxy.cs | 10 ++++ .../MediaBrowser/MediaBrowserService.cs | 8 +++ .../Notifications/Xbmc/HttpApiProvider.cs | 49 +++++++++++++++++++ .../Notifications/Xbmc/IApiProvider.cs | 1 + .../Notifications/Xbmc/JsonApiProvider.cs | 38 +++++++++++++- src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs | 26 +++++++++- .../Notifications/Xbmc/XbmcService.cs | 7 +++ 9 files changed, 143 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs index d89f3aa42..8ff95a672 100644 --- a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs +++ b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs @@ -56,6 +56,7 @@ namespace NzbDrone.Core.Notifications.CustomScript environmentVariables.Add("Radarr_EventType", "Download"); environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString()); environmentVariables.Add("Radarr_Movie_Title", movie.Title); + environmentVariables.Add("Radarr_Movie_Path", movie.Path); environmentVariables.Add("Radarr_Movie_ImdbId", movie.ImdbId.ToString()); environmentVariables.Add("Radarr_MovieFile_Id", movieFile.Id.ToString()); environmentVariables.Add("Radarr_MovieFile_RelativePath", movieFile.RelativePath); diff --git a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowser.cs b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowser.cs index b47385736..f293a6ecd 100644 --- a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowser.cs +++ b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowser.cs @@ -37,14 +37,18 @@ namespace NzbDrone.Core.Notifications.MediaBrowser if (Settings.UpdateLibrary) { - _mediaBrowserService.Update(Settings, message.Series); + _mediaBrowserService.UpdateMovies(Settings, message.Movie); } } public override void OnMovieRename(Movie movie) { + if (Settings.UpdateLibrary) + { + _mediaBrowserService.UpdateMovies(Settings, movie); + } } - + public override void OnRename(Series series) { if (Settings.UpdateLibrary) diff --git a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserProxy.cs b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserProxy.cs index 251488d87..dafccb99a 100644 --- a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserProxy.cs +++ b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserProxy.cs @@ -40,6 +40,16 @@ namespace NzbDrone.Core.Notifications.MediaBrowser ProcessRequest(request, settings); } + + public void UpdateMovies(MediaBrowserSettings settings, string imdbid) + { + var path = string.Format("/Library/Movies/Updated?ImdbId={0}", imdbid); + var request = BuildRequest(path, settings); + request.Headers.Add("Content-Length", "0"); + + ProcessRequest(request, settings); + } + private string ProcessRequest(HttpRequest request, MediaBrowserSettings settings) { request.Headers.Add("X-MediaBrowser-Token", settings.ApiKey); diff --git a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserService.cs b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserService.cs index 748d2a67f..9c76145cd 100644 --- a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserService.cs +++ b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserService.cs @@ -11,6 +11,7 @@ namespace NzbDrone.Core.Notifications.MediaBrowser { void Notify(MediaBrowserSettings settings, string title, string message); void Update(MediaBrowserSettings settings, Series series); + void UpdateMovies(MediaBrowserSettings settings, Movie movie); ValidationFailure Test(MediaBrowserSettings settings); } @@ -35,6 +36,13 @@ namespace NzbDrone.Core.Notifications.MediaBrowser _proxy.Update(settings, series.TvdbId); } + + public void UpdateMovies(MediaBrowserSettings settings, Movie movie) + { + _proxy.UpdateMovies(settings, movie.ImdbId); + } + + public ValidationFailure Test(MediaBrowserSettings settings) { try diff --git a/src/NzbDrone.Core/Notifications/Xbmc/HttpApiProvider.cs b/src/NzbDrone.Core/Notifications/Xbmc/HttpApiProvider.cs index 76f2bc91f..528728cdf 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/HttpApiProvider.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/HttpApiProvider.cs @@ -51,6 +51,24 @@ namespace NzbDrone.Core.Notifications.Xbmc 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)"; @@ -167,6 +185,37 @@ namespace NzbDrone.Core.Notifications.Xbmc } } + 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); diff --git a/src/NzbDrone.Core/Notifications/Xbmc/IApiProvider.cs b/src/NzbDrone.Core/Notifications/Xbmc/IApiProvider.cs index bf250edc3..94bf80862 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/IApiProvider.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/IApiProvider.cs @@ -7,6 +7,7 @@ namespace NzbDrone.Core.Notifications.Xbmc { 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); } diff --git a/src/NzbDrone.Core/Notifications/Xbmc/JsonApiProvider.cs b/src/NzbDrone.Core/Notifications/Xbmc/JsonApiProvider.cs index 1a0674908..378bb0774 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/JsonApiProvider.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/JsonApiProvider.cs @@ -44,7 +44,25 @@ namespace NzbDrone.Core.Notifications.Xbmc 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 = _proxy.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) { _proxy.CleanLibrary(settings); @@ -108,5 +126,23 @@ namespace NzbDrone.Core.Notifications.Xbmc _logger.Debug(ex, ex.Message); } } + + private void UpdateMovieLibrary(XbmcSettings settings, Movie movie) + { + try + { + var response = _proxy.UpdateLibrary(settings, null); + + if (!response.Equals("OK", StringComparison.InvariantCultureIgnoreCase)) + { + _logger.Debug("Failed to update library for: {0}", settings.Address); + } + } + + catch (Exception ex) + { + _logger.Debug(ex, ex.Message); + } + } } } diff --git a/src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs b/src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs index 4939fbe3d..60469a9a9 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs @@ -33,13 +33,14 @@ namespace NzbDrone.Core.Notifications.Xbmc const string header = "Radarr - Downloaded"; Notify(Settings, header, message.Message); - UpdateAndClean(message.Series, message.OldFiles.Any()); + UpdateAndCleanMovie(message.Movie, message.OldFiles.Any()); } public override void OnMovieRename(Movie movie) { + UpdateAndCleanMovie(movie); } - + public override void OnRename(Series series) { UpdateAndClean(series); @@ -92,5 +93,26 @@ namespace NzbDrone.Core.Notifications.Xbmc _logger.Debug(ex, logMessage); } } + + private void UpdateAndCleanMovie(Movie movie, bool clean = true) + { + try + { + if (Settings.UpdateLibrary) + { + _xbmcService.UpdateMovie(Settings, movie); + } + + 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); + } + } } } diff --git a/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs b/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs index 84127f69f..85dbc99c5 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs @@ -15,6 +15,7 @@ namespace NzbDrone.Core.Notifications.Xbmc { 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); } @@ -51,6 +52,12 @@ namespace NzbDrone.Core.Notifications.Xbmc provider.Update(settings, series); } + public void UpdateMovie(XbmcSettings settings, Movie movie) + { + var provider = GetApiProvider(settings); + provider.UpdateMovie(settings, movie); + } + public void Clean(XbmcSettings settings) { var provider = GetApiProvider(settings);