Browse Source

fix path replacement logic with inconsistent casing (#1646)

pull/1647/head
Jason Dove 2 years ago committed by GitHub
parent
commit
a5aaceeee5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 32
      ErsatzTV.Core.Tests/Emby/EmbyPathReplacementServiceTests.cs
  3. 32
      ErsatzTV.Core.Tests/Jellyfin/JellyfinPathReplacementServiceTests.cs
  4. 32
      ErsatzTV.Core.Tests/Plex/PlexPathReplacementServiceTests.cs
  5. 6
      ErsatzTV.Core/Emby/EmbyPathReplacementService.cs
  6. 6
      ErsatzTV.Core/Jellyfin/JellyfinPathReplacementService.cs
  7. 6
      ErsatzTV.Core/Plex/PlexPathReplacementService.cs

1
CHANGELOG.md

@ -48,6 +48,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -48,6 +48,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix AV1 software decoder priority (`libdav1d`, `libaom-av1`, `av1`)
- Fix some stream failures caused by loudnorm filter
- Fix multi-collection editor improperly disabling collections/smart collections that haven't already been added to the multi-collection
- Fix path replacement logic when media server paths use inconsistent casing (e.g. `\\SERVERNAME` AND `\\ServerName`)
### Changed
- Log search index updates under scanner category at debug level, to indicate a potential cause for the UI being out of date

32
ErsatzTV.Core.Tests/Emby/EmbyPathReplacementServiceTests.cs

@ -165,6 +165,38 @@ public class EmbyPathReplacementServiceTests @@ -165,6 +165,38 @@ public class EmbyPathReplacementServiceTests
result.Should().Be(@"/mnt/something else/Some Shared Folder/Some Movie/Some Movie.mkv");
}
[Test]
public async Task EmbyWindows_To_EtvLinux_UncPathWithMixedCaseServerName()
{
var replacements = new List<EmbyPathReplacement>
{
new()
{
Id = 1,
EmbyPath = @"\\ServerName\Something\Some Shared Folder\",
LocalPath = @"/mnt/something else/Some Shared Folder/",
EmbyMediaSource = new EmbyMediaSource { OperatingSystem = "Windows" }
}
};
IMediaSourceRepository repo = Substitute.For<IMediaSourceRepository>();
repo.GetEmbyPathReplacementsByLibraryId(Arg.Any<int>()).Returns(replacements.AsTask());
IRuntimeInfo runtime = Substitute.For<IRuntimeInfo>();
runtime.IsOSPlatform(OSPlatform.Windows).Returns(false);
var service = new EmbyPathReplacementService(
repo,
runtime,
Substitute.For<ILogger<EmbyPathReplacementService>>());
string result = await service.GetReplacementEmbyPath(
0,
@"\\SERVERNAME\Something\Some Shared Folder\Some Movie\Some Movie.mkv");
result.Should().Be(@"/mnt/something else/Some Shared Folder/Some Movie/Some Movie.mkv");
}
[Test]
public async Task EmbyLinux_To_EtvWindows()
{

32
ErsatzTV.Core.Tests/Jellyfin/JellyfinPathReplacementServiceTests.cs

@ -165,6 +165,38 @@ public class JellyfinPathReplacementServiceTests @@ -165,6 +165,38 @@ public class JellyfinPathReplacementServiceTests
result.Should().Be(@"/mnt/something else/Some Shared Folder/Some Movie/Some Movie.mkv");
}
[Test]
public async Task JellyfinWindows_To_EtvLinux_UncPathWithMixedCaseServerName()
{
var replacements = new List<JellyfinPathReplacement>
{
new()
{
Id = 1,
JellyfinPath = @"\\ServerName\Something\Some Shared Folder\",
LocalPath = @"/mnt/something else/Some Shared Folder/",
JellyfinMediaSource = new JellyfinMediaSource { OperatingSystem = "Windows" }
}
};
IMediaSourceRepository repo = Substitute.For<IMediaSourceRepository>();
repo.GetJellyfinPathReplacementsByLibraryId(Arg.Any<int>()).Returns(replacements.AsTask());
IRuntimeInfo runtime = Substitute.For<IRuntimeInfo>();
runtime.IsOSPlatform(OSPlatform.Windows).Returns(false);
var service = new JellyfinPathReplacementService(
repo,
runtime,
Substitute.For<ILogger<JellyfinPathReplacementService>>());
string result = await service.GetReplacementJellyfinPath(
0,
@"\\SERVERNAME\Something\Some Shared Folder\Some Movie\Some Movie.mkv");
result.Should().Be(@"/mnt/something else/Some Shared Folder/Some Movie/Some Movie.mkv");
}
[Test]
public async Task JellyfinLinux_To_EtvWindows()
{

32
ErsatzTV.Core.Tests/Plex/PlexPathReplacementServiceTests.cs

@ -141,6 +141,38 @@ public class PlexPathReplacementServiceTests @@ -141,6 +141,38 @@ public class PlexPathReplacementServiceTests
result.Should().Be(@"/mnt/something else/Some Shared Folder/Some Movie/Some Movie.mkv");
}
[Test]
public async Task PlexWindows_To_EtvLinux_UncPathWithMixedCaseServerName()
{
var replacements = new List<PlexPathReplacement>
{
new()
{
Id = 1,
PlexPath = @"\\ServerName\Something\Some Shared Folder\",
LocalPath = @"/mnt/something else/Some Shared Folder/",
PlexMediaSource = new PlexMediaSource { Platform = "Windows" }
}
};
IMediaSourceRepository repo = Substitute.For<IMediaSourceRepository>();
repo.GetPlexPathReplacementsByLibraryId(Arg.Any<int>()).Returns(replacements.AsTask());
IRuntimeInfo runtime = Substitute.For<IRuntimeInfo>();
runtime.IsOSPlatform(OSPlatform.Windows).Returns(false);
var service = new PlexPathReplacementService(
repo,
runtime,
Substitute.For<ILogger<PlexPathReplacementService>>());
string result = await service.GetReplacementPlexPath(
0,
@"\\SERVERNAME\Something\Some Shared Folder\Some Movie\Some Movie.mkv");
result.Should().Be(@"/mnt/something else/Some Shared Folder/Some Movie/Some Movie.mkv");
}
[Test]
public async Task PlexLinux_To_EtvWindows()
{

6
ErsatzTV.Core/Emby/EmbyPathReplacementService.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Emby;
using ErsatzTV.Core.Interfaces.Repositories;
@ -85,7 +86,10 @@ public class EmbyPathReplacementService : IEmbyPathReplacementService @@ -85,7 +86,10 @@ public class EmbyPathReplacementService : IEmbyPathReplacementService
foreach (EmbyPathReplacement replacement in maybeReplacement)
{
string finalPath = path.Replace(replacement.EmbyPath, replacement.LocalPath);
string finalPath = Regex.Replace(path,
Regex.Escape(replacement.EmbyPath),
Regex.Replace(replacement.LocalPath ?? string.Empty, "\\$[0-9]+", @"$$$0"),
RegexOptions.IgnoreCase);
if (IsWindows(replacement.EmbyMediaSource, path) && !isTargetPlatformWindows)
{
finalPath = finalPath.Replace(@"\", @"/");

6
ErsatzTV.Core/Jellyfin/JellyfinPathReplacementService.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Jellyfin;
using ErsatzTV.Core.Interfaces.Repositories;
@ -85,7 +86,10 @@ public class JellyfinPathReplacementService : IJellyfinPathReplacementService @@ -85,7 +86,10 @@ public class JellyfinPathReplacementService : IJellyfinPathReplacementService
foreach (JellyfinPathReplacement replacement in maybeReplacement)
{
string finalPath = path.Replace(replacement.JellyfinPath, replacement.LocalPath);
string finalPath = Regex.Replace(path,
Regex.Escape(replacement.JellyfinPath),
Regex.Replace(replacement.LocalPath ?? string.Empty, "\\$[0-9]+", @"$$$0"),
RegexOptions.IgnoreCase);
if (IsWindows(replacement.JellyfinMediaSource, path) && !isTargetPlatformWindows)
{
finalPath = finalPath.Replace(@"\", @"/");

6
ErsatzTV.Core/Plex/PlexPathReplacementService.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Plex;
using ErsatzTV.Core.Interfaces.Repositories;
@ -51,7 +52,10 @@ public class PlexPathReplacementService : IPlexPathReplacementService @@ -51,7 +52,10 @@ public class PlexPathReplacementService : IPlexPathReplacementService
foreach (PlexPathReplacement replacement in maybeReplacement)
{
string finalPath = path.Replace(replacement.PlexPath, replacement.LocalPath);
string finalPath = Regex.Replace(path,
Regex.Escape(replacement.PlexPath),
Regex.Replace(replacement.LocalPath ?? string.Empty, "\\$[0-9]+", @"$$$0"),
RegexOptions.IgnoreCase);
if (IsWindows(replacement.PlexMediaSource) && !_runtimeInfo.IsOSPlatform(OSPlatform.Windows))
{
finalPath = finalPath.Replace(@"\", @"/");

Loading…
Cancel
Save