try to account for sloppy subtitle file naming

This commit is contained in:
Luke Pulverenti 2015-12-26 13:35:53 -05:00
parent fda7c3e9f8
commit 0dcd698c17

View File

@ -33,12 +33,14 @@ namespace MediaBrowser.Providers.MediaInfo
var streams = new List<MediaStream>();
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<string> SubtitleExtensions
{
get