diff --git a/src/NzbDrone.Core/Notifications/Plex/PlexServerService.cs b/src/NzbDrone.Core/Notifications/Plex/PlexServerService.cs index b466dadae..727c63e35 100644 --- a/src/NzbDrone.Core/Notifications/Plex/PlexServerService.cs +++ b/src/NzbDrone.Core/Notifications/Plex/PlexServerService.cs @@ -19,12 +19,14 @@ namespace NzbDrone.Core.Notifications.Plex public class PlexServerService : IPlexServerService { + private readonly ICached _versionCache; private readonly ICached _partialUpdateCache; private readonly IPlexServerProxy _plexServerProxy; private readonly Logger _logger; public PlexServerService(ICacheManager cacheManager, IPlexServerProxy plexServerProxy, Logger logger) { + _versionCache = cacheManager.GetCache(GetType(), "versionCache"); _partialUpdateCache = cacheManager.GetCache(GetType(), "partialUpdateCache"); _plexServerProxy = plexServerProxy; _logger = logger; @@ -35,9 +37,12 @@ namespace NzbDrone.Core.Notifications.Plex 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), TimeSpan.FromHours(2)); + var partialUpdates = _partialUpdateCache.Get(settings.Host, () => PartialUpdatesAllowed(settings, version), TimeSpan.FromHours(2)); if (partialUpdates) { @@ -64,13 +69,10 @@ namespace NzbDrone.Core.Notifications.Plex return _plexServerProxy.GetTvSections(settings).ToList(); } - private bool PartialUpdatesAllowed(PlexServerSettings settings) + private bool PartialUpdatesAllowed(PlexServerSettings settings, Version version) { try { - var rawVersion = GetVersion(settings); - var version = new Version(Regex.Match(rawVersion, @"^(\d+[.-]){4}").Value.Trim('.', '-')); - if (version >= new Version(0, 9, 12, 0)) { var preferences = GetPreferences(settings); @@ -92,13 +94,28 @@ namespace NzbDrone.Core.Notifications.Plex return false; } - private string GetVersion(PlexServerSettings settings) + private void ValidateVersion(Version version) + { + if (version >= new Version(1, 3, 0) && version < new Version(1, 3, 1)) + { + throw new PlexVersionException("Found version {0}, upgrade to PMS 1.3.1 to fix library updating and then restart Sonarr", version); + } + } + + private Version GetVersion(PlexServerSettings settings) { _logger.Debug("Getting version from Plex host: {0}", settings.Host); - return _plexServerProxy.Version(settings); + var rawVersion = _plexServerProxy.Version(settings); + var version = new Version(Regex.Match(rawVersion, @"^(\d+[.-]){4}").Value.Trim('.', '-')); + + + + return version; } + + private List GetPreferences(PlexServerSettings settings) { _logger.Debug("Getting preferences from Plex host: {0}", settings.Host); diff --git a/src/NzbDrone.Core/Notifications/Plex/PlexVersionException.cs b/src/NzbDrone.Core/Notifications/Plex/PlexVersionException.cs new file mode 100644 index 000000000..439cb57ac --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Plex/PlexVersionException.cs @@ -0,0 +1,15 @@ +using NzbDrone.Common.Exceptions; + +namespace NzbDrone.Core.Notifications.Plex +{ + public class PlexVersionException : NzbDroneException + { + public PlexVersionException(string message) : base(message) + { + } + + public PlexVersionException(string message, params object[] args) : base(message, args) + { + } + } +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index e24705b25..f991ecf3b 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -829,6 +829,7 @@ +