From a798ff3dcc7c21f384fd89b1080cd526285b2c6a Mon Sep 17 00:00:00 2001 From: Jendrik Weise Date: Tue, 25 Jul 2023 05:12:43 +0200 Subject: [PATCH] Added path mappings for Jellyfin/Emby connections --- .../Notifications/MediaBrowser/MediaBrowserService.cs | 11 ++++++++++- .../MediaBrowser/MediaBrowserSettings.cs | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserService.cs b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserService.cs index d30ff88c6..7abd4e579 100644 --- a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserService.cs +++ b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserService.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Net; using FluentValidation.Results; using NLog; +using NzbDrone.Common.Disk; +using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.Tv; @@ -46,7 +48,14 @@ namespace NzbDrone.Core.Notifications.Emby foreach (var path in paths) { - _proxy.Update(settings, path, updateType); + var mappedPath = new OsPath(path); + + if (settings.MapTo.IsNotNullOrWhiteSpace()) + { + mappedPath = new OsPath(settings.MapTo) + (mappedPath - new OsPath(settings.MapFrom)); + } + + _proxy.Update(settings, mappedPath.ToString(), updateType); } } diff --git a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserSettings.cs b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserSettings.cs index ec3ea943d..ff9ac81c4 100644 --- a/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserSettings.cs +++ b/src/NzbDrone.Core/Notifications/MediaBrowser/MediaBrowserSettings.cs @@ -13,6 +13,8 @@ namespace NzbDrone.Core.Notifications.Emby { RuleFor(c => c.Host).ValidHost(); RuleFor(c => c.ApiKey).NotEmpty(); + RuleFor(c => c.MapFrom).NotEmpty().Unless(c => c.MapTo.IsNullOrWhiteSpace()); + RuleFor(c => c.MapTo).NotEmpty().Unless(c => c.MapFrom.IsNullOrWhiteSpace()); } } @@ -31,7 +33,7 @@ namespace NzbDrone.Core.Notifications.Emby [FieldDefinition(1, Label = "Port")] public int Port { get; set; } - [FieldDefinition(2, Label = "Use SSL", Type = FieldType.Checkbox, HelpText = "Connect to Emby over HTTPS instead of HTTP")] + [FieldDefinition(2, Label = "Use SSL", Type = FieldType.Checkbox, HelpText = "Connect to Emby/Jellyfin over HTTPS instead of HTTP")] public bool UseSsl { get; set; } [FieldDefinition(3, Label = "API Key", Privacy = PrivacyLevel.ApiKey)] @@ -46,6 +48,12 @@ namespace NzbDrone.Core.Notifications.Emby [FieldDefinition(5, Label = "Update Library By Name", HelpText = "Update Library by name rather than path(Requires 'UpdateLibrary')", Type = FieldType.Checkbox, Advanced = true)] public bool UpdateLibraryByName { get; set; } + [FieldDefinition(5, Label = "Map Paths From", HelpText = "Sonarr path, used to modify series paths when Emby/Jellyfin sees library path location differently from Sonarr(Requires 'UpdateLibrary')", Type = FieldType.Textbox, Advanced = true)] + public string MapFrom { get; set; } + + [FieldDefinition(5, Label = "Map Paths To", HelpText = "Emby/Jellyfin path, used to modify series paths when Emby/Jellyfin sees library path location differently from Sonarr(Requires 'UpdateLibrary')", Type = FieldType.Textbox, Advanced = true)] + public string MapTo { get; set; } + [JsonIgnore] public string Address => $"{Host.ToUrlHost()}:{Port}";