Fixed: .srt files in subfolders are not being imported (#3647)

* Fixed #1958
- extra file module will search for any subfolder and filename
- fixed language parser to match RARBG format
- Add .srt subs according to level of details such that higher detailed sub gets loaded to media player first

* Fixed Code Factor issue on SubtitleService.cs:104

* Fixed: issues on unit test for TV subs; added test cases for RARBG movie subs

* Updated RARBG parser so it won't match movie title format

* Cleaned up code for review

* Update SubtitleService.cs
jpogs 5 years ago committed by Qstick
parent 61629a527c
commit c27f08738a

@ -70,6 +70,10 @@ namespace NzbDrone.Core.Test.ParserTests
[TestCase("2 Broke Girls - S01E01 - Pilot.sub", Language.Unknown)]
[TestCase("2 Broke Girls - S01E01 - Pilot.eng.forced.sub", Language.English)]
[TestCase("2 Broke Girls - S01E01 - Pilot-eng-forced.sub", Language.English)]
[TestCase("2_Eng.srt", Language.English)]
[TestCase("3_English.srt", Language.English)]
[TestCase("Title.2000.1080p.BluRay.H264.AAC-RARBG.idx", Language.Unknown)]
[TestCase("Title.2000.1080p.BluRay.H264.AAC-RARBG.sub", Language.Unknown)]
public void should_parse_subtitle_language(string fileName, Language language)
{
var result = LanguageParser.ParseSubtitleLanguage(fileName);

@ -66,15 +66,13 @@ namespace NzbDrone.Core.Extras
var sourcePath = localMovie.Path;
var sourceFolder = _diskProvider.GetParentFolder(sourcePath);
var sourceFileName = Path.GetFileNameWithoutExtension(sourcePath);
var files = _diskProvider.GetFiles(sourceFolder, SearchOption.TopDirectoryOnly);
var files = _diskProvider.GetFiles(sourceFolder, SearchOption.AllDirectories).OrderByDescending(d => d).ToArray();
var wantedExtensions = _configService.ExtraFileExtensions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(e => e.Trim(' ', '.'))
.ToList();
var matchingFilenames = files.Where(f => Path.GetFileNameWithoutExtension(f).StartsWith(sourceFileName, StringComparison.InvariantCultureIgnoreCase));
foreach (var matchingFilename in matchingFilenames)
foreach (var matchingFilename in files)
{
var matchingExtension = wantedExtensions.FirstOrDefault(e => matchingFilename.EndsWith(e));

@ -88,11 +88,22 @@ namespace NzbDrone.Core.Extras.Subtitles
if (SubtitleFileExtensions.Extensions.Contains(Path.GetExtension(path)))
{
var language = LanguageParser.ParseSubtitleLanguage(path);
var suffix = GetSuffix(language, 1, false);
var subtitleFile = ImportFile(movie, movieFile, path, readOnly, extension, suffix);
subtitleFile.Language = language;
var subtitleFiles = _subtitleFileService.GetFilesByMovie(movie.Id);
var existingSrtSubs = subtitleFiles.Where(m => m.MovieFileId == movieFile.Id)
.Where(m => m.Language == language)
.Where(m => m.Extension == extension);
var suffix = GetSuffix(language, existingSrtSubs.Count() + 1, extension.EqualsIgnoreCase(".srt"));
var subtitleFile = new SubtitleFile();
if ((extension.EqualsIgnoreCase(".srt") && language != Language.Unknown) ||
!extension.EqualsIgnoreCase(".srt"))
{
subtitleFile = ImportFile(movie, movieFile, path, readOnly, extension, suffix);
subtitleFile.Language = language;
_subtitleFileService.Upsert(subtitleFile);
_subtitleFileService.Upsert(subtitleFile);
}
return subtitleFile;
}

@ -15,9 +15,8 @@ namespace NzbDrone.Core.Parser
private static readonly Regex LanguageRegex = new Regex(@"(?:\W|_|^)(?<italian>\b(?:ita|italian)\b)|(?<german>german\b|videomann)|(?<flemish>flemish)|(?<greek>greek)|(?<french>(?:\W|_)(?:FR|VOSTFR|VO|VFF|VFQ|VF2|TRUEFRENCH)(?:\W|_))|(?<russian>\brus\b)|(?<dutch>nl\W?subs?)|(?<hungarian>\b(?:HUNDUB|HUN)\b)|(?<hebrew>\bHebDub\b)|(?<czech>\b(?:CZ|SK)\b)|(?<ukrainian>\bukr\b)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex SubtitleLanguageRegex = new Regex(".+?[-_. ](?<iso_code>[a-z]{2,3})(?:[-_. ]forced)?$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex RarbgSubtitleLanguageRegex = new Regex("^[0-9]{1,2}_(?<iso_code>[A-Za-z]{2,3}).*$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static List<Language> ParseLanguages(string title)
{
var lowerTitle = title.ToLower();
@ -153,13 +152,19 @@ namespace NzbDrone.Core.Parser
var simpleFilename = Path.GetFileNameWithoutExtension(fileName);
var languageMatch = SubtitleLanguageRegex.Match(simpleFilename);
if (!languageMatch.Success)
{
languageMatch = RarbgSubtitleLanguageRegex.Match(simpleFilename);
}
if (languageMatch.Success)
{
var isoCode = languageMatch.Groups["iso_code"].Value;
var isoLanguage = IsoLanguages.Find(isoCode);
var isoLanguage = IsoLanguages.Find(isoCode.ToLower());
return isoLanguage?.Language ?? Language.Unknown;
Logger.Debug("Parsed language: {0}", isoLanguage?.Language ?? Language.Unknown);
return isoLanguage?.Language ?? Language.Unknown;
}
#if !LIBRARY
Logger.Debug("Unable to parse langauge from subtitle file: {0}", fileName);

Loading…
Cancel
Save