Browse Source

fix unc path replacements from jellyfin and emby (#205)

* fix UNC path replacements from non-windows JF and Emby servers

* use emby path replacements for playback
pull/207/head
Jason Dove 5 years ago committed by GitHub
parent
commit
f8b45ed9db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      ErsatzTV.Application/Streaming/Queries/GetPlayoutItemProcessByChannelNumberHandler.cs
  2. 16
      ErsatzTV.Core/Emby/EmbyPathReplacementService.cs
  3. 16
      ErsatzTV.Core/Jellyfin/JellyfinPathReplacementService.cs

12
ErsatzTV.Application/Streaming/Queries/GetPlayoutItemProcessByChannelNumberHandler.cs

@ -5,6 +5,7 @@ using ErsatzTV.Core;
using ErsatzTV.Core.Domain; using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Errors; using ErsatzTV.Core.Errors;
using ErsatzTV.Core.FFmpeg; using ErsatzTV.Core.FFmpeg;
using ErsatzTV.Core.Interfaces.Emby;
using ErsatzTV.Core.Interfaces.Jellyfin; using ErsatzTV.Core.Interfaces.Jellyfin;
using ErsatzTV.Core.Interfaces.Metadata; using ErsatzTV.Core.Interfaces.Metadata;
using ErsatzTV.Core.Interfaces.Plex; using ErsatzTV.Core.Interfaces.Plex;
@ -20,6 +21,7 @@ namespace ErsatzTV.Application.Streaming.Queries
private readonly IConfigElementRepository _configElementRepository; private readonly IConfigElementRepository _configElementRepository;
private readonly FFmpegProcessService _ffmpegProcessService; private readonly FFmpegProcessService _ffmpegProcessService;
private readonly IJellyfinPathReplacementService _jellyfinPathReplacementService; private readonly IJellyfinPathReplacementService _jellyfinPathReplacementService;
private readonly IEmbyPathReplacementService _embyPathReplacementService;
private readonly ILocalFileSystem _localFileSystem; private readonly ILocalFileSystem _localFileSystem;
private readonly IPlayoutRepository _playoutRepository; private readonly IPlayoutRepository _playoutRepository;
private readonly IPlexPathReplacementService _plexPathReplacementService; private readonly IPlexPathReplacementService _plexPathReplacementService;
@ -31,7 +33,8 @@ namespace ErsatzTV.Application.Streaming.Queries
FFmpegProcessService ffmpegProcessService, FFmpegProcessService ffmpegProcessService,
ILocalFileSystem localFileSystem, ILocalFileSystem localFileSystem,
IPlexPathReplacementService plexPathReplacementService, IPlexPathReplacementService plexPathReplacementService,
IJellyfinPathReplacementService jellyfinPathReplacementService) IJellyfinPathReplacementService jellyfinPathReplacementService,
IEmbyPathReplacementService embyPathReplacementService)
: base(channelRepository, configElementRepository) : base(channelRepository, configElementRepository)
{ {
_configElementRepository = configElementRepository; _configElementRepository = configElementRepository;
@ -40,6 +43,7 @@ namespace ErsatzTV.Application.Streaming.Queries
_localFileSystem = localFileSystem; _localFileSystem = localFileSystem;
_plexPathReplacementService = plexPathReplacementService; _plexPathReplacementService = plexPathReplacementService;
_jellyfinPathReplacementService = jellyfinPathReplacementService; _jellyfinPathReplacementService = jellyfinPathReplacementService;
_embyPathReplacementService = embyPathReplacementService;
} }
protected override async Task<Either<BaseError, Process>> GetProcess( protected override async Task<Either<BaseError, Process>> GetProcess(
@ -178,6 +182,12 @@ namespace ErsatzTV.Application.Streaming.Queries
JellyfinEpisode jellyfinEpisode => await _jellyfinPathReplacementService.GetReplacementJellyfinPath( JellyfinEpisode jellyfinEpisode => await _jellyfinPathReplacementService.GetReplacementJellyfinPath(
jellyfinEpisode.LibraryPathId, jellyfinEpisode.LibraryPathId,
path), path),
EmbyMovie embyMovie => await _embyPathReplacementService.GetReplacementEmbyPath(
embyMovie.LibraryPathId,
path),
EmbyEpisode embyEpisode => await _embyPathReplacementService.GetReplacementEmbyPath(
embyEpisode.LibraryPathId,
path),
_ => path _ => path
}; };
} }

16
ErsatzTV.Core/Emby/EmbyPathReplacementService.cs

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -44,7 +45,7 @@ namespace ErsatzTV.Core.Emby
.SingleOrDefault( .SingleOrDefault(
r => r =>
{ {
string separatorChar = IsWindows(r.EmbyMediaSource) ? @"\" : @"/"; string separatorChar = IsWindows(r.EmbyMediaSource, path) ? @"\" : @"/";
string prefix = r.EmbyPath.EndsWith(separatorChar) string prefix = r.EmbyPath.EndsWith(separatorChar)
? r.EmbyPath ? r.EmbyPath
: r.EmbyPath + separatorChar; : r.EmbyPath + separatorChar;
@ -55,11 +56,11 @@ namespace ErsatzTV.Core.Emby
replacement => replacement =>
{ {
string finalPath = path.Replace(replacement.EmbyPath, replacement.LocalPath); string finalPath = path.Replace(replacement.EmbyPath, replacement.LocalPath);
if (IsWindows(replacement.EmbyMediaSource) && !_runtimeInfo.IsOSPlatform(OSPlatform.Windows)) if (IsWindows(replacement.EmbyMediaSource, path) && !_runtimeInfo.IsOSPlatform(OSPlatform.Windows))
{ {
finalPath = finalPath.Replace(@"\", @"/"); finalPath = finalPath.Replace(@"\", @"/");
} }
else if (!IsWindows(replacement.EmbyMediaSource) && else if (!IsWindows(replacement.EmbyMediaSource, path) &&
_runtimeInfo.IsOSPlatform(OSPlatform.Windows)) _runtimeInfo.IsOSPlatform(OSPlatform.Windows))
{ {
finalPath = finalPath.Replace(@"/", @"\"); finalPath = finalPath.Replace(@"/", @"\");
@ -79,7 +80,10 @@ namespace ErsatzTV.Core.Emby
() => path); () => path);
} }
private static bool IsWindows(EmbyMediaSource embyMediaSource) => private static bool IsWindows(EmbyMediaSource embyMediaSource, string path)
embyMediaSource.OperatingSystem.ToLowerInvariant().StartsWith("windows"); {
bool isUnc = Uri.TryCreate(path, UriKind.Absolute, out Uri uri) && uri.IsUnc;
return isUnc || embyMediaSource.OperatingSystem.ToLowerInvariant().StartsWith("windows");
}
} }
} }

16
ErsatzTV.Core/Jellyfin/JellyfinPathReplacementService.cs

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -44,7 +45,7 @@ namespace ErsatzTV.Core.Jellyfin
.SingleOrDefault( .SingleOrDefault(
r => r =>
{ {
string separatorChar = IsWindows(r.JellyfinMediaSource) ? @"\" : @"/"; string separatorChar = IsWindows(r.JellyfinMediaSource, path) ? @"\" : @"/";
string prefix = r.JellyfinPath.EndsWith(separatorChar) string prefix = r.JellyfinPath.EndsWith(separatorChar)
? r.JellyfinPath ? r.JellyfinPath
: r.JellyfinPath + separatorChar; : r.JellyfinPath + separatorChar;
@ -55,11 +56,11 @@ namespace ErsatzTV.Core.Jellyfin
replacement => replacement =>
{ {
string finalPath = path.Replace(replacement.JellyfinPath, replacement.LocalPath); string finalPath = path.Replace(replacement.JellyfinPath, replacement.LocalPath);
if (IsWindows(replacement.JellyfinMediaSource) && !_runtimeInfo.IsOSPlatform(OSPlatform.Windows)) if (IsWindows(replacement.JellyfinMediaSource, path) && !_runtimeInfo.IsOSPlatform(OSPlatform.Windows))
{ {
finalPath = finalPath.Replace(@"\", @"/"); finalPath = finalPath.Replace(@"\", @"/");
} }
else if (!IsWindows(replacement.JellyfinMediaSource) && else if (!IsWindows(replacement.JellyfinMediaSource, path) &&
_runtimeInfo.IsOSPlatform(OSPlatform.Windows)) _runtimeInfo.IsOSPlatform(OSPlatform.Windows))
{ {
finalPath = finalPath.Replace(@"/", @"\"); finalPath = finalPath.Replace(@"/", @"\");
@ -79,7 +80,10 @@ namespace ErsatzTV.Core.Jellyfin
() => path); () => path);
} }
private static bool IsWindows(JellyfinMediaSource jellyfinMediaSource) => private static bool IsWindows(JellyfinMediaSource jellyfinMediaSource, string path)
jellyfinMediaSource.OperatingSystem.ToLowerInvariant().StartsWith("windows"); {
bool isUnc = Uri.TryCreate(path, UriKind.Absolute, out Uri uri) && uri.IsUnc;
return isUnc || jellyfinMediaSource.OperatingSystem.ToLowerInvariant().StartsWith("windows");
}
} }
} }

Loading…
Cancel
Save