From 4a20260a27e8ede4188609d8206a7313f7243e97 Mon Sep 17 00:00:00 2001 From: Narfinger Date: Fri, 11 Oct 2019 19:24:55 +0900 Subject: [PATCH] add another parser case and allow parsing of seasonless Add another parser case and we now allow parsing of seasonless series which hopefully should cover more cases of directory structure --- Emby.Naming/Common/NamingOptions.cs | 10 +++++++--- Emby.Server.Implementations/Library/LibraryManager.cs | 6 +++++- tests/Jellyfin.Naming.Tests/EpisodePathParserTest.cs | 5 +++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Emby.Naming/Common/NamingOptions.cs b/Emby.Naming/Common/NamingOptions.cs index 88a9b46e6..e1f25fd2b 100644 --- a/Emby.Naming/Common/NamingOptions.cs +++ b/Emby.Naming/Common/NamingOptions.cs @@ -328,6 +328,10 @@ namespace Emby.Naming.Common // *** End Kodi Standard Naming +                // [bar] Foo - 1 [baz] +                new EpisodeExpression(@".*?(\[.*?\])+.*?(?(\w+\s)+?)[-\s_]+(?\d{1,3}).*$"){ + IsNamed=false, + }, new EpisodeExpression(@".*(\\|\/)[sS]?(?\d{1,4})[xX](?\d{1,3})[^\\\/]*$") { IsNamed = true @@ -654,9 +658,9 @@ namespace Emby.Naming.Common @".*(\\|\/)(?[^\\\/]*)[sS](?\d{1,4})[xX\.]?[eE](?\d{1,3})((-| - )?[xXeE](?\d{1,3}))+[^\\\/]*$", @".*(\\|\/)(?[^\\\/]*)[sS](?\d{1,4})[xX\.]?[eE](?\d{1,3})(-[xX]?[eE]?(?\d{1,3}))+[^\\\/]*$" }.Select(i => new EpisodeExpression(i) - { - IsNamed = true - }).ToArray(); + { + IsNamed = true + }).ToArray(); VideoFileExtensions = extensions .Distinct(StringComparer.OrdinalIgnoreCase) diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index 87e951f25..90f373cc6 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -1899,7 +1899,7 @@ namespace Emby.Server.Implementations.Library /// The cancellation token. public void UpdateItem(BaseItem item, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken) { - UpdateItems(new [] { item }, parent, updateReason, cancellationToken); + UpdateItems(new[] { item }, parent, updateReason, cancellationToken); } /// @@ -2487,6 +2487,10 @@ namespace Emby.Server.Implementations.Library { episode.ParentIndexNumber = season.IndexNumber; } + else + { + episode.ParentIndexNumber = 1; + } if (episode.ParentIndexNumber.HasValue) { diff --git a/tests/Jellyfin.Naming.Tests/EpisodePathParserTest.cs b/tests/Jellyfin.Naming.Tests/EpisodePathParserTest.cs index c4e1ff354..28ccd6df1 100644 --- a/tests/Jellyfin.Naming.Tests/EpisodePathParserTest.cs +++ b/tests/Jellyfin.Naming.Tests/EpisodePathParserTest.cs @@ -30,12 +30,13 @@ namespace Emby.Naming.TV } [Theory] - [InlineData("/media/Foo/Foo 889.avi", "Foo", 889)] + [InlineData("/media/Foo/Foo 889", "Foo", 889)] + [InlineData("/media/Foo/[Bar] Foo Baz - 11 [1080p]", "Foo Baz", 11)] public void ParseEpisodeWithoutSeason(string path, string name, int episode) { NamingOptions o = new NamingOptions(); EpisodePathParser p = new EpisodePathParser(o); - var res = p.Parse(path, false, null, null, true); + var res = p.Parse(path, true, null, null, true); Assert.True(res.Success); Assert.Equal(name, res.SeriesName);