|
|
|
@ -72,7 +72,7 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
|
foreach (var movieFile in movieFiles)
|
|
|
|
|
{
|
|
|
|
|
var groupedExtraFilesForMovieFile = subtitleFiles.Where(m => m.MovieFileId == movieFile.Id)
|
|
|
|
|
.GroupBy(s => s.Language + s.Extension).ToList();
|
|
|
|
|
.GroupBy(s => s.AggregateString).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var group in groupedExtraFilesForMovieFile)
|
|
|
|
|
{
|
|
|
|
@ -81,7 +81,7 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
|
|
|
|
|
|
foreach (var subtitleFile in group)
|
|
|
|
|
{
|
|
|
|
|
var suffix = GetSuffix(subtitleFile.Language, copy, groupCount > 1);
|
|
|
|
|
var suffix = GetSuffix(subtitleFile.Language, copy, subtitleFile.LanguageTags, groupCount > 1);
|
|
|
|
|
movedFiles.AddIfNotNull(MoveFile(movie, movieFile, subtitleFile, suffix));
|
|
|
|
|
|
|
|
|
|
copy++;
|
|
|
|
@ -116,7 +116,7 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Filename match
|
|
|
|
|
if (Path.GetFileNameWithoutExtension(file).StartsWith(sourceFileName, StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
|
if (Path.GetFileNameWithoutExtension(file).StartsWithIgnoreCase(sourceFileName))
|
|
|
|
|
{
|
|
|
|
|
matchingFiles.Add(file);
|
|
|
|
|
continue;
|
|
|
|
@ -175,16 +175,24 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var subtitleFiles = new List<Tuple<string, Language, string>>();
|
|
|
|
|
var subtitleFiles = new List<SubtitleFile>();
|
|
|
|
|
|
|
|
|
|
foreach (string file in matchingFiles)
|
|
|
|
|
{
|
|
|
|
|
var language = LanguageParser.ParseSubtitleLanguage(file);
|
|
|
|
|
var extension = Path.GetExtension(file);
|
|
|
|
|
subtitleFiles.Add(new Tuple<string, Language, string>(file, language, extension));
|
|
|
|
|
var languageTags = LanguageParser.ParseLanguageTags(file);
|
|
|
|
|
var subFile = new SubtitleFile
|
|
|
|
|
{
|
|
|
|
|
Language = language,
|
|
|
|
|
Extension = extension
|
|
|
|
|
};
|
|
|
|
|
subFile.LanguageTags = languageTags.ToList();
|
|
|
|
|
subFile.RelativePath = PathExtensions.GetRelativePath(sourceFolder, file);
|
|
|
|
|
subtitleFiles.Add(subFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var groupedSubtitleFiles = subtitleFiles.GroupBy(s => s.Item2 + s.Item3).ToList();
|
|
|
|
|
var groupedSubtitleFiles = subtitleFiles.GroupBy(s => s.AggregateString).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var group in groupedSubtitleFiles)
|
|
|
|
|
{
|
|
|
|
@ -193,14 +201,15 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
|
|
|
|
|
|
foreach (var file in group)
|
|
|
|
|
{
|
|
|
|
|
var path = Path.Combine(sourceFolder, file.RelativePath);
|
|
|
|
|
var language = file.Language;
|
|
|
|
|
var extension = file.Extension;
|
|
|
|
|
var suffix = GetSuffix(language, copy, file.LanguageTags, groupCount > 1);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var path = file.Item1;
|
|
|
|
|
var language = file.Item2;
|
|
|
|
|
var extension = file.Item3;
|
|
|
|
|
var suffix = GetSuffix(language, copy, groupCount > 1);
|
|
|
|
|
var subtitleFile = ImportFile(localMovie.Movie, movieFile, path, isReadOnly, extension, suffix);
|
|
|
|
|
subtitleFile.Language = language;
|
|
|
|
|
subtitleFile.LanguageTags = file.LanguageTags;
|
|
|
|
|
|
|
|
|
|
_mediaFileAttributeService.SetFilePermissions(path);
|
|
|
|
|
_subtitleFileService.Upsert(subtitleFile);
|
|
|
|
@ -211,7 +220,7 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.Warn(ex, "Failed to import subtitle file: {0}", file.Item1);
|
|
|
|
|
_logger.Warn(ex, "Failed to import subtitle file: {0}", path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -219,7 +228,7 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
|
return importedFiles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetSuffix(Language language, int copy, bool multipleCopies = false)
|
|
|
|
|
private string GetSuffix(Language language, int copy, List<string> languageTags, bool multipleCopies = false)
|
|
|
|
|
{
|
|
|
|
|
var suffixBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
|
@ -235,6 +244,12 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
|
suffixBuilder.Append(IsoLanguages.Get(language).TwoLetterCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (languageTags.Any())
|
|
|
|
|
{
|
|
|
|
|
suffixBuilder.Append(".");
|
|
|
|
|
suffixBuilder.Append(string.Join(".", languageTags));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return suffixBuilder.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|