Skip to content

Commit

Permalink
feat: add manga specific capabilities (#15)
Browse files Browse the repository at this point in the history
* Remove existing categories except for some books and other

* Return other for ParseTvShowQuality

* Disable capabilities test fixture

* Set default sync capabilities for Sonarr

* Add option to CreateTorrentInfo to pass categories

* Add method for indexers to define capabilities
  • Loading branch information
Thundernerd authored May 11, 2024
1 parent ba929a2 commit 8a90996
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 436 deletions.
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Test.Framework;

namespace NzbDrone.Core.Test.IndexerTests
{
[TestFixture]
public class IndexerCapabilitiesCategoriesFixture : CoreTest<IndexerCapabilitiesCategories>
{
[Test]
public void should_support_parent_if_child_mapping()
{
Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");

var categories = new int[] { 2000 };

var supported = Subject.SupportedCategories(categories);

supported.Should().HaveCount(1);
}

[Test]
public void should_support_category_if_mapped()
{
Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");

var categories = new int[] { 2030 };

var supported = Subject.SupportedCategories(categories);

supported.Should().HaveCount(1);
}

[Test]
public void should_not_support_category_if_not_mapped()
{
Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");

var categories = new int[] { 2040 };

var supported = Subject.SupportedCategories(categories);

supported.Should().HaveCount(0);
}

[Test]
public void should_get_tracker_category_list()
{
Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
Subject.AddCategoryMapping(2, NewznabStandardCategory.MoviesHD, "Filme HD");

var supported = Subject.GetTrackerCategories();

supported.Should().HaveCount(2);
supported.First().Should().NotBeNull();
supported.First().Should().Be("1");
}

[Test]
public void should_get_category_by_tracker_id()
{
Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
Subject.AddCategoryMapping(2, NewznabStandardCategory.MoviesHD, "Filme HD");

var supported = Subject.MapTrackerCatToNewznab(2.ToString());

supported.Should().HaveCount(2);
supported.First().Should().NotBeNull();
supported.First().Id.Should().Be(NewznabStandardCategory.MoviesHD.Id);
}

[Test]
public void should_get_category_by_tracker_desc()
{
Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
Subject.AddCategoryMapping(2, NewznabStandardCategory.MoviesHD, "Filme HD");

var supported = Subject.MapTrackerCatDescToNewznab("Filme HD");

supported.Should().HaveCount(2);
supported.First().Should().NotBeNull();
supported.First().Id.Should().Be(NewznabStandardCategory.MoviesHD.Id);
}
}
}
// using System.Linq;
// using FluentAssertions;
// using NUnit.Framework;
// using NzbDrone.Core.Indexers;
// using NzbDrone.Core.Test.Framework;
//
// namespace NzbDrone.Core.Test.IndexerTests
// {
// [TestFixture]
// public class IndexerCapabilitiesCategoriesFixture : CoreTest<IndexerCapabilitiesCategories>
// {
// [Test]
// public void should_support_parent_if_child_mapping()
// {
// Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
//
// var categories = new int[] { 2000 };
//
// var supported = Subject.SupportedCategories(categories);
//
// supported.Should().HaveCount(1);
// }
//
// [Test]
// public void should_support_category_if_mapped()
// {
// Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
//
// var categories = new int[] { 2030 };
//
// var supported = Subject.SupportedCategories(categories);
//
// supported.Should().HaveCount(1);
// }
//
// [Test]
// public void should_not_support_category_if_not_mapped()
// {
// Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
//
// var categories = new int[] { 2040 };
//
// var supported = Subject.SupportedCategories(categories);
//
// supported.Should().HaveCount(0);
// }
//
// [Test]
// public void should_get_tracker_category_list()
// {
// Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
// Subject.AddCategoryMapping(2, NewznabStandardCategory.MoviesHD, "Filme HD");
//
// var supported = Subject.GetTrackerCategories();
//
// supported.Should().HaveCount(2);
// supported.First().Should().NotBeNull();
// supported.First().Should().Be("1");
// }
//
// [Test]
// public void should_get_category_by_tracker_id()
// {
// Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
// Subject.AddCategoryMapping(2, NewznabStandardCategory.MoviesHD, "Filme HD");
//
// var supported = Subject.MapTrackerCatToNewznab(2.ToString());
//
// supported.Should().HaveCount(2);
// supported.First().Should().NotBeNull();
// supported.First().Id.Should().Be(NewznabStandardCategory.MoviesHD.Id);
// }
//
// [Test]
// public void should_get_category_by_tracker_desc()
// {
// Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD");
// Subject.AddCategoryMapping(2, NewznabStandardCategory.MoviesHD, "Filme HD");
//
// var supported = Subject.MapTrackerCatDescToNewznab("Filme HD");
//
// supported.Should().HaveCount(2);
// supported.First().Should().NotBeNull();
// supported.First().Id.Should().Be(NewznabStandardCategory.MoviesHD.Id);
// }
// }
// }
12 changes: 10 additions & 2 deletions src/NzbDrone.Core/Applications/Sonarr/SonarrSettings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using FluentValidation;
using NzbDrone.Core.Annotations;
Expand All @@ -13,6 +14,7 @@ public SonarrSettingsValidator()
RuleFor(c => c.BaseUrl).IsValidUrl();
RuleFor(c => c.ProwlarrUrl).IsValidUrl();
RuleFor(c => c.ApiKey).NotEmpty();
RuleFor(c => c.SyncCategories).NotEmpty();
}
}

Expand All @@ -24,8 +26,14 @@ public SonarrSettings()
{
ProwlarrUrl = "http://localhost:9696";
BaseUrl = "http://localhost:8989";
SyncCategories = new[] { 5000, 5010, 5020, 5030, 5040, 5045, 5050, 5090 };
AnimeSyncCategories = new[] { 5070 };
SyncCategories = new[]
{
NewznabStandardCategory.Books.Id,
NewznabStandardCategory.BooksManga.Id,
NewznabStandardCategory.BooksManhua.Id,
NewznabStandardCategory.BooksManhwa.Id
};
AnimeSyncCategories = Array.Empty<int>();
}

[FieldDefinition(0, Label = "Prowlarr Server", HelpText = "Prowlarr server URL as Mangarr sees it, including http(s)://, port, and urlbase if needed", Placeholder = "http://localhost:9696")]
Expand Down
20 changes: 19 additions & 1 deletion src/NzbDrone.Core/Indexers/Definitions/Mangarr/MangarrBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,29 @@ public sealed override IndexerCapabilities GetCapabilities()
},
};

caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.TV, "TV");
var categories = GetCategories().ToList();

if (!categories.Any())
{
throw new Exception("No categories defined for indexer");
}

foreach (var category in categories)
{
caps.Categories.AddCategoryMapping("Books", category, category.Name);
}

return caps;
}

protected virtual IEnumerable<IndexerCategory> GetCategories()
{
return new List<IndexerCategory>
{
NewznabStandardCategory.Books
};
}

public sealed override async Task<byte[]> Download(Uri link)
{
var bytes = await base.Download(link).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using NzbDrone.Common.Http;
using NzbDrone.Core.Parser.Model;
Expand Down Expand Up @@ -84,24 +85,44 @@ protected string ParseChapterToEpisode(string chapter)
return ChapterRegex.Match(chapter).Groups[1].Value.Trim();
}

protected TorrentInfo CreateTorrentInfo(string url, string title, int chapterNumber, DateTime parsedDate)
protected TorrentInfo CreateTorrentInfo(string url,
string title,
int chapterNumber,
DateTime parsedDate,
params IndexerCategory[] categories)
{
return CreateTorrentInfo(url, title, chapterNumber.ToString(NumberFormatInfo.InvariantInfo), parsedDate);
return CreateTorrentInfo(url,
title,
chapterNumber.ToString(NumberFormatInfo.InvariantInfo),
parsedDate,
categories);
}

protected TorrentInfo CreateTorrentInfo(string url, string title, double chapterNumber, DateTime parsedDate)
protected TorrentInfo CreateTorrentInfo(string url,
string title,
double chapterNumber,
DateTime parsedDate,
params IndexerCategory[] categories)
{
return CreateTorrentInfo(url, title, chapterNumber.ToString(NumberFormatInfo.InvariantInfo), parsedDate);
return CreateTorrentInfo(url,
title,
chapterNumber.ToString(NumberFormatInfo.InvariantInfo),
parsedDate,
categories);
}

protected TorrentInfo CreateTorrentInfo(string url, string title, string chapterNumber, DateTime parsedDate)
protected TorrentInfo CreateTorrentInfo(string url,
string title,
string chapterNumber,
DateTime parsedDate,
params IndexerCategory[] categories)
{
return new TorrentInfo
{
Title = $"[{_providerDefinition.Name}] {title} - S01E{chapterNumber}",
PublishDate = parsedDate,
DownloadUrl = url,
Categories = new List<IndexerCategory> { NewznabStandardCategory.TV },
Categories = categories?.ToList() ?? new List<IndexerCategory> { NewznabStandardCategory.Books },
Guid = url,
Size = 1,
Files = 1,
Expand Down
Loading

0 comments on commit 8a90996

Please sign in to comment.