From 34f870d559d976a22e28c92a3430bf43f8e8a200 Mon Sep 17 00:00:00 2001 From: Harshith Mohan <26010946+harshithmohan@users.noreply.github.com> Date: Fri, 13 Sep 2024 23:55:33 +0530 Subject: [PATCH] Fix cross-platform plex sync, get episode data using both parent folder and filename (#1176) * Fix cross-platform plex sync * Plex sync job: use both parent folder and file name to get episode --- Shoko.Server/Plex/TVShow/SVR_Episode.cs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Shoko.Server/Plex/TVShow/SVR_Episode.cs b/Shoko.Server/Plex/TVShow/SVR_Episode.cs index 0069b79c1..57db4ca7f 100644 --- a/Shoko.Server/Plex/TVShow/SVR_Episode.cs +++ b/Shoko.Server/Plex/TVShow/SVR_Episode.cs @@ -1,4 +1,6 @@ -using System.IO; +using System; +using System.IO; +using System.Linq; using Shoko.Models.Plex.TVShow; using Shoko.Server.Models; using Shoko.Server.Repositories; @@ -14,8 +16,24 @@ public SVR_Episode(PlexHelper helper) Helper = helper; } - public SVR_AnimeEpisode AnimeEpisode => - RepoFactory.AnimeEpisode.GetByFilename(Path.GetFileName(Media[0].Part[0].File)); + public SVR_AnimeEpisode AnimeEpisode + { + get + { + var normalizedPath = Media[0].Part[0].File.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar); + + var finalPath = Path.Combine( + Path.GetFileName(Path.GetDirectoryName(normalizedPath)) ?? string.Empty, + Path.GetFileName(normalizedPath) + ); + + var file = RepoFactory.VideoLocalPlace + .GetAll() + .FirstOrDefault(location => location.FullServerPath?.EndsWith(finalPath, StringComparison.OrdinalIgnoreCase) ?? false); + + return string.IsNullOrEmpty(file?.Hashes.ED2K) ? null : RepoFactory.AnimeEpisode.GetByHash(file.Hashes.ED2K).FirstOrDefault(); + } + } public void Unscrobble() {