From 0dcd698c17139b88dd33f4ab091c67525b9d1f98 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 26 Dec 2015 13:35:53 -0500 Subject: [PATCH] try to account for sloppy subtitle file naming --- .../MediaInfo/SubtitleResolver.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs b/MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs index 30995ebad7..2c748d2b7e 100644 --- a/MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs +++ b/MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs @@ -33,12 +33,14 @@ namespace MediaBrowser.Providers.MediaInfo var streams = new List(); var videoFileNameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(video.Path); + videoFileNameWithoutExtension = NormalizeFilenameForSubtitleComparison(videoFileNameWithoutExtension); foreach (var file in files) { var fullName = file.FullName; var fileNameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(file); + fileNameWithoutExtension = NormalizeFilenameForSubtitleComparison(fileNameWithoutExtension); var codec = Path.GetExtension(fullName).ToLower().TrimStart('.'); @@ -59,6 +61,8 @@ namespace MediaBrowser.Providers.MediaInfo var isForced = fullName.IndexOf(".forced.", StringComparison.OrdinalIgnoreCase) != -1 || fullName.IndexOf(".foreign.", StringComparison.OrdinalIgnoreCase) != -1; + var isDefault = fullName.IndexOf(".default.", StringComparison.OrdinalIgnoreCase) != -1; + // Support xbmc naming conventions - 300.spanish.srt var language = fileNameWithoutExtension .Replace(".forced", string.Empty, StringComparison.OrdinalIgnoreCase) @@ -84,7 +88,8 @@ namespace MediaBrowser.Providers.MediaInfo Path = fullName, Codec = codec, Language = language, - IsForced = isForced + IsForced = isForced, + IsDefault = isDefault }); } } @@ -92,6 +97,18 @@ namespace MediaBrowser.Providers.MediaInfo return streams; } + private string NormalizeFilenameForSubtitleComparison(string filename) + { + // Try to account for sloppy file naming + filename = filename.Replace("-", string.Empty); + filename = filename.Replace("_", string.Empty); + filename = filename.Replace(" ", string.Empty); + + //filename = filename.Replace(".", string.Empty); + + return filename; + } + private static IEnumerable SubtitleExtensions { get