mirror of
https://github.com/Radarr/Radarr
synced 2025-02-24 23:23:21 +00:00
Cleanup ParsingService
This commit is contained in:
parent
c3f30fb237
commit
a03323703a
9 changed files with 7 additions and 59 deletions
|
@ -32,8 +32,6 @@ public class DownloadDecisionMakerFixture : CoreTest<DownloadDecisionMaker>
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
ParseMovieTitle();
|
|
||||||
|
|
||||||
_pass1 = new Mock<IDecisionEngineSpecification>();
|
_pass1 = new Mock<IDecisionEngineSpecification>();
|
||||||
_pass2 = new Mock<IDecisionEngineSpecification>();
|
_pass2 = new Mock<IDecisionEngineSpecification>();
|
||||||
_pass3 = new Mock<IDecisionEngineSpecification>();
|
_pass3 = new Mock<IDecisionEngineSpecification>();
|
||||||
|
|
|
@ -58,8 +58,6 @@ public void should_track_downloads_using_the_source_title_if_it_cannot_be_found_
|
||||||
.Setup(s => s.Map(It.Is<ParsedMovieInfo>(i => i.PrimaryMovieTitle == "A Movie"), It.IsAny<string>(), null))
|
.Setup(s => s.Map(It.Is<ParsedMovieInfo>(i => i.PrimaryMovieTitle == "A Movie"), It.IsAny<string>(), null))
|
||||||
.Returns(remoteMovie);
|
.Returns(remoteMovie);
|
||||||
|
|
||||||
ParseMovieTitle();
|
|
||||||
|
|
||||||
var client = new DownloadClientDefinition()
|
var client = new DownloadClientDefinition()
|
||||||
{
|
{
|
||||||
Id = 1,
|
Id = 1,
|
||||||
|
@ -110,8 +108,6 @@ public void should_unmap_tracked_download_if_movie_deleted()
|
||||||
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
|
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
|
||||||
.Returns(new List<MovieHistory>());
|
.Returns(new List<MovieHistory>());
|
||||||
|
|
||||||
ParseMovieTitle();
|
|
||||||
|
|
||||||
var client = new DownloadClientDefinition()
|
var client = new DownloadClientDefinition()
|
||||||
{
|
{
|
||||||
Id = 1,
|
Id = 1,
|
||||||
|
@ -169,8 +165,6 @@ public void should_not_throw_when_processing_deleted_movie()
|
||||||
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
|
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
|
||||||
.Returns(new List<MovieHistory>());
|
.Returns(new List<MovieHistory>());
|
||||||
|
|
||||||
ParseMovieTitle();
|
|
||||||
|
|
||||||
var client = new DownloadClientDefinition()
|
var client = new DownloadClientDefinition()
|
||||||
{
|
{
|
||||||
Id = 1,
|
Id = 1,
|
||||||
|
|
|
@ -31,28 +31,6 @@ protected void UseRealHttp()
|
||||||
Mocker.SetConstant<IHttpClient>(new HttpClient(Array.Empty<IHttpRequestInterceptor>(), Mocker.Resolve<CacheManager>(), Mocker.Resolve<RateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), TestLogger));
|
Mocker.SetConstant<IHttpClient>(new HttpClient(Array.Empty<IHttpRequestInterceptor>(), Mocker.Resolve<CacheManager>(), Mocker.Resolve<RateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), TestLogger));
|
||||||
Mocker.SetConstant<IRadarrCloudRequestBuilder>(new RadarrCloudRequestBuilder());
|
Mocker.SetConstant<IRadarrCloudRequestBuilder>(new RadarrCloudRequestBuilder());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used for tests that rely on parsing working correctly.
|
|
||||||
protected void UseRealParsingService()
|
|
||||||
{
|
|
||||||
// Mocker.SetConstant<IParsingService>(new ParsingService(Mocker.Resolve<MovieService>(), Mocker.Resolve<ConfigService>(), Mocker.Resolve<QualityDefinitionService>(), TestLogger));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used for tests that rely on parsing working correctly. Does some minimal parsing using the old static methods.
|
|
||||||
protected void ParseMovieTitle()
|
|
||||||
{
|
|
||||||
Mocker.GetMock<IParsingService>().Setup(c => c.ParseMovieInfo(It.IsAny<string>(), It.IsAny<System.Collections.Generic.List<object>>()))
|
|
||||||
.Returns<string, System.Collections.Generic.List<object>>((title, helpers) =>
|
|
||||||
{
|
|
||||||
var result = Parser.Parser.ParseMovieTitle(title);
|
|
||||||
if (result != null)
|
|
||||||
{
|
|
||||||
result.Quality = QualityParser.ParseQuality(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class CoreTest<TSubject> : CoreTest
|
public abstract class CoreTest<TSubject> : CoreTest
|
||||||
|
|
|
@ -30,9 +30,6 @@ public class DownloadedMoviesImportServiceFixture : CoreTest<DownloadedMovieImpo
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
ParseMovieTitle();
|
|
||||||
|
|
||||||
// UseRealParsingService();
|
|
||||||
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
|
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
|
||||||
.Returns(_videoFiles);
|
.Returns(_videoFiles);
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ private IEnumerable<DownloadDecision> GetDecisions(List<ReleaseInfo> reports, bo
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var parsedMovieInfo = _parsingService.ParseMovieInfo(report.Title, new List<object> { report });
|
var parsedMovieInfo = Parser.Parser.ParseMovieTitle(report.Title);
|
||||||
|
|
||||||
if (parsedMovieInfo != null && !parsedMovieInfo.PrimaryMovieTitle.IsNullOrWhiteSpace())
|
if (parsedMovieInfo != null && !parsedMovieInfo.PrimaryMovieTitle.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
|
|
|
@ -118,7 +118,7 @@ public TrackedDownload TrackDownload(DownloadClientDefinition downloadClient, Do
|
||||||
var grabbedHistoryItem = historyItems.FirstOrDefault(h => h.EventType == MovieHistoryEventType.Grabbed);
|
var grabbedHistoryItem = historyItems.FirstOrDefault(h => h.EventType == MovieHistoryEventType.Grabbed);
|
||||||
|
|
||||||
// TODO: Create release info from history and use that here, so we don't loose indexer flags!
|
// TODO: Create release info from history and use that here, so we don't loose indexer flags!
|
||||||
var parsedMovieInfo = _parsingService.ParseMovieInfo(trackedDownload.DownloadItem.Title, new List<object> { grabbedHistoryItem });
|
var parsedMovieInfo = Parser.Parser.ParseMovieTitle(trackedDownload.DownloadItem.Title);
|
||||||
|
|
||||||
if (parsedMovieInfo != null)
|
if (parsedMovieInfo != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -193,7 +193,7 @@ private List<ImportResult> ProcessFolder(DirectoryInfo directoryInfo, ImportMode
|
||||||
var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name);
|
var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name);
|
||||||
var historyItems = _historyService.FindByDownloadId(downloadClientItem?.DownloadId ?? "");
|
var historyItems = _historyService.FindByDownloadId(downloadClientItem?.DownloadId ?? "");
|
||||||
var firstHistoryItem = historyItems?.OrderByDescending(h => h.Date).FirstOrDefault();
|
var firstHistoryItem = historyItems?.OrderByDescending(h => h.Date).FirstOrDefault();
|
||||||
var folderInfo = _parsingService.ParseMovieInfo(cleanedUpName, new List<object> { firstHistoryItem });
|
var folderInfo = Parser.Parser.ParseMovieTitle(cleanedUpName);
|
||||||
|
|
||||||
if (folderInfo != null)
|
if (folderInfo != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,8 +15,6 @@ public interface IParsingService
|
||||||
Movie GetMovie(string title);
|
Movie GetMovie(string title);
|
||||||
RemoteMovie Map(ParsedMovieInfo parsedMovieInfo, string imdbId, SearchCriteriaBase searchCriteria = null);
|
RemoteMovie Map(ParsedMovieInfo parsedMovieInfo, string imdbId, SearchCriteriaBase searchCriteria = null);
|
||||||
RemoteMovie Map(ParsedMovieInfo parsedMovieInfo, int movieId);
|
RemoteMovie Map(ParsedMovieInfo parsedMovieInfo, int movieId);
|
||||||
ParsedMovieInfo ParseMovieInfo(string title, List<object> helpers);
|
|
||||||
ParsedMovieInfo ParseMinimalMovieInfo(string path, bool isDir = false);
|
|
||||||
ParsedMovieInfo ParseMinimalPathMovieInfo(string path);
|
ParsedMovieInfo ParseMinimalPathMovieInfo(string path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,39 +37,22 @@ public ParsingService(IMovieService movieService,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParsedMovieInfo ParseMovieInfo(string title, List<object> helpers)
|
|
||||||
{
|
|
||||||
var result = Parser.ParseMovieTitle(title);
|
|
||||||
|
|
||||||
if (result == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParsedMovieInfo ParseMinimalMovieInfo(string file, bool isDir = false)
|
|
||||||
{
|
|
||||||
return Parser.ParseMovieTitle(file, isDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParsedMovieInfo ParseMinimalPathMovieInfo(string path)
|
public ParsedMovieInfo ParseMinimalPathMovieInfo(string path)
|
||||||
{
|
{
|
||||||
var fileInfo = new FileInfo(path);
|
var fileInfo = new FileInfo(path);
|
||||||
|
|
||||||
var result = ParseMinimalMovieInfo(fileInfo.Name, true);
|
var result = Parser.ParseMovieTitle(fileInfo.Name, true);
|
||||||
|
|
||||||
if (result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
_logger.Debug("Attempting to parse movie info using directory and file names. {0}", fileInfo.Directory.Name);
|
_logger.Debug("Attempting to parse movie info using directory and file names. {0}", fileInfo.Directory.Name);
|
||||||
result = ParseMinimalMovieInfo(fileInfo.Directory.Name + " " + fileInfo.Name);
|
result = Parser.ParseMovieTitle(fileInfo.Directory.Name + " " + fileInfo.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
_logger.Debug("Attempting to parse movie info using directory name. {0}", fileInfo.Directory.Name);
|
_logger.Debug("Attempting to parse movie info using directory name. {0}", fileInfo.Directory.Name);
|
||||||
result = ParseMinimalMovieInfo(fileInfo.Directory.Name + fileInfo.Extension);
|
result = Parser.ParseMovieTitle(fileInfo.Directory.Name + fileInfo.Extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -33,7 +33,7 @@ public ParseResource Parse(string title)
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var parsedMovieInfo = _parsingService.ParseMovieInfo(title, new List<object>());
|
var parsedMovieInfo = Parser.ParseMovieTitle(title);
|
||||||
|
|
||||||
if (parsedMovieInfo == null)
|
if (parsedMovieInfo == null)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue