From 1a371276dc92e303eba8445b2ba9c97766a052b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Miguel=20Alm=C3=A1nzar?= Date: Thu, 3 Jul 2014 00:01:36 -0400 Subject: [PATCH] add multi-episode support for filenames without seasons --- MediaBrowser.Controller/Library/TVUtils.cs | 14 ++++++++++---- MediaBrowser.Tests/Resolvers/TvUtilTests.cs | 8 ++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Controller/Library/TVUtils.cs b/MediaBrowser.Controller/Library/TVUtils.cs index 64f3a3b4b..0681a8cd1 100644 --- a/MediaBrowser.Controller/Library/TVUtils.cs +++ b/MediaBrowser.Controller/Library/TVUtils.cs @@ -98,19 +98,19 @@ namespace MediaBrowser.Controller.Library private static readonly Regex[] EpisodeExpressionsWithoutSeason = { new Regex( - @".*[\\\/](?\d{1,3})\.\w+$", + @".*[\\\/](?\d{1,3})(-(?\d{2,3}))*\.\w+$", RegexOptions.Compiled), // "01.avi" new Regex( - @".*(\\|\/)(?\d{1,2})\s?-\s?[^\\\/]*$", + @".*(\\|\/)(?\d{1,3})(-(?\d{2,3}))*\s?-\s?[^\\\/]*$", RegexOptions.Compiled), // "01 - blah.avi", "01-blah.avi" new Regex( - @".*(\\|\/)(?\d{1,2})\.[^\\\/]+$", + @".*(\\|\/)(?\d{1,3})(-(?\d{2,3}))*\.[^\\\/]+$", RegexOptions.Compiled), // "01.blah.avi" new Regex( - @".*[\\\/][^\\\/]* - (?\d{1,3})[^\\\/]*$", + @".*[\\\/][^\\\/]* - (?\d{1,3})(-(?\d{2,3}))*[^\\\/]*$", RegexOptions.Compiled), // "blah - 01.avi", "blah 2 - 01.avi", "blah - 01 blah.avi", "blah 2 - 01 blah", "blah - 01 - blah.avi", "blah 2 - 01 - blah" }; @@ -284,6 +284,12 @@ namespace MediaBrowser.Controller.Library if (m.Success && !string.IsNullOrEmpty(m.Groups["endingepnumber"].Value)) return ParseEpisodeNumber(m.Groups["endingepnumber"].Value); } + foreach (var r in EpisodeExpressionsWithoutSeason) + { + var m = r.Match(fl); + if (m.Success && !string.IsNullOrEmpty(m.Groups["endingepnumber"].Value)) + return ParseEpisodeNumber(m.Groups["endingepnumber"].Value); + } return null; } diff --git a/MediaBrowser.Tests/Resolvers/TvUtilTests.cs b/MediaBrowser.Tests/Resolvers/TvUtilTests.cs index 97e790776..bffd22f3e 100644 --- a/MediaBrowser.Tests/Resolvers/TvUtilTests.cs +++ b/MediaBrowser.Tests/Resolvers/TvUtilTests.cs @@ -31,6 +31,7 @@ namespace MediaBrowser.Tests.Resolvers Assert.AreEqual(23, TVUtils.GetEpisodeNumberFromFile(@"Season 1\S01E23-E24-E26 - The Woman.mp4", true)); Assert.AreEqual(9, TVUtils.GetEpisodeNumberFromFile(@"Season 25\The Simpsons.S25E09.Steal this episode.mp4", true)); Assert.AreEqual(8, TVUtils.GetEpisodeNumberFromFile(@"The Simpsons\The Simpsons.S25E08.Steal this episode.mp4", false)); + Assert.AreEqual(136, TVUtils.GetEpisodeNumberFromFile(@"Season 2\[HorribleSubs] Hunter X Hunter - 136 [720p].mkv",true)); //Four Digits seasons Assert.AreEqual(02, TVUtils.GetEpisodeNumberFromFile(@"Season 2009\2009x02 blah.avi", true)); @@ -128,6 +129,13 @@ namespace MediaBrowser.Tests.Resolvers Assert.AreEqual(null, TVUtils.GetEndingEpisodeNumberFromFile(@"Season 2\02 - blah 14 blah.avi")); Assert.AreEqual(null, TVUtils.GetEndingEpisodeNumberFromFile(@"Season 1\02 - blah-02 a.avi")); Assert.AreEqual(null, TVUtils.GetEndingEpisodeNumberFromFile(@"Season 2\02.avi")); + + Assert.AreEqual(3, TVUtils.GetEndingEpisodeNumberFromFile(@"Season 1\02-03 - blah.avi")); + Assert.AreEqual(4, TVUtils.GetEndingEpisodeNumberFromFile(@"Season 2\02-04 - blah 14 blah.avi")); + Assert.AreEqual(5, TVUtils.GetEndingEpisodeNumberFromFile(@"Season 1\02-05 - blah-02 a.avi")); + Assert.AreEqual(4, TVUtils.GetEndingEpisodeNumberFromFile(@"Season 2\02-04.avi")); + Assert.AreEqual(null, TVUtils.GetEndingEpisodeNumberFromFile(@"Season 2\[HorribleSubs] Hunter X Hunter - 136 [720p].mkv")); + } [TestMethod]