Readded Movies cat to the end of the Newznab list

This commit is contained in:
Taloth Saldono 2020-11-14 22:33:03 +01:00
parent 158e31d54a
commit e5ec4e706a
5 changed files with 212 additions and 14 deletions

View File

@ -10,8 +10,10 @@ namespace NzbDrone.Core.Indexers.Newznab
{ {
public static List<FieldSelectOption> GetFieldSelectOptions(List<NewznabCategory> categories) public static List<FieldSelectOption> GetFieldSelectOptions(List<NewznabCategory> categories)
{ {
// Ignore categories not relevant for Sonarr // Categories not relevant for Sonarr
var ignoreCategories = new[] { 0, 1000, 2000, 3000, 4000, 6000, 7000 }; var ignoreCategories = new[] { 1000, 3000, 4000, 6000, 7000 };
// And maybe relevant for specific users
var unimportantCategories = new[] { 0, 2000 };
var result = new List<FieldSelectOption>(); var result = new List<FieldSelectOption>();
@ -38,13 +40,8 @@ namespace NzbDrone.Core.Indexers.Newznab
}); });
} }
foreach (var category in categories) foreach (var category in categories.Where(cat => !ignoreCategories.Contains(cat.Id)).OrderBy(cat => unimportantCategories.Contains(cat.Id)).ThenBy(cat => cat.Id))
{ {
if (ignoreCategories.Contains(category.Id))
{
continue;
}
result.Add(new FieldSelectOption result.Add(new FieldSelectOption
{ {
Value = category.Id, Value = category.Id,
@ -54,7 +51,7 @@ namespace NzbDrone.Core.Indexers.Newznab
if (category.Subcategories != null) if (category.Subcategories != null)
{ {
foreach (var subcat in category.Subcategories) foreach (var subcat in category.Subcategories.OrderBy(cat => cat.Id))
{ {
result.Add(new FieldSelectOption result.Add(new FieldSelectOption
{ {
@ -67,8 +64,6 @@ namespace NzbDrone.Core.Indexers.Newznab
} }
} }
result.Sort((l, r) => l.Value.CompareTo(r.Value));
return result; return result;
} }
} }

View File

@ -1,7 +1,10 @@
using System.Linq; using System.Linq;
using FluentAssertions; using FluentAssertions;
using Newtonsoft.Json.Linq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Api.Indexers;
using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.ThingiProvider;
using Sonarr.Http.ClientSchema;
namespace NzbDrone.Integration.Test.ApiTests namespace NzbDrone.Integration.Test.ApiTests
{ {
@ -18,5 +21,183 @@ namespace NzbDrone.Integration.Test.ApiTests
indexers.Should().NotContain(c => string.IsNullOrWhiteSpace(c.Name)); indexers.Should().NotContain(c => string.IsNullOrWhiteSpace(c.Name));
indexers.Where(c => c.ConfigContract == typeof(NullConfig).Name).Should().OnlyContain(c => c.EnableRss); indexers.Where(c => c.ConfigContract == typeof(NullConfig).Name).Should().OnlyContain(c => c.EnableRss);
} }
private IndexerResource GetNewznabSchemav2(string name = null)
{
var schema = Indexers.Schema().First(v => v.Implementation == "Newznab");
schema.Name = name;
schema.EnableRss = false;
schema.EnableSearch = false;
return schema;
}
private IndexerResource GetNewznabSchemav3(string name = null)
{
var schema = Indexersv3.Schema().First(v => v.Implementation == "Newznab");
schema.Name = name;
schema.EnableRss = false;
schema.EnableSearch = false;
return schema;
}
private Field GetCategoriesField(IndexerResource resource)
{
var field = resource.Fields.First(v => v.Name == "categories");
return field;
}
[Test]
public void v2_categories_should_be_array()
{
var schema = GetNewznabSchemav2();
var categoriesField = GetCategoriesField(schema);
categoriesField.Value.Should().BeOfType<JArray>();
}
[Test]
public void v3_categories_should_be_array()
{
var schema = GetNewznabSchemav3();
var categoriesField = GetCategoriesField(schema);
categoriesField.Value.Should().BeOfType<JArray>();
}
[Test]
public void v2_categories_should_accept_null()
{
var schema = GetNewznabSchemav2("Testv2null");
var categoriesField = GetCategoriesField(schema);
categoriesField.Value = null;
var result = Indexers.Post(schema);
var resultArray = GetCategoriesField(result).Value;
resultArray.Should().BeOfType<JArray>();
resultArray.As<JArray>().Should().BeEmpty();
}
[Test]
public void v2_categories_should_accept_emptystring()
{
var schema = GetNewznabSchemav2("Testv2emptystring");
var categoriesField = GetCategoriesField(schema);
categoriesField.Value = "";
var result = Indexers.Post(schema);
var resultArray = GetCategoriesField(result).Value;
resultArray.Should().BeOfType<JArray>();
resultArray.As<JArray>().Should().BeEmpty();
}
[Test]
public void v2_categories_should_accept_string()
{
var schema = GetNewznabSchemav2("Testv2string");
var categoriesField = GetCategoriesField(schema);
categoriesField.Value = "1000,1010";
var result = Indexers.Post(schema);
var resultArray = GetCategoriesField(result).Value;
resultArray.Should().BeOfType<JArray>();
resultArray.As<JArray>().ToObject<int[]>().Should().BeEquivalentTo(new[] { 1000, 1010 });
}
[Test]
public void v2_categories_should_accept_array()
{
var schema = GetNewznabSchemav2("Testv2array");
var categoriesField = GetCategoriesField(schema);
categoriesField.Value = new object[] { 1000, 1010 };
var result = Indexers.Post(schema);
var resultArray = GetCategoriesField(result).Value;
resultArray.Should().BeOfType<JArray>();
resultArray.As<JArray>().ToObject<int[]>().Should().BeEquivalentTo(new[] { 1000, 1010 });
}
[Test]
public void v3_categories_should_accept_null()
{
var schema = GetNewznabSchemav3("Testv3null");
var categoriesField = GetCategoriesField(schema);
categoriesField.Value = null;
var result = Indexersv3.Post(schema);
var resultArray = GetCategoriesField(result).Value;
resultArray.Should().BeOfType<JArray>();
resultArray.As<JArray>().Should().BeEmpty();
}
[Test]
public void v3_categories_should_accept_emptystring()
{
var schema = GetNewznabSchemav3("Testv3emptystring");
var categoriesField = GetCategoriesField(schema);
categoriesField.Value = "";
var result = Indexersv3.Post(schema);
var resultArray = GetCategoriesField(result).Value;
resultArray.Should().BeOfType<JArray>();
resultArray.As<JArray>().Should().BeEmpty();
}
[Test]
public void v3_categories_should_accept_string()
{
var schema = GetNewznabSchemav3("Testv3string");
var categoriesField = GetCategoriesField(schema);
categoriesField.Value = "1000,1010";
var result = Indexersv3.Post(schema);
var resultArray = GetCategoriesField(result).Value;
resultArray.Should().BeOfType<JArray>();
resultArray.As<JArray>().ToObject<int[]>().Should().BeEquivalentTo(new[] { 1000, 1010 });
}
[Test]
public void v3_categories_should_accept_array()
{
var schema = GetNewznabSchemav3("Testv3array");
var categoriesField = GetCategoriesField(schema);
categoriesField.Value = new object[] { 1000, 1010 };
var result = Indexersv3.Post(schema);
var resultArray = GetCategoriesField(result).Value;
resultArray.Should().BeOfType<JArray>();
resultArray.As<JArray>().ToObject<int[]>().Should().BeEquivalentTo(new[] { 1000, 1010 });
}
} }
} }

View File

@ -1,4 +1,5 @@
using NzbDrone.Api.Indexers; using System.Collections.Generic;
using NzbDrone.Api.Indexers;
using RestSharp; using RestSharp;
namespace NzbDrone.Integration.Test.Client namespace NzbDrone.Integration.Test.Client
@ -9,5 +10,11 @@ namespace NzbDrone.Integration.Test.Client
: base(restClient, apiKey) : base(restClient, apiKey)
{ {
} }
public List<IndexerResource> Schema()
{
var request = BuildRequest("/schema");
return Get<List<IndexerResource>>(request);
}
} }
} }

View File

@ -37,6 +37,7 @@ namespace NzbDrone.Integration.Test
public abstract class IntegrationTestBase public abstract class IntegrationTestBase
{ {
protected RestClient RestClient { get; private set; } protected RestClient RestClient { get; private set; }
protected RestClient RestClientv3 { get; private set; }
public ClientBase<BlacklistResource> Blacklist; public ClientBase<BlacklistResource> Blacklist;
public CommandClient Commands; public CommandClient Commands;
@ -45,6 +46,7 @@ namespace NzbDrone.Integration.Test
public ClientBase<HistoryResource> History; public ClientBase<HistoryResource> History;
public ClientBase<HostConfigResource> HostConfig; public ClientBase<HostConfigResource> HostConfig;
public IndexerClient Indexers; public IndexerClient Indexers;
public IndexerClient Indexersv3;
public LogsClient Logs; public LogsClient Logs;
public ClientBase<NamingConfigResource> NamingConfig; public ClientBase<NamingConfigResource> NamingConfig;
public NotificationClient Notifications; public NotificationClient Notifications;
@ -100,6 +102,10 @@ namespace NzbDrone.Integration.Test
RestClient.AddDefaultHeader("Authentication", ApiKey); RestClient.AddDefaultHeader("Authentication", ApiKey);
RestClient.AddDefaultHeader("X-Api-Key", ApiKey); RestClient.AddDefaultHeader("X-Api-Key", ApiKey);
RestClientv3 = new RestClient(RootUrl + "api/v3/");
RestClientv3.AddDefaultHeader("Authentication", ApiKey);
RestClientv3.AddDefaultHeader("X-Api-Key", ApiKey);
Blacklist = new ClientBase<BlacklistResource>(RestClient, ApiKey); Blacklist = new ClientBase<BlacklistResource>(RestClient, ApiKey);
Commands = new CommandClient(RestClient, ApiKey); Commands = new CommandClient(RestClient, ApiKey);
DownloadClients = new DownloadClientClient(RestClient, ApiKey); DownloadClients = new DownloadClientClient(RestClient, ApiKey);
@ -107,6 +113,7 @@ namespace NzbDrone.Integration.Test
History = new ClientBase<HistoryResource>(RestClient, ApiKey); History = new ClientBase<HistoryResource>(RestClient, ApiKey);
HostConfig = new ClientBase<HostConfigResource>(RestClient, ApiKey, "config/host"); HostConfig = new ClientBase<HostConfigResource>(RestClient, ApiKey, "config/host");
Indexers = new IndexerClient(RestClient, ApiKey); Indexers = new IndexerClient(RestClient, ApiKey);
Indexersv3 = new IndexerClient(RestClientv3, ApiKey);
Logs = new LogsClient(RestClient, ApiKey); Logs = new LogsClient(RestClient, ApiKey);
NamingConfig = new ClientBase<NamingConfigResource>(RestClient, ApiKey, "config/naming"); NamingConfig = new ClientBase<NamingConfigResource>(RestClient, ApiKey, "config/naming");
Notifications = new NotificationClient(RestClient, ApiKey); Notifications = new NotificationClient(RestClient, ApiKey);

View File

@ -217,7 +217,11 @@ namespace Sonarr.Http.ClientSchema
{ {
return fieldValue => return fieldValue =>
{ {
if (fieldValue.GetType() == typeof(JArray)) if (fieldValue == null)
{
return Enumerable.Empty<int>();
}
else if (fieldValue.GetType() == typeof(JArray))
{ {
return ((JArray)fieldValue).Select(s => s.Value<int>()); return ((JArray)fieldValue).Select(s => s.Value<int>());
} }
@ -232,7 +236,11 @@ namespace Sonarr.Http.ClientSchema
{ {
return fieldValue => return fieldValue =>
{ {
if (fieldValue.GetType() == typeof(JArray)) if (fieldValue == null)
{
return Enumerable.Empty<string>();
}
else if (fieldValue.GetType() == typeof(JArray))
{ {
return ((JArray)fieldValue).Select(s => s.Value<string>()); return ((JArray)fieldValue).Select(s => s.Value<string>());
} }