mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-21 22:05:43 -04:00
New: Custom Format Updates (#8067)
This commit is contained in:
@@ -14,28 +14,133 @@ namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public interface ICustomFormatCalculationService
|
||||
{
|
||||
List<CustomFormat> ParseCustomFormat(ParsedMovieInfo movieInfo, Movie movie);
|
||||
List<CustomFormat> ParseCustomFormat(RemoteMovie remoteMovie, long size);
|
||||
List<CustomFormat> ParseCustomFormat(MovieFile movieFile, Movie movie);
|
||||
List<CustomFormat> ParseCustomFormat(MovieFile movieFile);
|
||||
List<CustomFormat> ParseCustomFormat(Blocklist blocklist);
|
||||
List<CustomFormat> ParseCustomFormat(MovieHistory history);
|
||||
List<CustomFormat> ParseCustomFormat(Blocklist blocklist, Movie movie);
|
||||
List<CustomFormat> ParseCustomFormat(MovieHistory history, Movie movie);
|
||||
List<CustomFormat> ParseCustomFormat(LocalMovie localMovie);
|
||||
}
|
||||
|
||||
public class CustomFormatCalculationService : ICustomFormatCalculationService
|
||||
{
|
||||
private readonly ICustomFormatService _formatService;
|
||||
private readonly IParsingService _parsingService;
|
||||
private readonly IMovieService _movieService;
|
||||
|
||||
public CustomFormatCalculationService(ICustomFormatService formatService,
|
||||
IParsingService parsingService,
|
||||
IMovieService movieService)
|
||||
public CustomFormatCalculationService(ICustomFormatService formatService)
|
||||
{
|
||||
_formatService = formatService;
|
||||
_parsingService = parsingService;
|
||||
_movieService = movieService;
|
||||
}
|
||||
|
||||
public static List<CustomFormat> ParseCustomFormat(ParsedMovieInfo movieInfo, List<CustomFormat> allCustomFormats)
|
||||
public List<CustomFormat> ParseCustomFormat(RemoteMovie remoteMovie, long size)
|
||||
{
|
||||
var input = new CustomFormatInput
|
||||
{
|
||||
MovieInfo = remoteMovie.ParsedMovieInfo,
|
||||
Movie = remoteMovie.Movie,
|
||||
Size = size,
|
||||
Languages = remoteMovie.Languages
|
||||
};
|
||||
|
||||
return ParseCustomFormat(input);
|
||||
}
|
||||
|
||||
public List<CustomFormat> ParseCustomFormat(MovieFile movieFile, Movie movie)
|
||||
{
|
||||
return ParseCustomFormat(movieFile, movie, _formatService.All());
|
||||
}
|
||||
|
||||
public List<CustomFormat> ParseCustomFormat(MovieFile movieFile)
|
||||
{
|
||||
return ParseCustomFormat(movieFile, movieFile.Movie, _formatService.All());
|
||||
}
|
||||
|
||||
public List<CustomFormat> ParseCustomFormat(Blocklist blocklist, Movie movie)
|
||||
{
|
||||
var parsed = Parser.Parser.ParseMovieTitle(blocklist.SourceTitle);
|
||||
|
||||
var movieInfo = new ParsedMovieInfo
|
||||
{
|
||||
MovieTitles = new List<string>() { movie.Title },
|
||||
SimpleReleaseTitle = parsed?.SimpleReleaseTitle ?? blocklist.SourceTitle.SimplifyReleaseTitle(),
|
||||
ReleaseTitle = parsed?.ReleaseTitle ?? blocklist.SourceTitle,
|
||||
Edition = parsed?.Edition,
|
||||
Quality = blocklist.Quality,
|
||||
Languages = blocklist.Languages,
|
||||
ReleaseGroup = parsed?.ReleaseGroup
|
||||
};
|
||||
|
||||
var input = new CustomFormatInput
|
||||
{
|
||||
MovieInfo = movieInfo,
|
||||
Movie = movie,
|
||||
Size = blocklist.Size ?? 0,
|
||||
IndexerFlags = blocklist.IndexerFlags,
|
||||
Languages = blocklist.Languages
|
||||
};
|
||||
|
||||
return ParseCustomFormat(input);
|
||||
}
|
||||
|
||||
public List<CustomFormat> ParseCustomFormat(MovieHistory history, Movie movie)
|
||||
{
|
||||
var parsed = Parser.Parser.ParseMovieTitle(history.SourceTitle);
|
||||
|
||||
long.TryParse(history.Data.GetValueOrDefault("size"), out var size);
|
||||
Enum.TryParse(history.Data.GetValueOrDefault("indexerFlags"), true, out IndexerFlags flags);
|
||||
|
||||
var movieInfo = new ParsedMovieInfo
|
||||
{
|
||||
MovieTitles = new List<string>() { movie.Title },
|
||||
SimpleReleaseTitle = parsed?.SimpleReleaseTitle ?? history.SourceTitle.SimplifyReleaseTitle(),
|
||||
ReleaseTitle = parsed?.ReleaseTitle ?? history.SourceTitle,
|
||||
Edition = parsed?.Edition,
|
||||
Quality = history.Quality,
|
||||
Languages = history.Languages,
|
||||
ReleaseGroup = parsed?.ReleaseGroup,
|
||||
};
|
||||
|
||||
var input = new CustomFormatInput
|
||||
{
|
||||
MovieInfo = movieInfo,
|
||||
Movie = movie,
|
||||
Size = size,
|
||||
IndexerFlags = flags,
|
||||
Languages = history.Languages
|
||||
};
|
||||
|
||||
return ParseCustomFormat(input);
|
||||
}
|
||||
|
||||
public List<CustomFormat> ParseCustomFormat(LocalMovie localMovie)
|
||||
{
|
||||
var episodeInfo = new ParsedMovieInfo
|
||||
{
|
||||
MovieTitles = new List<string>() { localMovie.Movie.Title },
|
||||
SimpleReleaseTitle = localMovie.SceneName.SimplifyReleaseTitle(),
|
||||
ReleaseTitle = localMovie.SceneName,
|
||||
Quality = localMovie.Quality,
|
||||
Edition = localMovie.Edition,
|
||||
Languages = localMovie.Languages,
|
||||
ReleaseGroup = localMovie.ReleaseGroup
|
||||
};
|
||||
|
||||
var input = new CustomFormatInput
|
||||
{
|
||||
MovieInfo = episodeInfo,
|
||||
Movie = localMovie.Movie,
|
||||
Size = localMovie.Size,
|
||||
Languages = localMovie.Languages
|
||||
};
|
||||
|
||||
return ParseCustomFormat(input);
|
||||
}
|
||||
|
||||
private List<CustomFormat> ParseCustomFormat(CustomFormatInput input)
|
||||
{
|
||||
return ParseCustomFormat(input, _formatService.All());
|
||||
}
|
||||
|
||||
private static List<CustomFormat> ParseCustomFormat(CustomFormatInput input, List<CustomFormat> allCustomFormats)
|
||||
{
|
||||
var matches = new List<CustomFormat>();
|
||||
|
||||
@@ -45,7 +150,7 @@ namespace NzbDrone.Core.CustomFormats
|
||||
.GroupBy(t => t.GetType())
|
||||
.Select(g => new SpecificationMatchesGroup
|
||||
{
|
||||
Matches = g.ToDictionary(t => t, t => t.IsSatisfiedBy(movieInfo))
|
||||
Matches = g.ToDictionary(t => t, t => t.IsSatisfiedBy(input))
|
||||
})
|
||||
.ToList();
|
||||
|
||||
@@ -58,7 +163,7 @@ namespace NzbDrone.Core.CustomFormats
|
||||
return matches;
|
||||
}
|
||||
|
||||
public static List<CustomFormat> ParseCustomFormat(MovieFile movieFile, List<CustomFormat> allCustomFormats)
|
||||
private static List<CustomFormat> ParseCustomFormat(MovieFile movieFile, Movie movie, List<CustomFormat> allCustomFormats)
|
||||
{
|
||||
var sceneName = string.Empty;
|
||||
if (movieFile.SceneName.IsNotNullOrWhiteSpace())
|
||||
@@ -74,90 +179,29 @@ namespace NzbDrone.Core.CustomFormats
|
||||
sceneName = Path.GetFileName(movieFile.RelativePath);
|
||||
}
|
||||
|
||||
var info = new ParsedMovieInfo
|
||||
var movieInfo = new ParsedMovieInfo
|
||||
{
|
||||
MovieTitles = new List<string>() { movieFile.Movie.MovieMetadata.Value.Title },
|
||||
MovieTitles = new List<string>() { movie.Title },
|
||||
SimpleReleaseTitle = sceneName.SimplifyReleaseTitle(),
|
||||
Quality = movieFile.Quality,
|
||||
Languages = movieFile.Languages,
|
||||
ReleaseGroup = movieFile.ReleaseGroup,
|
||||
Edition = movieFile.Edition,
|
||||
Year = movieFile.Movie.MovieMetadata.Value.Year,
|
||||
ImdbId = movieFile.Movie.MovieMetadata.Value.ImdbId,
|
||||
ExtraInfo = new Dictionary<string, object>
|
||||
{
|
||||
{ "IndexerFlags", movieFile.IndexerFlags },
|
||||
{ "Size", movieFile.Size },
|
||||
{ "Filename", Path.GetFileName(movieFile.RelativePath) },
|
||||
{ "OriginalLanguage", movieFile.Movie.MovieMetadata.Value.OriginalLanguage }
|
||||
}
|
||||
ImdbId = movieFile.Movie.MovieMetadata.Value.ImdbId
|
||||
};
|
||||
|
||||
return ParseCustomFormat(info, allCustomFormats);
|
||||
}
|
||||
|
||||
public List<CustomFormat> ParseCustomFormat(ParsedMovieInfo movieInfo, Movie movie)
|
||||
{
|
||||
movieInfo = _parsingService.EnhanceMovieInfo(movieInfo, new List<object> { movie }) ?? movieInfo;
|
||||
return ParseCustomFormat(movieInfo, _formatService.All());
|
||||
}
|
||||
|
||||
public List<CustomFormat> ParseCustomFormat(MovieFile movieFile)
|
||||
{
|
||||
return ParseCustomFormat(movieFile, _formatService.All());
|
||||
}
|
||||
|
||||
public List<CustomFormat> ParseCustomFormat(Blocklist blocklist)
|
||||
{
|
||||
var movie = _movieService.GetMovie(blocklist.MovieId);
|
||||
var parsed = _parsingService.ParseMovieInfo(blocklist.SourceTitle, null);
|
||||
|
||||
var info = new ParsedMovieInfo
|
||||
var input = new CustomFormatInput
|
||||
{
|
||||
MovieTitles = new List<string>() { movie.MovieMetadata.Value.Title },
|
||||
SimpleReleaseTitle = parsed?.SimpleReleaseTitle ?? blocklist.SourceTitle.SimplifyReleaseTitle(),
|
||||
Quality = blocklist.Quality,
|
||||
Languages = blocklist.Languages,
|
||||
ReleaseGroup = parsed?.ReleaseGroup,
|
||||
Edition = parsed?.Edition,
|
||||
Year = movie.MovieMetadata.Value.Year,
|
||||
ImdbId = movie.MovieMetadata.Value.ImdbId,
|
||||
ExtraInfo = new Dictionary<string, object>
|
||||
{
|
||||
{ "IndexerFlags", blocklist.IndexerFlags },
|
||||
{ "Size", blocklist.Size }
|
||||
}
|
||||
MovieInfo = movieInfo,
|
||||
Movie = movie,
|
||||
Size = movieFile.Size,
|
||||
IndexerFlags = movieFile.IndexerFlags,
|
||||
Languages = movieFile.Languages,
|
||||
Filename = Path.GetFileName(movieFile.RelativePath)
|
||||
};
|
||||
|
||||
return ParseCustomFormat(info, movie);
|
||||
}
|
||||
|
||||
public List<CustomFormat> ParseCustomFormat(MovieHistory history)
|
||||
{
|
||||
var movie = _movieService.GetMovie(history.MovieId);
|
||||
var parsed = _parsingService.ParseMovieInfo(history.SourceTitle, null);
|
||||
|
||||
Enum.TryParse(history.Data.GetValueOrDefault("indexerFlags"), true, out IndexerFlags flags);
|
||||
long.TryParse(history.Data.GetValueOrDefault("size"), out var size);
|
||||
|
||||
var info = new ParsedMovieInfo
|
||||
{
|
||||
MovieTitles = new List<string>() { movie.MovieMetadata.Value.Title },
|
||||
SimpleReleaseTitle = parsed?.SimpleReleaseTitle ?? history.SourceTitle.SimplifyReleaseTitle(),
|
||||
Quality = history.Quality,
|
||||
Languages = history.Languages,
|
||||
ReleaseGroup = parsed?.ReleaseGroup,
|
||||
Edition = parsed?.Edition,
|
||||
Year = movie.MovieMetadata.Value.Year,
|
||||
ImdbId = movie.MovieMetadata.Value.ImdbId,
|
||||
ExtraInfo = new Dictionary<string, object>
|
||||
{
|
||||
{ "IndexerFlags", flags },
|
||||
{ "Size", size }
|
||||
}
|
||||
};
|
||||
|
||||
return ParseCustomFormat(info, movie);
|
||||
return ParseCustomFormat(input, allCustomFormats);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user