mirror of
https://github.com/Radarr/Radarr
synced 2024-12-25 09:21:57 +00:00
New: Validate PMS version before performing a library update
This commit is contained in:
parent
3f64c01d5b
commit
c99e92e6af
3 changed files with 41 additions and 8 deletions
|
@ -19,12 +19,14 @@ public interface IPlexServerService
|
|||
|
||||
public class PlexServerService : IPlexServerService
|
||||
{
|
||||
private readonly ICached<Version> _versionCache;
|
||||
private readonly ICached<bool> _partialUpdateCache;
|
||||
private readonly IPlexServerProxy _plexServerProxy;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public PlexServerService(ICacheManager cacheManager, IPlexServerProxy plexServerProxy, Logger logger)
|
||||
{
|
||||
_versionCache = cacheManager.GetCache<Version>(GetType(), "versionCache");
|
||||
_partialUpdateCache = cacheManager.GetCache<bool>(GetType(), "partialUpdateCache");
|
||||
_plexServerProxy = plexServerProxy;
|
||||
_logger = logger;
|
||||
|
@ -35,9 +37,12 @@ public void UpdateLibrary(Series series, 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), TimeSpan.FromHours(2));
|
||||
var partialUpdates = _partialUpdateCache.Get(settings.Host, () => PartialUpdatesAllowed(settings, version), TimeSpan.FromHours(2));
|
||||
|
||||
if (partialUpdates)
|
||||
{
|
||||
|
@ -64,13 +69,10 @@ private List<PlexSection> GetSections(PlexServerSettings settings)
|
|||
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 @@ private bool PartialUpdatesAllowed(PlexServerSettings settings)
|
|||
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<PlexPreference> GetPreferences(PlexServerSettings settings)
|
||||
{
|
||||
_logger.Debug("Getting preferences from Plex host: {0}", settings.Host);
|
||||
|
|
15
src/NzbDrone.Core/Notifications/Plex/PlexVersionException.cs
Normal file
15
src/NzbDrone.Core/Notifications/Plex/PlexVersionException.cs
Normal file
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -829,6 +829,7 @@
|
|||
<Compile Include="Notifications\Plex\PlexAuthenticationException.cs" />
|
||||
<Compile Include="Notifications\CustomScript\CustomScript.cs" />
|
||||
<Compile Include="Notifications\CustomScript\CustomScriptSettings.cs" />
|
||||
<Compile Include="Notifications\Plex\PlexVersionException.cs" />
|
||||
<Compile Include="Notifications\Plex\PlexHomeTheater.cs" />
|
||||
<Compile Include="Notifications\Plex\PlexHomeTheaterSettings.cs" />
|
||||
<Compile Include="Notifications\Plex\PlexClientService.cs" />
|
||||
|
|
Loading…
Reference in a new issue