New: Better interface for creating custom formats

This commit is contained in:
ta264
2020-02-18 21:03:05 +00:00
committed by Qstick
parent a5bac30ef3
commit 241bf85f15
74 changed files with 2259 additions and 1090 deletions
@@ -16,7 +16,6 @@ namespace NzbDrone.Core.CustomFormats
List<CustomFormat> ParseCustomFormat(MovieFile movieFile);
List<CustomFormat> ParseCustomFormat(Blacklist blacklist);
List<CustomFormat> ParseCustomFormat(History.History history);
List<CustomFormatMatchResult> MatchFormatTags(ParsedMovieInfo movieInfo);
}
public class CustomFormatCalculationService : ICustomFormatCalculationService
@@ -35,88 +34,54 @@ namespace NzbDrone.Core.CustomFormats
}
public List<CustomFormat> ParseCustomFormat(ParsedMovieInfo movieInfo)
{
return MatchFormatTags(movieInfo)
.Where(m => m.GoodMatch)
.Select(r => r.CustomFormat)
.ToList();
}
public List<CustomFormat> ParseCustomFormat(MovieFile movieFile)
{
return MatchFormatTags(movieFile)
.Where(m => m.GoodMatch)
.Select(r => r.CustomFormat)
.ToList();
}
public List<CustomFormat> ParseCustomFormat(Blacklist blacklist)
{
return MatchFormatTags(blacklist)
.Where(m => m.GoodMatch)
.Select(r => r.CustomFormat)
.ToList();
}
public List<CustomFormat> ParseCustomFormat(History.History history)
{
return MatchFormatTags(history)
.Where(m => m.GoodMatch)
.Select(r => r.CustomFormat)
.ToList();
}
public List<CustomFormatMatchResult> MatchFormatTags(ParsedMovieInfo movieInfo)
{
var formats = _formatService.All();
var matches = new List<CustomFormatMatchResult>();
var matches = new List<CustomFormat>();
foreach (var customFormat in formats)
{
var tagTypeMatches = customFormat.FormatTags
.GroupBy(t => t.TagType)
.Select(g => new FormatTagMatchesGroup
var specificationMatches = customFormat.Specifications
.GroupBy(t => t.GetType())
.Select(g => new SpecificationMatchesGroup
{
Type = g.Key,
Matches = g.ToDictionary(t => t, t => t.DoesItMatch(movieInfo))
Matches = g.ToDictionary(t => t, t => t.IsSatisfiedBy(movieInfo))
})
.ToList();
matches.Add(new CustomFormatMatchResult
if (specificationMatches.All(x => x.DidMatch))
{
CustomFormat = customFormat,
GroupMatches = tagTypeMatches
});
matches.Add(customFormat);
}
}
return matches;
}
private List<CustomFormatMatchResult> MatchFormatTags(MovieFile file)
public List<CustomFormat> ParseCustomFormat(MovieFile movieFile)
{
var info = new ParsedMovieInfo
{
MovieTitle = file.Movie.Title,
SimpleReleaseTitle = file.GetSceneOrFileName().SimplifyReleaseTitle(),
Quality = file.Quality,
Languages = file.Languages,
ReleaseGroup = file.ReleaseGroup,
Edition = file.Edition,
Year = file.Movie.Year,
ImdbId = file.Movie.ImdbId,
MovieTitle = movieFile.Movie.Title,
SimpleReleaseTitle = movieFile.GetSceneOrFileName().SimplifyReleaseTitle(),
Quality = movieFile.Quality,
Languages = movieFile.Languages,
ReleaseGroup = movieFile.ReleaseGroup,
Edition = movieFile.Edition,
Year = movieFile.Movie.Year,
ImdbId = movieFile.Movie.ImdbId,
ExtraInfo = new Dictionary<string, object>
{
{ "IndexerFlags", file.IndexerFlags },
{ "Size", file.Size },
{ "Filename", System.IO.Path.GetFileName(file.RelativePath) }
{ "IndexerFlags", movieFile.IndexerFlags },
{ "Size", movieFile.Size },
{ "Filename", System.IO.Path.GetFileName(movieFile.RelativePath) }
}
};
return MatchFormatTags(info);
return ParseCustomFormat(info);
}
private List<CustomFormatMatchResult> MatchFormatTags(Blacklist blacklist)
public List<CustomFormat> ParseCustomFormat(Blacklist blacklist)
{
var parsed = _parsingService.ParseMovieInfo(blacklist.SourceTitle, null);
@@ -137,10 +102,10 @@ namespace NzbDrone.Core.CustomFormats
}
};
return MatchFormatTags(info);
return ParseCustomFormat(info);
}
private List<CustomFormatMatchResult> MatchFormatTags(History.History history)
public List<CustomFormat> ParseCustomFormat(History.History history)
{
var movie = _movieService.GetMovie(history.MovieId);
var parsed = _parsingService.ParseMovieInfo(history.SourceTitle, null);
@@ -165,7 +130,7 @@ namespace NzbDrone.Core.CustomFormats
}
};
return MatchFormatTags(info);
return ParseCustomFormat(info);
}
}
}