mirror of https://github.com/Radarr/Radarr
New: Import subtitles from sub folders
This commit is contained in:
parent
c8ab4f8c68
commit
dd5bc41eda
|
@ -0,0 +1,245 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Extras;
|
||||
using NzbDrone.Core.Extras.Files;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.Extras
|
||||
{
|
||||
[TestFixture]
|
||||
public class ExtraServiceFixture : CoreTest<ExtraService>
|
||||
{
|
||||
private Movie _movie;
|
||||
private MovieFile _movieFile;
|
||||
private LocalMovie _localMovie;
|
||||
|
||||
private string _movieFolder;
|
||||
private string _releaseFolder;
|
||||
|
||||
private Mock<IManageExtraFiles> _subtitleService;
|
||||
private Mock<IManageExtraFiles> _otherExtraService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_movieFolder = @"C:\Test\Movies\Movie Title".AsOsAgnostic();
|
||||
_releaseFolder = @"C:\Test\Unsorted TV\Movie.Title.2022".AsOsAgnostic();
|
||||
|
||||
_movie = Builder<Movie>.CreateNew()
|
||||
.With(s => s.Path = _movieFolder)
|
||||
.Build();
|
||||
|
||||
_movieFile = Builder<MovieFile>.CreateNew()
|
||||
.With(f => f.Path = Path.Combine(_movie.Path, "Movie Title - 2022.mkv").AsOsAgnostic())
|
||||
.With(f => f.RelativePath = @"Movie Title - 2022.mkv".AsOsAgnostic())
|
||||
.Build();
|
||||
|
||||
_localMovie = Builder<LocalMovie>.CreateNew()
|
||||
.With(l => l.Movie = _movie)
|
||||
.With(l => l.Path = Path.Combine(_releaseFolder, "Movie.Title.2022.mkv").AsOsAgnostic())
|
||||
.Build();
|
||||
|
||||
_subtitleService = new Mock<IManageExtraFiles>();
|
||||
_subtitleService.SetupGet(s => s.Order).Returns(0);
|
||||
_subtitleService.Setup(s => s.CanImportFile(It.IsAny<LocalMovie>(), It.IsAny<MovieFile>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Returns(false);
|
||||
_subtitleService.Setup(s => s.CanImportFile(It.IsAny<LocalMovie>(), It.IsAny<MovieFile>(), It.IsAny<string>(), ".srt", It.IsAny<bool>()))
|
||||
.Returns(true);
|
||||
|
||||
_otherExtraService = new Mock<IManageExtraFiles>();
|
||||
_otherExtraService.SetupGet(s => s.Order).Returns(1);
|
||||
_otherExtraService.Setup(s => s.CanImportFile(It.IsAny<LocalMovie>(), It.IsAny<MovieFile>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Returns(true);
|
||||
|
||||
Mocker.SetConstant<IEnumerable<IManageExtraFiles>>(new[]
|
||||
{
|
||||
_subtitleService.Object,
|
||||
_otherExtraService.Object
|
||||
});
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.FolderExists(It.IsAny<string>()))
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetParentFolder(It.IsAny<string>()))
|
||||
.Returns((string path) => Directory.GetParent(path).FullName);
|
||||
|
||||
WithExistingFolder(_movie.Path);
|
||||
WithExistingFile(_movieFile.Path);
|
||||
WithExistingFile(_localMovie.Path);
|
||||
|
||||
Mocker.GetMock<IConfigService>().Setup(v => v.ImportExtraFiles).Returns(true);
|
||||
Mocker.GetMock<IConfigService>().Setup(v => v.ExtraFileExtensions).Returns("nfo,srt");
|
||||
}
|
||||
|
||||
private void WithExistingFolder(string path, bool exists = true)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(path);
|
||||
|
||||
if (exists && dir.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
WithExistingFolder(dir);
|
||||
}
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(v => v.FolderExists(path)).Returns(exists);
|
||||
}
|
||||
|
||||
private void WithExistingFile(string path, bool exists = true, int size = 1000)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(path);
|
||||
|
||||
if (exists && dir.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
WithExistingFolder(dir);
|
||||
}
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(v => v.FileExists(path)).Returns(exists);
|
||||
Mocker.GetMock<IDiskProvider>().Setup(v => v.GetFileSize(path)).Returns(size);
|
||||
}
|
||||
|
||||
private void WithExistingFiles(List<string> files)
|
||||
{
|
||||
foreach (string file in files)
|
||||
{
|
||||
WithExistingFile(file);
|
||||
}
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(_releaseFolder, It.IsAny<SearchOption>()))
|
||||
.Returns(files.ToArray());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_pass_file_if_import_disabled()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>().Setup(v => v.ImportExtraFiles).Returns(false);
|
||||
|
||||
var nfofile = Path.Combine(_releaseFolder, "Movie.Title.2022.nfo").AsOsAgnostic();
|
||||
|
||||
var files = new List<string>
|
||||
{
|
||||
_localMovie.Path,
|
||||
nfofile
|
||||
};
|
||||
|
||||
WithExistingFiles(files);
|
||||
|
||||
Subject.ImportMovie(_localMovie, _movieFile, true);
|
||||
|
||||
_subtitleService.Verify(v => v.CanImportFile(_localMovie, _movieFile, It.IsAny<string>(), It.IsAny<string>(), true), Times.Never());
|
||||
_otherExtraService.Verify(v => v.CanImportFile(_localMovie, _movieFile, It.IsAny<string>(), It.IsAny<string>(), true), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase("Movie Title - 2022.sub")]
|
||||
[TestCase("Movie Title - 2022.ass")]
|
||||
public void should_not_pass_unwanted_file(string filePath)
|
||||
{
|
||||
Mocker.GetMock<IConfigService>().Setup(v => v.ImportExtraFiles).Returns(false);
|
||||
|
||||
var nfofile = Path.Combine(_releaseFolder, filePath).AsOsAgnostic();
|
||||
|
||||
var files = new List<string>
|
||||
{
|
||||
_localMovie.Path,
|
||||
nfofile
|
||||
};
|
||||
|
||||
WithExistingFiles(files);
|
||||
|
||||
Subject.ImportMovie(_localMovie, _movieFile, true);
|
||||
|
||||
_subtitleService.Verify(v => v.CanImportFile(_localMovie, _movieFile, It.IsAny<string>(), It.IsAny<string>(), true), Times.Never());
|
||||
_otherExtraService.Verify(v => v.CanImportFile(_localMovie, _movieFile, It.IsAny<string>(), It.IsAny<string>(), true), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_pass_subtitle_file_to_subtitle_service()
|
||||
{
|
||||
var subtitleFile = Path.Combine(_releaseFolder, "Movie.Title.2022.en.srt").AsOsAgnostic();
|
||||
|
||||
var files = new List<string>
|
||||
{
|
||||
_localMovie.Path,
|
||||
subtitleFile
|
||||
};
|
||||
|
||||
WithExistingFiles(files);
|
||||
|
||||
Subject.ImportMovie(_localMovie, _movieFile, true);
|
||||
|
||||
_subtitleService.Verify(v => v.ImportFiles(_localMovie, _movieFile, new List<string> { subtitleFile }, true), Times.Once());
|
||||
_otherExtraService.Verify(v => v.ImportFiles(_localMovie, _movieFile, new List<string> { subtitleFile }, true), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_pass_nfo_file_to_other_service()
|
||||
{
|
||||
var nfofile = Path.Combine(_releaseFolder, "Movie.Title.2022.nfo").AsOsAgnostic();
|
||||
|
||||
var files = new List<string>
|
||||
{
|
||||
_localMovie.Path,
|
||||
nfofile
|
||||
};
|
||||
|
||||
WithExistingFiles(files);
|
||||
|
||||
Subject.ImportMovie(_localMovie, _movieFile, true);
|
||||
|
||||
_subtitleService.Verify(v => v.ImportFiles(_localMovie, _movieFile, new List<string> { nfofile }, true), Times.Never());
|
||||
_otherExtraService.Verify(v => v.ImportFiles(_localMovie, _movieFile, new List<string> { nfofile }, true), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_search_subtitles_when_importing_from_job_folder()
|
||||
{
|
||||
_localMovie.FolderMovieInfo = new ParsedMovieInfo();
|
||||
|
||||
var subtitleFile = Path.Combine(_releaseFolder, "Movie.Title.2022.en.srt").AsOsAgnostic();
|
||||
|
||||
var files = new List<string>
|
||||
{
|
||||
_localMovie.Path,
|
||||
subtitleFile
|
||||
};
|
||||
|
||||
WithExistingFiles(files);
|
||||
|
||||
Subject.ImportMovie(_localMovie, _movieFile, true);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_releaseFolder, SearchOption.AllDirectories), Times.Once);
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_releaseFolder, SearchOption.TopDirectoryOnly), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_search_subtitles_when_not_importing_from_job_folder()
|
||||
{
|
||||
_localMovie.FolderMovieInfo = null;
|
||||
|
||||
var subtitleFile = Path.Combine(_releaseFolder, "Movie.Title.2022.en.srt").AsOsAgnostic();
|
||||
|
||||
var files = new List<string>
|
||||
{
|
||||
_localMovie.Path,
|
||||
subtitleFile
|
||||
};
|
||||
|
||||
WithExistingFiles(files);
|
||||
|
||||
Subject.ImportMovie(_localMovie, _movieFile, true);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_releaseFolder, SearchOption.AllDirectories), Times.Never);
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_releaseFolder, SearchOption.TopDirectoryOnly), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Extras.Others;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.Extras.Others
|
||||
{
|
||||
[TestFixture]
|
||||
public class OtherExtraServiceFixture : CoreTest<OtherExtraService>
|
||||
{
|
||||
private Movie _movie;
|
||||
private MovieFile _movieFile;
|
||||
private LocalMovie _localMovie;
|
||||
|
||||
private string _movieFolder;
|
||||
private string _releaseFolder;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_movieFolder = @"C:\Test\Movies\Movie Title".AsOsAgnostic();
|
||||
_releaseFolder = @"C:\Test\Unsorted Movies\Movie.Title.2022".AsOsAgnostic();
|
||||
|
||||
_movie = Builder<Movie>.CreateNew()
|
||||
.With(s => s.Path = _movieFolder)
|
||||
.Build();
|
||||
|
||||
_movieFile = Builder<MovieFile>.CreateNew()
|
||||
.With(f => f.Path = Path.Combine(_movie.Path, "Movie Title - 2022.mkv").AsOsAgnostic())
|
||||
.With(f => f.RelativePath = @"Movie Title - 2022.mkv")
|
||||
.Build();
|
||||
|
||||
_localMovie = Builder<LocalMovie>.CreateNew()
|
||||
.With(l => l.Movie = _movie)
|
||||
.With(l => l.Path = Path.Combine(_releaseFolder, "Movie.Title.2022.mkv").AsOsAgnostic())
|
||||
.With(l => l.FileMovieInfo = new ParsedMovieInfo
|
||||
{
|
||||
MovieTitles = new List<string> { "Movie Title" },
|
||||
Year = 2022
|
||||
})
|
||||
.Build();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase("Movie Title - 2022.nfo", "Movie Title - 2022.nfo")]
|
||||
[TestCase("Movie.Title.2022.nfo", "Movie Title - 2022.nfo")]
|
||||
[TestCase("Movie Title 2022.nfo", "Movie Title - 2022.nfo")]
|
||||
[TestCase("Movie_Title_2022.nfo", "Movie Title - 2022.nfo")]
|
||||
[TestCase(@"Movie.Title.2022\thumb.jpg", "Movie Title - 2022.jpg")]
|
||||
public void should_import_matching_file(string filePath, string expectedOutputPath)
|
||||
{
|
||||
var files = new List<string> { Path.Combine(_releaseFolder, filePath).AsOsAgnostic() };
|
||||
|
||||
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
|
||||
|
||||
results.Count().Should().Be(1);
|
||||
|
||||
results[0].RelativePath.AsOsAgnostic().PathEquals(expectedOutputPath.AsOsAgnostic()).Should().Be(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_import_multiple_nfo_files()
|
||||
{
|
||||
var files = new List<string>
|
||||
{
|
||||
Path.Combine(_releaseFolder, "Movie.Title.2022.nfo").AsOsAgnostic(),
|
||||
Path.Combine(_releaseFolder, "Movie_Title_2022.nfo").AsOsAgnostic(),
|
||||
};
|
||||
|
||||
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
|
||||
|
||||
results.Count().Should().Be(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Extras.Subtitles;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.MovieImport;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.Extras.Subtitles
|
||||
{
|
||||
[TestFixture]
|
||||
public class SubtitleServiceFixture : CoreTest<SubtitleService>
|
||||
{
|
||||
private Movie _movie;
|
||||
private MovieFile _movieFile;
|
||||
private LocalMovie _localMovie;
|
||||
|
||||
private string _MovieFolder;
|
||||
private string _releaseFolder;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_MovieFolder = @"C:\Test\Movies\Movie Title".AsOsAgnostic();
|
||||
_releaseFolder = @"C:\Test\Unsorted Movies\Movie.Title.2022".AsOsAgnostic();
|
||||
|
||||
_movie = Builder<Movie>.CreateNew()
|
||||
.With(s => s.Path = _MovieFolder)
|
||||
.Build();
|
||||
|
||||
_movieFile = Builder<MovieFile>.CreateNew()
|
||||
.With(f => f.Path = Path.Combine(_movie.Path, "Movie Title - 2022.mkv").AsOsAgnostic())
|
||||
.With(f => f.RelativePath = @"Movie Title - 2022.mkv".AsOsAgnostic())
|
||||
.Build();
|
||||
|
||||
_localMovie = Builder<LocalMovie>.CreateNew()
|
||||
.With(l => l.Movie = _movie)
|
||||
.With(l => l.Path = Path.Combine(_releaseFolder, "Movie.Title.2022.mkv").AsOsAgnostic())
|
||||
.With(l => l.FileMovieInfo = new ParsedMovieInfo
|
||||
{
|
||||
MovieTitles = new List<string> { "Movie Title" },
|
||||
Year = 2022
|
||||
})
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetParentFolder(It.IsAny<string>()))
|
||||
.Returns((string path) => Directory.GetParent(path).FullName);
|
||||
|
||||
Mocker.GetMock<IDetectSample>().Setup(s => s.IsSample(It.IsAny<MovieMetadata>(), It.IsAny<string>()))
|
||||
.Returns(DetectSampleResult.NotSample);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase("Movie.Title.2022.en.nfo")]
|
||||
public void should_not_import_non_subtitle_file(string filePath)
|
||||
{
|
||||
var files = new List<string> { Path.Combine(_releaseFolder, filePath).AsOsAgnostic() };
|
||||
|
||||
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
|
||||
|
||||
results.Count().Should().Be(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase("Movie Title - 2022.srt", "Movie Title - 2022.srt")]
|
||||
[TestCase("Movie.Title.2022.en.srt", "Movie Title - 2022.en.srt")]
|
||||
[TestCase("Movie.Title.2022.english.srt", "Movie Title - 2022.en.srt")]
|
||||
[TestCase("Movie Title 2022_en_sdh_forced.srt", "Movie Title - 2022.en.srt")]
|
||||
[TestCase("Movie_Title_2022 en.srt", "Movie Title - 2022.en.srt")]
|
||||
[TestCase(@"Subs\Movie.Title.2022\2_en.srt", "Movie Title - 2022.en.srt")]
|
||||
[TestCase("sub.srt", "Movie Title - 2022.srt")]
|
||||
public void should_import_matching_subtitle_file(string filePath, string expectedOutputPath)
|
||||
{
|
||||
var files = new List<string> { Path.Combine(_releaseFolder, filePath).AsOsAgnostic() };
|
||||
|
||||
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
|
||||
|
||||
results.Count().Should().Be(1);
|
||||
|
||||
results[0].RelativePath.AsOsAgnostic().PathEquals(expectedOutputPath.AsOsAgnostic()).Should().Be(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_import_multiple_subtitle_files_per_language()
|
||||
{
|
||||
var files = new List<string>
|
||||
{
|
||||
Path.Combine(_releaseFolder, "Movie.Title.2022.en.srt").AsOsAgnostic(),
|
||||
Path.Combine(_releaseFolder, "Movie.Title.2022.english.srt").AsOsAgnostic(),
|
||||
Path.Combine(_releaseFolder, "Subs", "Movie_Title_2022_en_forced.srt").AsOsAgnostic(),
|
||||
Path.Combine(_releaseFolder, "Subs", "Movie.Title.2022", "2_fr.srt").AsOsAgnostic()
|
||||
};
|
||||
|
||||
var expectedOutputs = new string[]
|
||||
{
|
||||
"Movie Title - 2022.1.en.srt",
|
||||
"Movie Title - 2022.2.en.srt",
|
||||
"Movie Title - 2022.3.en.srt",
|
||||
"Movie Title - 2022.fr.srt",
|
||||
};
|
||||
|
||||
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
|
||||
|
||||
results.Count().Should().Be(expectedOutputs.Length);
|
||||
|
||||
for (int i = 0; i < expectedOutputs.Length; i++)
|
||||
{
|
||||
results[i].RelativePath.AsOsAgnostic().PathEquals(expectedOutputs[i].AsOsAgnostic()).Should().Be(true);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_import_multiple_subtitle_files_per_language_with_tags()
|
||||
{
|
||||
var files = new List<string>
|
||||
{
|
||||
Path.Combine(_releaseFolder, "Movie.Title.2022.en.forced.cc.srt").AsOsAgnostic(),
|
||||
Path.Combine(_releaseFolder, "Movie.Title.2022.other.en.forced.cc.srt").AsOsAgnostic(),
|
||||
Path.Combine(_releaseFolder, "Movie.Title.2022.en.forced.sdh.srt").AsOsAgnostic(),
|
||||
Path.Combine(_releaseFolder, "Movie.Title.2022.en.forced.default.srt").AsOsAgnostic(),
|
||||
};
|
||||
|
||||
var expectedOutputs = new[]
|
||||
{
|
||||
"Movie Title - 2022.1.en.forced.cc.srt",
|
||||
"Movie Title - 2022.2.en.forced.cc.srt",
|
||||
"Movie Title - 2022.en.forced.sdh.srt",
|
||||
"Movie Title - 2022.en.forced.default.srt"
|
||||
};
|
||||
|
||||
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
|
||||
|
||||
results.Count().Should().Be(expectedOutputs.Length);
|
||||
|
||||
for (int i = 0; i < expectedOutputs.Length; i++)
|
||||
{
|
||||
results[i].RelativePath.AsOsAgnostic().PathEquals(expectedOutputs[i].AsOsAgnostic()).Should().Be(true);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase(@"Subs\2_en.srt", "Movie Title - 2022.en.srt")]
|
||||
public void should_import_unmatching_subtitle_file_if_only_episode(string filePath, string expectedOutputPath)
|
||||
{
|
||||
var subtitleFile = Path.Combine(_releaseFolder, filePath).AsOsAgnostic();
|
||||
|
||||
var sampleFile = Path.Combine(_movie.Path, "Movie Title - 2022.sample.mkv").AsOsAgnostic();
|
||||
|
||||
var videoFiles = new string[]
|
||||
{
|
||||
_localMovie.Path,
|
||||
sampleFile
|
||||
};
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories))
|
||||
.Returns(videoFiles);
|
||||
|
||||
Mocker.GetMock<IDetectSample>().Setup(s => s.IsSample(It.IsAny<MovieMetadata>(), sampleFile))
|
||||
.Returns(DetectSampleResult.Sample);
|
||||
|
||||
var results = Subject.ImportFiles(_localMovie, _movieFile, new List<string> { subtitleFile }, true).ToList();
|
||||
|
||||
results.Count().Should().Be(1);
|
||||
|
||||
results[0].RelativePath.AsOsAgnostic().PathEquals(expectedOutputPath.AsOsAgnostic()).Should().Be(true);
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,6 +27,22 @@ namespace NzbDrone.Core.Test.ParserTests
|
|||
result.Languages.Should().BeEquivalentTo(Language.Unknown);
|
||||
}
|
||||
|
||||
[TestCase("Movie Title - 2022.en.sub")]
|
||||
[TestCase("Movie Title - 2022.EN.sub")]
|
||||
[TestCase("Movie Title - 2022.eng.sub")]
|
||||
[TestCase("Movie Title - 2022.ENG.sub")]
|
||||
[TestCase("Movie Title - 2022.English.sub")]
|
||||
[TestCase("Movie Title - 2022.english.sub")]
|
||||
[TestCase("Movie Title - 2022.en.cc.sub")]
|
||||
[TestCase("Movie Title - 2022.en.sdh.sub")]
|
||||
[TestCase("Movie Title - 2022.en.forced.sub")]
|
||||
[TestCase("Movie Title - 2022.en.sdh.forced.sub")]
|
||||
public void should_parse_subtitle_language_english(string fileName)
|
||||
{
|
||||
var result = LanguageParser.ParseSubtitleLanguage(fileName);
|
||||
result.Should().Be(Language.English);
|
||||
}
|
||||
|
||||
[TestCase("Movie.Title.1994.French.1080p.XviD-LOL")]
|
||||
[TestCase("Movie Title : Other Title 2011 AVC.1080p.Blu-ray HD.VOSTFR.VFF")]
|
||||
[TestCase("Movie Title - Other Title 2011 Bluray 4k HDR HEVC AC3 VFF")]
|
||||
|
|
|
@ -31,7 +31,6 @@ namespace NzbDrone.Core.Extras
|
|||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly List<IManageExtraFiles> _extraFileManagers;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ExtraService(IMediaFileService mediaFileService,
|
||||
IMovieService movieService,
|
||||
|
@ -45,7 +44,6 @@ namespace NzbDrone.Core.Extras
|
|||
_diskProvider = diskProvider;
|
||||
_configService = configService;
|
||||
_extraFileManagers = extraFileManagers.OrderBy(e => e.Order).ToList();
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void ImportMovie(LocalMovie localMovie, MovieFile movieFile, bool isReadOnly)
|
||||
|
@ -62,61 +60,42 @@ namespace NzbDrone.Core.Extras
|
|||
return;
|
||||
}
|
||||
|
||||
var sourcePath = localMovie.Path;
|
||||
var sourceFolder = _diskProvider.GetParentFolder(sourcePath);
|
||||
var sourceFileName = Path.GetFileNameWithoutExtension(sourcePath);
|
||||
var files = _diskProvider.GetFiles(sourceFolder, SearchOption.AllDirectories).Where(f => f != localMovie.Path);
|
||||
var folderSearchOption = localMovie.FolderMovieInfo == null
|
||||
? SearchOption.TopDirectoryOnly
|
||||
: SearchOption.AllDirectories;
|
||||
|
||||
var wantedExtensions = _configService.ExtraFileExtensions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(e => e.Trim(' ', '.'))
|
||||
.Select(e => e.Trim(' ', '.')
|
||||
.Insert(0, "."))
|
||||
.ToList();
|
||||
|
||||
var matchingFilenames = files.Where(f => Path.GetFileNameWithoutExtension(f).StartsWith(sourceFileName, StringComparison.InvariantCultureIgnoreCase)).ToList();
|
||||
var filteredFilenames = new List<string>();
|
||||
var hasNfo = false;
|
||||
var sourceFolder = _diskProvider.GetParentFolder(localMovie.Path);
|
||||
var files = _diskProvider.GetFiles(sourceFolder, folderSearchOption);
|
||||
var managedFiles = _extraFileManagers.Select((i) => new List<string>()).ToArray();
|
||||
|
||||
foreach (var matchingFilename in matchingFilenames)
|
||||
foreach (var file in files)
|
||||
{
|
||||
// Filter out duplicate NFO files
|
||||
if (matchingFilename.EndsWith(".nfo", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
if (hasNfo)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
hasNfo = true;
|
||||
}
|
||||
|
||||
filteredFilenames.Add(matchingFilename);
|
||||
}
|
||||
|
||||
foreach (var matchingFilename in filteredFilenames)
|
||||
{
|
||||
var matchingExtension = wantedExtensions.FirstOrDefault(e => matchingFilename.EndsWith(e));
|
||||
var extension = Path.GetExtension(file);
|
||||
var matchingExtension = wantedExtensions.FirstOrDefault(e => e.Equals(extension));
|
||||
|
||||
if (matchingExtension == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
for (int i = 0; i < _extraFileManagers.Count; i++)
|
||||
{
|
||||
foreach (var extraFileManager in _extraFileManagers)
|
||||
if (_extraFileManagers[i].CanImportFile(localMovie, movieFile, file, extension, isReadOnly))
|
||||
{
|
||||
var extension = Path.GetExtension(matchingFilename);
|
||||
var extraFile = extraFileManager.Import(localMovie.Movie, movieFile, matchingFilename, extension, isReadOnly);
|
||||
|
||||
if (extraFile != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
managedFiles[i].Add(file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Failed to import extra file: {0}", matchingFilename);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _extraFileManagers.Count; i++)
|
||||
{
|
||||
_extraFileManagers[i].ImportFiles(localMovie, movieFile, managedFiles[i], isReadOnly);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ using NzbDrone.Common.Extensions;
|
|||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Files
|
||||
{
|
||||
|
@ -19,7 +20,8 @@ namespace NzbDrone.Core.Extras.Files
|
|||
IEnumerable<ExtraFile> CreateAfterMovieImport(Movie movie, MovieFile movieFile);
|
||||
IEnumerable<ExtraFile> CreateAfterMovieFolder(Movie movie, string movieFolder);
|
||||
IEnumerable<ExtraFile> MoveFilesAfterRename(Movie movie, List<MovieFile> movieFiles);
|
||||
ExtraFile Import(Movie movie, MovieFile movieFile, string path, string extension, bool readOnly);
|
||||
bool CanImportFile(LocalMovie localMovie, MovieFile movieFile, string path, string extension, bool readOnly);
|
||||
IEnumerable<ExtraFile> ImportFiles(LocalMovie localMovie, MovieFile movieFile, List<string> files, bool isReadOnly);
|
||||
}
|
||||
|
||||
public abstract class ExtraFileManager<TExtraFile> : IManageExtraFiles
|
||||
|
@ -47,7 +49,8 @@ namespace NzbDrone.Core.Extras.Files
|
|||
public abstract IEnumerable<ExtraFile> CreateAfterMovieImport(Movie movie, MovieFile movieFile);
|
||||
public abstract IEnumerable<ExtraFile> CreateAfterMovieFolder(Movie movie, string movieFolder);
|
||||
public abstract IEnumerable<ExtraFile> MoveFilesAfterRename(Movie movie, List<MovieFile> movieFiles);
|
||||
public abstract ExtraFile Import(Movie movie, MovieFile movieFile, string path, string extension, bool readOnly);
|
||||
public abstract bool CanImportFile(LocalMovie localMovie, MovieFile movieFile, string path, string extension, bool readOnly);
|
||||
public abstract IEnumerable<ExtraFile> ImportFiles(LocalMovie localMovie, MovieFile movieFile, List<string> files, bool isReadOnly);
|
||||
|
||||
protected TExtraFile ImportFile(Movie movie, MovieFile movieFile, string path, bool readOnly, string extension, string fileNameSuffix = null)
|
||||
{
|
||||
|
|
|
@ -13,6 +13,7 @@ using NzbDrone.Core.Extras.Metadata.Files;
|
|||
using NzbDrone.Core.Extras.Others;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Metadata
|
||||
{
|
||||
|
@ -191,9 +192,14 @@ namespace NzbDrone.Core.Extras.Metadata
|
|||
return movedFiles;
|
||||
}
|
||||
|
||||
public override ExtraFile Import(Movie movie, MovieFile movieFile, string path, string extension, bool readOnly)
|
||||
public override bool CanImportFile(LocalMovie localMovie, MovieFile movieFile, string path, string extension, bool readOnly)
|
||||
{
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override IEnumerable<ExtraFile> ImportFiles(LocalMovie localMovie, MovieFile movieFile, List<string> files, bool isReadOnly)
|
||||
{
|
||||
return Enumerable.Empty<ExtraFile>();
|
||||
}
|
||||
|
||||
private List<MetadataFile> GetMetadataFilesForConsumer(IMetadata consumer, List<MetadataFile> movieMetadata)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
|
@ -7,13 +9,16 @@ using NzbDrone.Core.Configuration;
|
|||
using NzbDrone.Core.Extras.Files;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Others
|
||||
{
|
||||
public class OtherExtraService : ExtraFileManager<OtherExtraFile>
|
||||
{
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IOtherExtraFileService _otherExtraFileService;
|
||||
private readonly IMediaFileAttributeService _mediaFileAttributeService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public OtherExtraService(IConfigService configService,
|
||||
IDiskProvider diskProvider,
|
||||
|
@ -23,8 +28,10 @@ namespace NzbDrone.Core.Extras.Others
|
|||
Logger logger)
|
||||
: base(configService, diskProvider, diskTransferService, logger)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_otherExtraFileService = otherExtraFileService;
|
||||
_mediaFileAttributeService = mediaFileAttributeService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override int Order => 2;
|
||||
|
@ -69,17 +76,79 @@ namespace NzbDrone.Core.Extras.Others
|
|||
return movedFiles;
|
||||
}
|
||||
|
||||
public override ExtraFile Import(Movie movie, MovieFile movieFile, string path, string extension, bool readOnly)
|
||||
public override bool CanImportFile(LocalMovie localMovie, MovieFile movieFile, string path, string extension, bool readOnly)
|
||||
{
|
||||
var extraFile = ImportFile(movie, movieFile, path, readOnly, extension, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (extraFile != null)
|
||||
public override IEnumerable<ExtraFile> ImportFiles(LocalMovie localMovie, MovieFile movieFile, List<string> files, bool isReadOnly)
|
||||
{
|
||||
var importedFiles = new List<ExtraFile>();
|
||||
var filteredFiles = files.Where(f => CanImportFile(localMovie, movieFile, f, Path.GetExtension(f), isReadOnly)).ToList();
|
||||
var sourcePath = localMovie.Path;
|
||||
var sourceFolder = _diskProvider.GetParentFolder(sourcePath);
|
||||
var sourceFileName = Path.GetFileNameWithoutExtension(sourcePath);
|
||||
var matchingFiles = new List<string>();
|
||||
var hasNfo = false;
|
||||
|
||||
foreach (var file in filteredFiles)
|
||||
{
|
||||
_mediaFileAttributeService.SetFilePermissions(path);
|
||||
_otherExtraFileService.Upsert(extraFile);
|
||||
try
|
||||
{
|
||||
// Filter out duplicate NFO files
|
||||
if (file.EndsWith(".nfo", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
if (hasNfo)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
hasNfo = true;
|
||||
}
|
||||
|
||||
// Filename match
|
||||
if (Path.GetFileNameWithoutExtension(file).StartsWith(sourceFileName, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
matchingFiles.Add(file);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Movie match
|
||||
var fileMovieInfo = Parser.Parser.ParseMoviePath(file) ?? new ParsedMovieInfo();
|
||||
|
||||
if (fileMovieInfo.MovieTitle == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fileMovieInfo.MovieTitle == localMovie.FileMovieInfo.MovieTitle &&
|
||||
fileMovieInfo.Year.Equals(localMovie.FileMovieInfo.Year))
|
||||
{
|
||||
matchingFiles.Add(file);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Failed to import extra file: {0}", file);
|
||||
}
|
||||
}
|
||||
|
||||
return extraFile;
|
||||
foreach (string file in matchingFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
var extraFile = ImportFile(localMovie.Movie, movieFile, file, isReadOnly, Path.GetExtension(file), null);
|
||||
_mediaFileAttributeService.SetFilePermissions(file);
|
||||
_otherExtraFileService.Upsert(extraFile);
|
||||
importedFiles.Add(extraFile);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Failed to import extra file: {0}", file);
|
||||
}
|
||||
}
|
||||
|
||||
return importedFiles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
@ -9,13 +10,17 @@ using NzbDrone.Core.Configuration;
|
|||
using NzbDrone.Core.Extras.Files;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.MovieImport;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.Extras.Subtitles
|
||||
{
|
||||
public class SubtitleService : ExtraFileManager<SubtitleFile>
|
||||
{
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IDetectSample _detectSample;
|
||||
private readonly ISubtitleFileService _subtitleFileService;
|
||||
private readonly IMediaFileAttributeService _mediaFileAttributeService;
|
||||
private readonly Logger _logger;
|
||||
|
@ -23,11 +28,14 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|||
public SubtitleService(IConfigService configService,
|
||||
IDiskProvider diskProvider,
|
||||
IDiskTransferService diskTransferService,
|
||||
IDetectSample detectSample,
|
||||
ISubtitleFileService subtitleFileService,
|
||||
IMediaFileAttributeService mediaFileAttributeService,
|
||||
Logger logger)
|
||||
: base(configService, diskProvider, diskTransferService, logger)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_detectSample = detectSample;
|
||||
_subtitleFileService = subtitleFileService;
|
||||
_mediaFileAttributeService = mediaFileAttributeService;
|
||||
_logger = logger;
|
||||
|
@ -71,11 +79,6 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|||
var groupCount = group.Count();
|
||||
var copy = 1;
|
||||
|
||||
if (groupCount > 1)
|
||||
{
|
||||
_logger.Warn("Multiple subtitle files found with the same language and extension for {0}", Path.Combine(movie.Path, movieFile.RelativePath));
|
||||
}
|
||||
|
||||
foreach (var subtitleFile in group)
|
||||
{
|
||||
var suffix = GetSuffix(subtitleFile.Language, copy, groupCount > 1);
|
||||
|
@ -91,22 +94,129 @@ namespace NzbDrone.Core.Extras.Subtitles
|
|||
return movedFiles;
|
||||
}
|
||||
|
||||
public override ExtraFile Import(Movie movie, MovieFile movieFile, string path, string extension, bool readOnly)
|
||||
public override bool CanImportFile(LocalMovie localEpisode, MovieFile movieFile, string path, string extension, bool readOnly)
|
||||
{
|
||||
if (SubtitleFileExtensions.Extensions.Contains(Path.GetExtension(path)))
|
||||
return SubtitleFileExtensions.Extensions.Contains(extension.ToLowerInvariant());
|
||||
}
|
||||
|
||||
public override IEnumerable<ExtraFile> ImportFiles(LocalMovie localMovie, MovieFile movieFile, List<string> files, bool isReadOnly)
|
||||
{
|
||||
var importedFiles = new List<SubtitleFile>();
|
||||
|
||||
var filteredFiles = files.Where(f => CanImportFile(localMovie, movieFile, f, Path.GetExtension(f), isReadOnly)).ToList();
|
||||
|
||||
var sourcePath = localMovie.Path;
|
||||
var sourceFolder = _diskProvider.GetParentFolder(sourcePath);
|
||||
var sourceFileName = Path.GetFileNameWithoutExtension(sourcePath);
|
||||
|
||||
var matchingFiles = new List<string>();
|
||||
|
||||
foreach (var file in filteredFiles)
|
||||
{
|
||||
var language = LanguageParser.ParseSubtitleLanguage(path);
|
||||
var suffix = GetSuffix(language, 1, false);
|
||||
var subtitleFile = ImportFile(movie, movieFile, path, readOnly, extension, suffix);
|
||||
subtitleFile.Language = language;
|
||||
try
|
||||
{
|
||||
// Filename match
|
||||
if (Path.GetFileNameWithoutExtension(file).StartsWith(sourceFileName, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
matchingFiles.Add(file);
|
||||
continue;
|
||||
}
|
||||
|
||||
_mediaFileAttributeService.SetFilePermissions(path);
|
||||
_subtitleFileService.Upsert(subtitleFile);
|
||||
// Movie match
|
||||
var fileMovieInfo = Parser.Parser.ParseMoviePath(file) ?? new ParsedMovieInfo();
|
||||
|
||||
return subtitleFile;
|
||||
if (fileMovieInfo.MovieTitle == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fileMovieInfo.MovieTitle == localMovie.FileMovieInfo.MovieTitle &&
|
||||
fileMovieInfo.Year.Equals(localMovie.FileMovieInfo.Year))
|
||||
{
|
||||
matchingFiles.Add(file);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Failed to import subtitle file: {0}", file);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
// Use any sub if only episode in folder
|
||||
if (matchingFiles.Count == 0 && filteredFiles.Count > 0)
|
||||
{
|
||||
var videoFiles = _diskProvider.GetFiles(sourceFolder, SearchOption.AllDirectories)
|
||||
.Where(file => MediaFileExtensions.Extensions.Contains(Path.GetExtension(file)))
|
||||
.ToList();
|
||||
|
||||
if (videoFiles.Count() > 2)
|
||||
{
|
||||
return importedFiles;
|
||||
}
|
||||
|
||||
// Filter out samples
|
||||
videoFiles = videoFiles.Where(file =>
|
||||
{
|
||||
var sample = _detectSample.IsSample(localMovie.Movie.MovieMetadata, file);
|
||||
|
||||
if (sample == DetectSampleResult.Sample)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}).ToList();
|
||||
|
||||
if (videoFiles.Count == 1)
|
||||
{
|
||||
matchingFiles.AddRange(filteredFiles);
|
||||
|
||||
_logger.Warn("Imported any available subtitle file for movie: {0}", localMovie);
|
||||
}
|
||||
}
|
||||
|
||||
var subtitleFiles = new List<Tuple<string, Language, string>>();
|
||||
|
||||
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 groupedSubtitleFiles = subtitleFiles.GroupBy(s => s.Item2 + s.Item3).ToList();
|
||||
|
||||
foreach (var group in groupedSubtitleFiles)
|
||||
{
|
||||
var groupCount = group.Count();
|
||||
var copy = 1;
|
||||
|
||||
foreach (var file in group)
|
||||
{
|
||||
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;
|
||||
|
||||
_mediaFileAttributeService.SetFilePermissions(path);
|
||||
_subtitleFileService.Upsert(subtitleFile);
|
||||
|
||||
importedFiles.Add(subtitleFile);
|
||||
|
||||
copy++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Failed to import subtitle file: {0}", file.Item1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return importedFiles;
|
||||
}
|
||||
|
||||
private string GetSuffix(Language language, int copy, bool multipleCopies = false)
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace NzbDrone.Core.Parser
|
|||
(?<slovak>\bSK\b)",
|
||||
RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace);
|
||||
|
||||
private static readonly Regex SubtitleLanguageRegex = new Regex(".+?[-_. ](?<iso_code>[a-z]{2,3})(?:[-_. ]forced)?$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
private static readonly Regex SubtitleLanguageRegex = new Regex(".+?[-_. ](?<iso_code>[a-z]{2,3})([-_. ](?<tags>full|forced|foreign|default|cc|psdh|sdh))*$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public static List<Language> ParseLanguages(string title)
|
||||
{
|
||||
|
@ -316,11 +316,19 @@ namespace NzbDrone.Core.Parser
|
|||
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;
|
||||
}
|
||||
|
||||
foreach (Language language in Language.All)
|
||||
{
|
||||
if (simpleFilename.EndsWith(language.ToString(), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return language;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Debug("Unable to parse langauge from subtitle file: {0}", fileName);
|
||||
}
|
||||
catch (Exception)
|
||||
|
|
Loading…
Reference in New Issue