|
|
@ -72,7 +72,7 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
foreach (var episodeFile in episodeFiles)
|
|
|
|
foreach (var episodeFile in episodeFiles)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var groupedExtraFilesForEpisodeFile = subtitleFiles.Where(m => m.EpisodeFileId == episodeFile.Id)
|
|
|
|
var groupedExtraFilesForEpisodeFile = subtitleFiles.Where(m => m.EpisodeFileId == episodeFile.Id)
|
|
|
|
.GroupBy(s => s.Language + s.Extension).ToList();
|
|
|
|
.GroupBy(s => s.AggregateString).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var group in groupedExtraFilesForEpisodeFile)
|
|
|
|
foreach (var group in groupedExtraFilesForEpisodeFile)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -81,7 +81,7 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var subtitleFile in group)
|
|
|
|
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(series, episodeFile, subtitleFile, suffix));
|
|
|
|
movedFiles.AddIfNotNull(MoveFile(series, episodeFile, subtitleFile, suffix));
|
|
|
|
|
|
|
|
|
|
|
|
copy++;
|
|
|
|
copy++;
|
|
|
@ -116,7 +116,7 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Filename match
|
|
|
|
// Filename match
|
|
|
|
if (Path.GetFileNameWithoutExtension(file).StartsWith(sourceFileName, StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
if (Path.GetFileNameWithoutExtension(file).StartsWithIgnoreCase(sourceFileName))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
matchingFiles.Add(file);
|
|
|
|
matchingFiles.Add(file);
|
|
|
|
continue;
|
|
|
|
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)
|
|
|
|
foreach (string file in matchingFiles)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var language = LanguageParser.ParseSubtitleLanguage(file);
|
|
|
|
var language = LanguageParser.ParseSubtitleLanguage(file);
|
|
|
|
var extension = Path.GetExtension(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)
|
|
|
|
foreach (var group in groupedSubtitleFiles)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -193,14 +201,15 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var file in group)
|
|
|
|
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
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var path = file.Item1;
|
|
|
|
|
|
|
|
var language = file.Item2;
|
|
|
|
|
|
|
|
var extension = file.Item3;
|
|
|
|
|
|
|
|
var suffix = GetSuffix(language, copy, groupCount > 1);
|
|
|
|
|
|
|
|
var subtitleFile = ImportFile(localEpisode.Series, episodeFile, path, isReadOnly, extension, suffix);
|
|
|
|
var subtitleFile = ImportFile(localEpisode.Series, episodeFile, path, isReadOnly, extension, suffix);
|
|
|
|
subtitleFile.Language = language;
|
|
|
|
subtitleFile.Language = language;
|
|
|
|
|
|
|
|
subtitleFile.LanguageTags = file.LanguageTags;
|
|
|
|
|
|
|
|
|
|
|
|
_mediaFileAttributeService.SetFilePermissions(path);
|
|
|
|
_mediaFileAttributeService.SetFilePermissions(path);
|
|
|
|
_subtitleFileService.Upsert(subtitleFile);
|
|
|
|
_subtitleFileService.Upsert(subtitleFile);
|
|
|
@ -211,7 +220,7 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
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;
|
|
|
|
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();
|
|
|
|
var suffixBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
@ -235,6 +244,12 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|
|
|
suffixBuilder.Append(IsoLanguages.Get(language).TwoLetterCode);
|
|
|
|
suffixBuilder.Append(IsoLanguages.Get(language).TwoLetterCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (languageTags.Any())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
suffixBuilder.Append(".");
|
|
|
|
|
|
|
|
suffixBuilder.Append(string.Join(".", languageTags));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return suffixBuilder.ToString();
|
|
|
|
return suffixBuilder.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|