mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-22 22:14:44 -04:00
Extend Qualities and Setup Default Groups (#127)
* Extend Qualities and Setup Default Groups * fixup! Extend Qualities * fixup! Codacy * fixup! One more
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Profiles.Qualities;
|
||||
using Lidarr.Http;
|
||||
|
||||
@@ -7,44 +5,19 @@ namespace Lidarr.Api.V1.Profiles.Quality
|
||||
{
|
||||
public class QualityProfileSchemaModule : LidarrRestModule<QualityProfileResource>
|
||||
{
|
||||
public QualityProfileSchemaModule()
|
||||
private readonly IProfileService _profileService;
|
||||
|
||||
public QualityProfileSchemaModule(IProfileService profileService)
|
||||
: base("/qualityprofile/schema")
|
||||
{
|
||||
_profileService = profileService;
|
||||
GetResourceSingle = GetSchema;
|
||||
}
|
||||
|
||||
private QualityProfileResource GetSchema()
|
||||
{
|
||||
var groupedQualites = NzbDrone.Core.Qualities.Quality.DefaultQualityDefinitions.GroupBy(q => q.Weight);
|
||||
var items = new List<ProfileQualityItem>();
|
||||
var groupId = 1000;
|
||||
Profile qualityProfile = _profileService.GetDefaultProfile(string.Empty);
|
||||
|
||||
foreach (var group in groupedQualites)
|
||||
{
|
||||
if (group.Count() == 1)
|
||||
{
|
||||
items.Add(new ProfileQualityItem { Quality = group.First().Quality, Allowed = false });
|
||||
continue;
|
||||
}
|
||||
|
||||
items.Add(new ProfileQualityItem
|
||||
{
|
||||
Id = groupId,
|
||||
Name = group.First().GroupName,
|
||||
Items = group.Select(g => new ProfileQualityItem
|
||||
{
|
||||
Quality = g.Quality,
|
||||
Allowed = false
|
||||
}).ToList(),
|
||||
Allowed = false
|
||||
});
|
||||
|
||||
groupId++;
|
||||
}
|
||||
|
||||
var qualityProfile = new Profile();
|
||||
qualityProfile.Cutoff = NzbDrone.Core.Qualities.Quality.Unknown.Id;
|
||||
qualityProfile.Items = items;
|
||||
|
||||
return qualityProfile.ToResource();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user