From a0068a3ed9689c86cc196427639c78a1d5acf363 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 1 May 2023 19:40:38 -0500 Subject: [PATCH] Fixed: Don't clean Kodi library if video is playing and Always Update is disabled Closes #8139 Co-Authored-By: Mark McDowall --- .../Notifications/Xbmc/XbmcService.cs | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs b/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs index 2cbb057c3..b749b605a 100644 --- a/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs +++ b/src/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Linq; using FluentValidation.Results; @@ -35,23 +35,25 @@ namespace NzbDrone.Core.Notifications.Xbmc public void UpdateMovie(XbmcSettings settings, Movie movie) { - if (!settings.AlwaysUpdate) + if (CheckIfVideoPlayerOpen(settings)) { - _logger.Debug("Determining if there are any active players on XBMC host: {0}", settings.Address); - var activePlayers = _proxy.GetActivePlayers(settings); + _logger.Debug("Video is currently playing, skipping library update"); - if (activePlayers.Any(a => a.Type.Equals("video"))) - { - _logger.Debug("Video is currently playing, skipping library update"); - return; - } + return; } - UpdateMovieLibrary(settings, movie); + UpdateLibrary(settings, movie); } public void Clean(XbmcSettings settings) { + if (CheckIfVideoPlayerOpen(settings)) + { + _logger.Debug("Video is currently playing, skipping library clean"); + + return; + } + _proxy.CleanLibrary(settings); } @@ -61,7 +63,7 @@ namespace NzbDrone.Core.Notifications.Xbmc if (!allMovies.Any()) { - _logger.Debug("No Movies returned from XBMC"); + _logger.Debug("No Movies returned from Kodi"); return null; } @@ -78,7 +80,7 @@ namespace NzbDrone.Core.Notifications.Xbmc return null; } - private void UpdateMovieLibrary(XbmcSettings settings, Movie movie) + private void UpdateLibrary(XbmcSettings settings, Movie movie) { try { @@ -86,11 +88,11 @@ namespace NzbDrone.Core.Notifications.Xbmc if (moviePath != null) { - _logger.Debug("Updating movie {0} (Path: {1}) on XBMC host: {2}", movie, moviePath, settings.Address); + _logger.Debug("Updating movie {0} (Path: {1}) on Kodi host: {2}", movie, moviePath, settings.Address); } else { - _logger.Debug("Movie {0} doesn't exist on XBMC host: {1}, Updating Entire Library", movie, settings.Address); + _logger.Debug("Movie {0} doesn't exist on Kodi host: {1}, Updating Entire Library", movie, settings.Address); } var response = _proxy.UpdateLibrary(settings, moviePath); @@ -106,6 +108,19 @@ namespace NzbDrone.Core.Notifications.Xbmc } } + private bool CheckIfVideoPlayerOpen(XbmcSettings settings) + { + if (settings.AlwaysUpdate) + { + return false; + } + + _logger.Debug("Determining if there are any active players on Kodi host: {0}", settings.Address); + var activePlayers = _proxy.GetActivePlayers(settings); + + return activePlayers.Any(a => a.Type.Equals("video")); + } + public ValidationFailure Test(XbmcSettings settings, string message) { try