1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-20 21:55:03 -04:00

New: Calculate custom formats on demand

This commit is contained in:
ta264
2020-01-22 21:47:33 +00:00
parent 13701498ce
commit df101258c5
103 changed files with 1901 additions and 1346 deletions
@@ -0,0 +1,50 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using NzbDrone.Core.CustomFormats;
using Radarr.Http.REST;
namespace Radarr.Api.V3.CustomFormats
{
public class CustomFormatResource : RestResource
{
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)]
public override int Id { get; set; }
public string Name { get; set; }
public string FormatTags { get; set; }
public string Simplicity { get; set; }
}
public static class CustomFormatResourceMapper
{
public static CustomFormatResource ToResource(this CustomFormat model)
{
return new CustomFormatResource
{
Id = model.Id,
Name = model.Name,
FormatTags = string.Join(",", model.FormatTags.Select(t => t.Raw.ToUpper()).ToList()),
};
}
public static List<CustomFormatResource> ToResource(this IEnumerable<CustomFormat> models)
{
return models.Select(m => m.ToResource()).ToList();
}
public static CustomFormat ToModel(this CustomFormatResource resource)
{
if (resource.Id == 0 && resource.Name == "None")
{
return CustomFormat.None;
}
return new CustomFormat
{
Id = resource.Id,
Name = resource.Name,
FormatTags = resource.FormatTags.Split(',').Select(s => new FormatTag(s)).ToList()
};
}
}
}