diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-06-20 00:50:39 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-06-20 00:50:39 -0400 |
| commit | c2d8cb47319cc441375f8db4a8a9077f8fb25e08 (patch) | |
| tree | 6860fdf25e7ff97ef26636ab8412bb0625d93b44 | |
| parent | 439839378364466ae7795c99b67a123bd1008945 (diff) | |
| parent | 0b85b7300d1097784ddb7377a59889d16d708df8 (diff) | |
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
5 files changed, 41 insertions, 31 deletions
diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs index be761ef66..b9630a66f 100644 --- a/MediaBrowser.Controller/Entities/TV/Episode.cs +++ b/MediaBrowser.Controller/Entities/TV/Episode.cs @@ -273,7 +273,7 @@ namespace MediaBrowser.Controller.Entities.TV { if (!IndexNumber.HasValue && !string.IsNullOrEmpty(Path)) { - IndexNumber = TVUtils.GetEpisodeNumberFromFile(Path, Parent is Season); + IndexNumber = TVUtils.GetEpisodeNumberFromFile(Path, true); // If a change was made record it if (IndexNumber.HasValue) diff --git a/MediaBrowser.Controller/Library/TVUtils.cs b/MediaBrowser.Controller/Library/TVUtils.cs index 7841a32ae..64f3a3b4b 100644 --- a/MediaBrowser.Controller/Library/TVUtils.cs +++ b/MediaBrowser.Controller/Library/TVUtils.cs @@ -93,27 +93,26 @@ namespace MediaBrowser.Controller.Library }; /// <summary> - /// To avoid the following matching movies they are only valid when contained in a folder which has been matched as a being season + /// To avoid the following matching movies they are only valid when contained in a folder which has been matched as a being season, or the media type is TV series /// </summary> - private static readonly Regex[] EpisodeExpressionsInASeasonFolder = + private static readonly Regex[] EpisodeExpressionsWithoutSeason = { new Regex( - @".*(\\|\/)(?<epnumber>\d{1,2})\s?-\s?[^\\\/]*$", + @".*[\\\/](?<epnumber>\d{1,3})\.\w+$", RegexOptions.Compiled), - // 01 - blah.avi, 01-blah.avi + // "01.avi" new Regex( - @".*(\\|\/)(?<epnumber>\d{1,2})[^\d\\]*[^\\\/]*$", + @".*(\\|\/)(?<epnumber>\d{1,2})\s?-\s?[^\\\/]*$", RegexOptions.Compiled), - // 01.avi, 01.blah.avi "01 - 22 blah.avi" - new Regex( - @".*(\\|\/)(?<seasonnumber>\d)(?<epnumber>\d{1,2})[^\d\\]+[^\\\/]*$", + // "01 - blah.avi", "01-blah.avi" + new Regex( + @".*(\\|\/)(?<epnumber>\d{1,2})\.[^\\\/]+$", RegexOptions.Compiled), - // 01.avi, 01.blah.avi + // "01.blah.avi" new Regex( - @".*(\\|\/)\D*\d+(?<epnumber>\d{2})", - RegexOptions.Compiled) - // hell0 - 101 - hello.avi - + @".*[\\\/][^\\\/]* - (?<epnumber>\d{1,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" }; /// <summary> @@ -197,7 +196,7 @@ namespace MediaBrowser.Controller.Library /// <param name="path">The path.</param> /// <param name="fileSystemChildren">The file system children.</param> /// <returns><c>true</c> if [is series folder] [the specified path]; otherwise, <c>false</c>.</returns> - public static bool IsSeriesFolder(string path, IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService) + public static bool IsSeriesFolder(string path, bool considerSeasonlessSeries, IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService) { // A folder with more than 3 non-season folders in will not becounted as a series var nonSeriesFolders = 0; @@ -236,7 +235,7 @@ namespace MediaBrowser.Controller.Library if (EntityResolutionHelper.IsVideoFile(fullName) || EntityResolutionHelper.IsVideoPlaceHolder(fullName)) { - if (GetEpisodeNumberFromFile(fullName, false).HasValue) + if (GetEpisodeNumberFromFile(fullName, considerSeasonlessSeries).HasValue) { return true; } @@ -251,9 +250,9 @@ namespace MediaBrowser.Controller.Library /// Episodes the number from file. /// </summary> /// <param name="fullPath">The full path.</param> - /// <param name="isInSeason">if set to <c>true</c> [is in season].</param> + /// <param name="considerSeasonlessNames">if set to <c>true</c> [is in season].</param> /// <returns>System.String.</returns> - public static int? GetEpisodeNumberFromFile(string fullPath, bool isInSeason) + public static int? GetEpisodeNumberFromFile(string fullPath, bool considerSeasonlessNames) { string fl = fullPath.ToLower(); foreach (var r in EpisodeExpressions) @@ -262,9 +261,9 @@ namespace MediaBrowser.Controller.Library if (m.Success) return ParseEpisodeNumber(m.Groups["epnumber"].Value); } - if (isInSeason) + if (considerSeasonlessNames) { - var match = EpisodeExpressionsInASeasonFolder.Select(r => r.Match(fl)) + var match = EpisodeExpressionsWithoutSeason.Select(r => r.Match(fl)) .FirstOrDefault(m => m.Success); if (match != null) diff --git a/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs index dd9f3af8b..ef9f5427c 100644 --- a/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs @@ -217,13 +217,8 @@ namespace MediaBrowser.Providers.TV var episodeNumber = identity.IndexNumber; var seasonOffset = TvdbSeriesProvider.GetSeriesOffset(seriesProviderIds) ?? 0; var seasonNumber = identity.SeasonIndex + seasonOffset; - - if (seasonNumber == null) - { - return null; - } - - var file = Path.Combine(seriesDataPath, string.Format("episode-{0}-{1}.xml", seasonNumber.Value, episodeNumber)); + + string file; var success = false; var usingAbsoluteData = false; @@ -236,14 +231,18 @@ namespace MediaBrowser.Providers.TV try { - FetchMainEpisodeInfo(episode, file, cancellationToken); + if (seasonNumber != null) + { + file = Path.Combine(seriesDataPath, string.Format("episode-{0}-{1}.xml", seasonNumber.Value, episodeNumber)); + FetchMainEpisodeInfo(episode, file, cancellationToken); - success = true; + success = true; + } } catch (FileNotFoundException) { // Could be using absolute numbering - if (seasonNumber.Value != 1) + if (seasonNumber.HasValue && seasonNumber.Value != 1) { throw; } @@ -255,6 +254,7 @@ namespace MediaBrowser.Providers.TV FetchMainEpisodeInfo(episode, file, cancellationToken); usingAbsoluteData = true; + success = true; } var end = identity.IndexNumberEnd ?? episodeNumber; diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs index e97bc97f8..6b376d3b4 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs @@ -74,7 +74,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV return null; } - if (args.ContainsMetaFileByName("series.xml") || filename.IndexOf("[tvdbid=", StringComparison.OrdinalIgnoreCase) != -1 || TVUtils.IsSeriesFolder(args.Path, args.FileSystemChildren, args.DirectoryService)) + if (args.ContainsMetaFileByName("series.xml") || filename.IndexOf("[tvdbid=", StringComparison.OrdinalIgnoreCase) != -1 || TVUtils.IsSeriesFolder(args.Path, collectionType == CollectionType.TvShows, args.FileSystemChildren, args.DirectoryService)) { return new Series(); } diff --git a/MediaBrowser.Tests/Resolvers/TvUtilTests.cs b/MediaBrowser.Tests/Resolvers/TvUtilTests.cs index 0786ced66..97e790776 100644 --- a/MediaBrowser.Tests/Resolvers/TvUtilTests.cs +++ b/MediaBrowser.Tests/Resolvers/TvUtilTests.cs @@ -59,6 +59,17 @@ namespace MediaBrowser.Tests.Resolvers Assert.AreEqual(02, TVUtils.GetEpisodeNumberFromFile(@"Season 2\02 - blah 14 blah.avi", true)); Assert.AreEqual(02, TVUtils.GetEpisodeNumberFromFile(@"Season 1\02 - blah-02 a.avi", true)); Assert.AreEqual(02, TVUtils.GetEpisodeNumberFromFile(@"Season 2\02.avi", true)); + + //Without seasons + Assert.AreEqual(02, TVUtils.GetEpisodeNumberFromFile(@"The Simpsons\02.avi", true)); + Assert.AreEqual(02, TVUtils.GetEpisodeNumberFromFile(@"The Simpsons\02 - Ep Name.avi", true)); + Assert.AreEqual(02, TVUtils.GetEpisodeNumberFromFile(@"The Simpsons\02-Ep Name.avi", true)); + Assert.AreEqual(02, TVUtils.GetEpisodeNumberFromFile(@"The Simpsons\02.EpName.avi", true)); + Assert.AreEqual(02, TVUtils.GetEpisodeNumberFromFile(@"The Simpsons\The Simpsons - 02.avi", true)); + Assert.AreEqual(02, TVUtils.GetEpisodeNumberFromFile(@"The Simpsons\The Simpsons - 02 - Ep Name.avi", true)); + Assert.AreEqual(02, TVUtils.GetEpisodeNumberFromFile(@"The Simpsons\The Simpsons - 02 Ep Name.avi", true)); + Assert.AreEqual(02, TVUtils.GetEpisodeNumberFromFile(@"The Simpsons\The Simpsons 5 - 02 - Ep Name.avi", true)); + Assert.AreEqual(02, TVUtils.GetEpisodeNumberFromFile(@"The Simpsons\The Simpsons 5 - 02 Ep Name.avi", true)); } [TestMethod] |
