diff --git a/MediaBrowser.Controller/Library/TVUtils.cs b/MediaBrowser.Controller/Library/TVUtils.cs
index 0b9972d0a6..8bd1c270de 100644
--- a/MediaBrowser.Controller/Library/TVUtils.cs
+++ b/MediaBrowser.Controller/Library/TVUtils.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Controller.Resolvers;
+using System.Globalization;
+using MediaBrowser.Controller.Resolvers;
using System;
using System.Collections.Generic;
using System.IO;
@@ -184,8 +185,7 @@ namespace MediaBrowser.Controller.Library
}
else
{
- if (EntityResolutionHelper.IsVideoFile(child.FullName) &&
- !string.IsNullOrEmpty(EpisodeNumberFromFile(child.FullName, false)))
+ if (EntityResolutionHelper.IsVideoFile(child.FullName) && GetEpisodeNumberFromFile(child.FullName, false).HasValue)
{
return true;
}
@@ -201,14 +201,14 @@ namespace MediaBrowser.Controller.Library
/// The full path.
/// if set to true [is in season].
/// System.String.
- public static string EpisodeNumberFromFile(string fullPath, bool isInSeason)
+ public static int? GetEpisodeNumberFromFile(string fullPath, bool isInSeason)
{
string fl = fullPath.ToLower();
foreach (var r in EpisodeExpressions)
{
Match m = r.Match(fl);
if (m.Success)
- return m.Groups["epnumber"].Value;
+ return ParseEpisodeNumber(m.Groups["epnumber"].Value);
}
if (isInSeason)
{
@@ -217,13 +217,27 @@ namespace MediaBrowser.Controller.Library
if (match != null)
{
- return match.Value;
+ return ParseEpisodeNumber(match.Value);
}
}
return null;
}
+ private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
+
+ private static int? ParseEpisodeNumber(string val)
+ {
+ int num;
+
+ if (!string.IsNullOrEmpty(val) && int.TryParse(val, NumberStyles.Integer, UsCulture, out num))
+ {
+ return num;
+ }
+
+ return null;
+ }
+
///
/// Seasons the number from episode file.
///
diff --git a/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs b/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs
index 805981e040..5be46aecc4 100644
--- a/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs
+++ b/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs
@@ -144,18 +144,16 @@ namespace MediaBrowser.Controller.Providers.TV
{
string location = episode.Path;
- string epNum = TVUtils.EpisodeNumberFromFile(location, episode.Season != null);
+ var episodeNumber = episode.IndexNumber ?? TVUtils.GetEpisodeNumberFromFile(location, episode.Season != null);
var status = ProviderRefreshStatus.Success;
- if (epNum == null)
+ if (episodeNumber == null)
{
Logger.Warn("TvDbProvider: Could not determine episode number for: " + episode.Path);
return status;
}
- var episodeNumber = Int32.Parse(epNum);
-
episode.IndexNumber = episodeNumber;
var usingAbsoluteData = false;
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs
index 7173705900..84f7a85229 100644
--- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs
+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs
@@ -18,30 +18,41 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
/// Episode.
protected override Episode Resolve(ItemResolveArgs args)
{
+ var isInSeason = args.Parent is Season;
+
// If the parent is a Season or Series, then this is an Episode if the VideoResolver returns something
- if (args.Parent is Season || args.Parent is Series)
+ if (isInSeason || args.Parent is Series)
{
if (args.IsDirectory)
{
if (args.ContainsFileSystemEntryByName("video_ts"))
{
return new Episode
- {
- Path = args.Path,
- VideoType = VideoType.Dvd
- };
+ {
+ IndexNumber = TVUtils.GetEpisodeNumberFromFile(args.Path, isInSeason),
+ Path = args.Path,
+ VideoType = VideoType.Dvd
+ };
}
if (args.ContainsFileSystemEntryByName("bdmv"))
{
return new Episode
- {
- Path = args.Path,
- VideoType = VideoType.BluRay
- };
+ {
+ IndexNumber = TVUtils.GetEpisodeNumberFromFile(args.Path, isInSeason),
+ Path = args.Path,
+ VideoType = VideoType.BluRay
+ };
}
}
- return base.Resolve(args);
+ var episide = base.Resolve(args);
+
+ if (episide != null)
+ {
+ episide.IndexNumber = TVUtils.GetEpisodeNumberFromFile(args.Path, isInSeason);
+ }
+
+ return episide;
}
return null;