From cf033b25f8c405393a66079c43a77010ac779afb Mon Sep 17 00:00:00 2001 From: Joe Rogers <1337joe@gmail.com> Date: Mon, 21 Feb 2022 22:08:54 +0100 Subject: [PATCH] Require delimiter immediately after filename match --- .../MediaInfo/MediaInfoResolver.cs | 12 ++++++++++-- .../MediaInfo/MediaInfoResolverTests.cs | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Providers/MediaInfo/MediaInfoResolver.cs b/MediaBrowser.Providers/MediaInfo/MediaInfoResolver.cs index e88b88cead..40b45faf52 100644 --- a/MediaBrowser.Providers/MediaInfo/MediaInfoResolver.cs +++ b/MediaBrowser.Providers/MediaInfo/MediaInfoResolver.cs @@ -43,6 +43,11 @@ namespace MediaBrowser.Providers.MediaInfo /// private readonly IMediaEncoder _mediaEncoder; + /// + /// The instance. + /// + private readonly NamingOptions _namingOptions; + /// /// The of the files this resolver should resolve. /// @@ -62,6 +67,7 @@ namespace MediaBrowser.Providers.MediaInfo DlnaProfileType type) { _mediaEncoder = mediaEncoder; + _namingOptions = namingOptions; _type = type; _externalPathParser = new ExternalPathParser(namingOptions, localizationManager, _type); } @@ -159,9 +165,11 @@ namespace MediaBrowser.Providers.MediaInfo foreach (var file in files) { - if (_compareInfo.IsPrefix(Path.GetFileNameWithoutExtension(file), video.FileNameWithoutExtension, CompareOptions, out int matchLength)) + var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file); + if (_compareInfo.IsPrefix(fileNameWithoutExtension, video.FileNameWithoutExtension, CompareOptions, out int matchLength) + && (fileNameWithoutExtension.Length == matchLength || _namingOptions.MediaFlagDelimiters.Contains(fileNameWithoutExtension[matchLength].ToString()))) { - var externalPathInfo = _externalPathParser.ParseFile(file, Path.GetFileNameWithoutExtension(file)[matchLength..]); + var externalPathInfo = _externalPathParser.ParseFile(file, fileNameWithoutExtension[matchLength..]); if (externalPathInfo != null) { diff --git a/tests/Jellyfin.Providers.Tests/MediaInfo/MediaInfoResolverTests.cs b/tests/Jellyfin.Providers.Tests/MediaInfo/MediaInfoResolverTests.cs index 02bf878a01..926ec5c91b 100644 --- a/tests/Jellyfin.Providers.Tests/MediaInfo/MediaInfoResolverTests.cs +++ b/tests/Jellyfin.Providers.Tests/MediaInfo/MediaInfoResolverTests.cs @@ -113,7 +113,7 @@ public class MediaInfoResolverTests [InlineData("My.Video.mp3")] [InlineData("My.Video.png")] [InlineData("My.Video.txt")] - // [InlineData("My.Video Sequel.srt")] + [InlineData("My.Video Sequel.srt")] [InlineData("Some.Other.Video.srt")] public void GetExternalFiles_FuzzyMatching_RejectsNonMatches(string file) {