|
|
|
@ -411,50 +411,6 @@ namespace MediaBrowser.Providers.MediaInfo
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<string> SubtitleExtensions
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new[] { ".srt", ".ssa", ".ass", ".sub" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<FileSystemInfo> GetSubtitleFiles(Video video, IDirectoryService directoryService, bool clearCache)
|
|
|
|
|
{
|
|
|
|
|
var containingPath = video.ContainingFolderPath;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(containingPath))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException(string.Format("Cannot search for items that don't have a path: {0} {1}", video.Name, video.Id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var files = directoryService.GetFiles(containingPath, clearCache);
|
|
|
|
|
|
|
|
|
|
var videoFileNameWithoutExtension = Path.GetFileNameWithoutExtension(video.Path);
|
|
|
|
|
|
|
|
|
|
return files.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
if (!i.Attributes.HasFlag(FileAttributes.Directory) &&
|
|
|
|
|
SubtitleExtensions.Contains(i.Extension, StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var fullName = i.FullName;
|
|
|
|
|
|
|
|
|
|
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullName);
|
|
|
|
|
|
|
|
|
|
if (string.Equals(videoFileNameWithoutExtension, fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (fileNameWithoutExtension.StartsWith(videoFileNameWithoutExtension + ".", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds the external subtitles.
|
|
|
|
|
/// </summary>
|
|
|
|
@ -462,7 +418,9 @@ namespace MediaBrowser.Providers.MediaInfo
|
|
|
|
|
/// <param name="currentStreams">The current streams.</param>
|
|
|
|
|
private async Task AddExternalSubtitles(Video video, List<MediaStream> currentStreams, IDirectoryService directoryService, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var externalSubtitleStreams = GetExternalSubtitleStreams(video, currentStreams.Count, directoryService, false).ToList();
|
|
|
|
|
var subtitleResolver = new SubtitleResolver(_localization);
|
|
|
|
|
|
|
|
|
|
var externalSubtitleStreams = subtitleResolver.GetExternalSubtitleStreams(video, currentStreams.Count, directoryService, false).ToList();
|
|
|
|
|
|
|
|
|
|
if ((_config.Configuration.SubtitleOptions.DownloadEpisodeSubtitles &&
|
|
|
|
|
video is Episode) ||
|
|
|
|
@ -482,7 +440,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
|
|
|
|
// Rescan
|
|
|
|
|
if (downloadedLanguages.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
externalSubtitleStreams = GetExternalSubtitleStreams(video, currentStreams.Count, directoryService, true).ToList();
|
|
|
|
|
externalSubtitleStreams = subtitleResolver.GetExternalSubtitleStreams(video, currentStreams.Count, directoryService, true).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -491,65 +449,6 @@ namespace MediaBrowser.Providers.MediaInfo
|
|
|
|
|
currentStreams.AddRange(externalSubtitleStreams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<MediaStream> GetExternalSubtitleStreams(Video video,
|
|
|
|
|
int startIndex,
|
|
|
|
|
IDirectoryService directoryService,
|
|
|
|
|
bool clearCache)
|
|
|
|
|
{
|
|
|
|
|
var files = GetSubtitleFiles(video, directoryService, clearCache);
|
|
|
|
|
|
|
|
|
|
var streams = new List<MediaStream>();
|
|
|
|
|
|
|
|
|
|
var videoFileNameWithoutExtension = Path.GetFileNameWithoutExtension(video.Path);
|
|
|
|
|
|
|
|
|
|
foreach (var file in files)
|
|
|
|
|
{
|
|
|
|
|
var fullName = file.FullName;
|
|
|
|
|
|
|
|
|
|
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullName);
|
|
|
|
|
|
|
|
|
|
// If the subtitle file matches the video file name
|
|
|
|
|
if (string.Equals(videoFileNameWithoutExtension, fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
streams.Add(new MediaStream
|
|
|
|
|
{
|
|
|
|
|
Index = startIndex++,
|
|
|
|
|
Type = MediaStreamType.Subtitle,
|
|
|
|
|
IsExternal = true,
|
|
|
|
|
Path = fullName,
|
|
|
|
|
Codec = Path.GetExtension(fullName).ToLower().TrimStart('.')
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (fileNameWithoutExtension.StartsWith(videoFileNameWithoutExtension + ".", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
// Support xbmc naming conventions - 300.spanish.srt
|
|
|
|
|
var language = fileNameWithoutExtension.Split('.').LastOrDefault();
|
|
|
|
|
|
|
|
|
|
// Try to translate to three character code
|
|
|
|
|
// Be flexible and check against both the full and three character versions
|
|
|
|
|
var culture = _localization.GetCultures()
|
|
|
|
|
.FirstOrDefault(i => string.Equals(i.DisplayName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Name, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.ThreeLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.TwoLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
if (culture != null)
|
|
|
|
|
{
|
|
|
|
|
language = culture.ThreeLetterISOLanguageName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
streams.Add(new MediaStream
|
|
|
|
|
{
|
|
|
|
|
Index = startIndex++,
|
|
|
|
|
Type = MediaStreamType.Subtitle,
|
|
|
|
|
IsExternal = true,
|
|
|
|
|
Path = fullName,
|
|
|
|
|
Codec = Path.GetExtension(fullName).ToLower().TrimStart('.'),
|
|
|
|
|
Language = language
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return streams;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The dummy chapter duration
|
|
|
|
|
/// </summary>
|
|
|
|
|