Explorar o código

try to account for sloppy subtitle file naming

Luke Pulverenti %!s(int64=9) %!d(string=hai) anos
pai
achega
0dcd698c17
Modificáronse 1 ficheiros con 18 adicións e 1 borrados
  1. 18 1
      MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs

+ 18 - 1
MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs

@@ -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