mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-18 21:34:28 -04:00
Readded 0 cat to the end of the Newznab list
Signed-off-by: Robin Dadswell <robin@dadswell.email>
This commit is contained in:
@@ -9,8 +9,11 @@ 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 Lidarr
|
// Ignore categories not relevant for Readarr
|
||||||
var ignoreCategories = new[] { 0, 1000, 2000, 4000, 5000, 6000, 7000 };
|
var ignoreCategories = new[] { 1000, 2000, 3000, 4000, 5000, 6000 };
|
||||||
|
|
||||||
|
// And maybe relevant for specific users
|
||||||
|
var unimportantCategories = new[] { 0, 8000 };
|
||||||
|
|
||||||
var result = new List<FieldSelectOption>();
|
var result = new List<FieldSelectOption>();
|
||||||
|
|
||||||
@@ -20,25 +23,20 @@ namespace NzbDrone.Core.Indexers.Newznab
|
|||||||
categories = new List<NewznabCategory>();
|
categories = new List<NewznabCategory>();
|
||||||
categories.Add(new NewznabCategory
|
categories.Add(new NewznabCategory
|
||||||
{
|
{
|
||||||
Id = 3000,
|
Id = 7000,
|
||||||
Name = "Music",
|
Name = "Books",
|
||||||
Subcategories = new List<NewznabCategory>
|
Subcategories = new List<NewznabCategory>
|
||||||
{
|
{
|
||||||
new NewznabCategory { Id = 3040, Name = "Loseless" },
|
new NewznabCategory { Id = 7010, Name = "Misc books" },
|
||||||
new NewznabCategory { Id = 3010, Name = "MP3" },
|
new NewznabCategory { Id = 7020, Name = "Ebook" },
|
||||||
new NewznabCategory { Id = 3050, Name = "Other" },
|
new NewznabCategory { Id = 7030, Name = "Comics" },
|
||||||
new NewznabCategory { Id = 3030, Name = "Audiobook" }
|
new NewznabCategory { Id = 7040, Name = "Magazines" }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
@@ -48,7 +46,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
|
||||||
{
|
{
|
||||||
@@ -61,8 +59,6 @@ namespace NzbDrone.Core.Indexers.Newznab
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Sort((l, r) => l.Value.CompareTo(r.Value));
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
|
using Lidarr.Api.V1.Indexers;
|
||||||
|
using Lidarr.Http.ClientSchema;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.ThingiProvider;
|
using NzbDrone.Core.ThingiProvider;
|
||||||
|
|
||||||
@@ -18,5 +21,172 @@ 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 GetNewznabSchemav1(string name = null)
|
||||||
|
{
|
||||||
|
var schema = Indexers.Schema().First(v => v.Implementation == "Newznab");
|
||||||
|
|
||||||
|
schema.Name = name;
|
||||||
|
schema.EnableRss = false;
|
||||||
|
schema.EnableAutomaticSearch = false;
|
||||||
|
schema.EnableInteractiveSearch = 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 = GetNewznabSchemav1();
|
||||||
|
|
||||||
|
var categoriesField = GetCategoriesField(schema);
|
||||||
|
|
||||||
|
categoriesField.Value.Should().BeOfType<JArray>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void v3_categories_should_be_array()
|
||||||
|
{
|
||||||
|
var schema = GetNewznabSchemav1();
|
||||||
|
|
||||||
|
var categoriesField = GetCategoriesField(schema);
|
||||||
|
|
||||||
|
categoriesField.Value.Should().BeOfType<JArray>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void v2_categories_should_accept_null()
|
||||||
|
{
|
||||||
|
var schema = GetNewznabSchemav1("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 = GetNewznabSchemav1("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 = GetNewznabSchemav1("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 = GetNewznabSchemav1("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 = GetNewznabSchemav1("Testv3null");
|
||||||
|
|
||||||
|
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 v3_categories_should_accept_emptystring()
|
||||||
|
{
|
||||||
|
var schema = GetNewznabSchemav1("Testv3emptystring");
|
||||||
|
|
||||||
|
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 v3_categories_should_accept_string()
|
||||||
|
{
|
||||||
|
var schema = GetNewznabSchemav1("Testv3string");
|
||||||
|
|
||||||
|
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 v3_categories_should_accept_array()
|
||||||
|
{
|
||||||
|
var schema = GetNewznabSchemav1("Testv3array");
|
||||||
|
|
||||||
|
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 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using Readarr.Api.V1.Indexers;
|
using Readarr.Api.V1.Indexers;
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
|
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,7 +209,11 @@ namespace Readarr.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>());
|
||||||
}
|
}
|
||||||
@@ -223,7 +227,11 @@ namespace Readarr.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>());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user