Radarr/src/Radarr.Api.V3/ManualImport/ManualImportResource.cs

73 lines
2.5 KiB
C#
Raw Permalink Normal View History

using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Crypto;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Languages;
using NzbDrone.Core.MediaFiles.MovieImport.Manual;
using NzbDrone.Core.Qualities;
2023-02-05 23:09:37 +00:00
using Radarr.Api.V3.CustomFormats;
using Radarr.Api.V3.Movies;
using Radarr.Http.REST;
namespace Radarr.Api.V3.ManualImport
{
public class ManualImportResource : RestResource
{
public string Path { get; set; }
public string RelativePath { get; set; }
public string FolderName { get; set; }
public string Name { get; set; }
public long Size { get; set; }
public MovieResource Movie { get; set; }
public QualityModel Quality { get; set; }
public List<Language> Languages { get; set; }
2021-12-24 17:04:27 +00:00
public string ReleaseGroup { get; set; }
public int QualityWeight { get; set; }
public string DownloadId { get; set; }
2023-02-05 23:09:37 +00:00
public List<CustomFormatResource> CustomFormats { get; set; }
public int CustomFormatScore { get; set; }
public int IndexerFlags { get; set; }
public IEnumerable<Rejection> Rejections { get; set; }
}
public static class ManualImportResourceMapper
{
public static ManualImportResource ToResource(this ManualImportItem model)
{
2019-12-22 22:08:53 +00:00
if (model == null)
{
return null;
}
var customFormats = model.CustomFormats;
2023-08-15 02:20:03 +00:00
var customFormatScore = model.Movie?.QualityProfile?.CalculateCustomFormatScore(customFormats) ?? 0;
return new ManualImportResource
{
Id = HashConverter.GetHashInt31(model.Path),
Path = model.Path,
RelativePath = model.RelativePath,
2020-05-26 01:55:10 +00:00
FolderName = model.FolderName,
Name = model.Name,
Size = model.Size,
Movie = model.Movie.ToResource(0),
2023-02-05 23:09:37 +00:00
ReleaseGroup = model.ReleaseGroup,
Quality = model.Quality,
Languages = model.Languages,
CustomFormats = customFormats.ToResource(false),
CustomFormatScore = customFormatScore,
2019-12-22 22:08:53 +00:00
2022-11-20 18:27:45 +00:00
// QualityWeight
DownloadId = model.DownloadId,
IndexerFlags = model.IndexerFlags,
Rejections = model.Rejections
};
}
public static List<ManualImportResource> ToResource(this IEnumerable<ManualImportItem> models)
{
return models.Select(ToResource).ToList();
}
}
}