From c03335dc4361a36d528fee7d3af172e9ea131a0a Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 21 Apr 2022 22:49:09 -0500 Subject: [PATCH] New: Add path mapping for partial library updates in Plex Server Notifications (cherry picked from commit de08d372677052f5dcf9ee689cd48282746bfbec) --- .../Notifications/Plex/Server/PlexServerService.cs | 13 ++++++++++++- .../Notifications/Plex/Server/PlexServerSettings.cs | 9 +++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/Notifications/Plex/Server/PlexServerService.cs b/src/NzbDrone.Core/Notifications/Plex/Server/PlexServerService.cs index 700a20a70..0d8cbf409 100644 --- a/src/NzbDrone.Core/Notifications/Plex/Server/PlexServerService.cs +++ b/src/NzbDrone.Core/Notifications/Plex/Server/PlexServerService.cs @@ -6,6 +6,7 @@ using System.Text.RegularExpressions; using FluentValidation.Results; using NLog; using NzbDrone.Common.Cache; +using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; using NzbDrone.Core.Music; using NzbDrone.Core.RootFolders; @@ -101,7 +102,17 @@ namespace NzbDrone.Core.Notifications.Plex.Server { foreach (var location in section.Locations) { - if (location.Path.PathEquals(rootFolderPath)) + var rootFolder = new OsPath(rootFolderPath); + var mappedPath = rootFolder; + + if (settings.MapTo.IsNotNullOrWhiteSpace()) + { + mappedPath = new OsPath(settings.MapTo) + (rootFolder - new OsPath(settings.MapFrom)); + + _logger.Trace("Mapping Path from {0} to {1} for partial scan", rootFolder, mappedPath); + } + + if (location.Path.PathEquals(mappedPath.FullPath)) { _logger.Debug("Updating matching section location, {0}", location.Path); UpdateSectionPath(artistRelativePath, section, location, settings); diff --git a/src/NzbDrone.Core/Notifications/Plex/Server/PlexServerSettings.cs b/src/NzbDrone.Core/Notifications/Plex/Server/PlexServerSettings.cs index ca959d298..6d125168d 100644 --- a/src/NzbDrone.Core/Notifications/Plex/Server/PlexServerSettings.cs +++ b/src/NzbDrone.Core/Notifications/Plex/Server/PlexServerSettings.cs @@ -1,4 +1,5 @@ using FluentValidation; +using NzbDrone.Common.Extensions; using NzbDrone.Core.Annotations; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation; @@ -11,6 +12,8 @@ namespace NzbDrone.Core.Notifications.Plex.Server { RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.Port).InclusiveBetween(1, 65535); + RuleFor(c => c.MapFrom).NotEmpty().Unless(c => c.MapTo.IsNullOrWhiteSpace()); + RuleFor(c => c.MapTo).NotEmpty().Unless(c => c.MapFrom.IsNullOrWhiteSpace()); } } @@ -43,6 +46,12 @@ namespace NzbDrone.Core.Notifications.Plex.Server [FieldDefinition(5, Label = "Update Library", Type = FieldType.Checkbox)] public bool UpdateLibrary { get; set; } + [FieldDefinition(6, Label = "Map Paths From", Type = FieldType.Textbox, Advanced = true, HelpText = "Lidarr path, used to modify series paths when Plex sees library path location differently from Lidarr")] + public string MapFrom { get; set; } + + [FieldDefinition(7, Label = "Map Paths To", Type = FieldType.Textbox, Advanced = true, HelpText = "Plex path, used to modify series paths when Plex sees library path location differently from Lidarr")] + public string MapTo { get; set; } + public bool IsValid => !string.IsNullOrWhiteSpace(Host); public NzbDroneValidationResult Validate()