Added contributor classes for manga. Implemented MangaDex search.
This commit is contained in:
@@ -1,14 +1,44 @@
|
||||
using MangaReader.Core.HttpService;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MangaReader.Core.Search.NatoManga;
|
||||
|
||||
public class NatoMangaSearchProvider(IHttpService httpService) : MangaSearchProviderBase<NatoMangaSearchResult[]>(httpService)
|
||||
{
|
||||
// https://www.natomanga.com/home/search/json?searchword=gal_can_t_be_kind
|
||||
|
||||
protected override string GetSearchUrl(string keyword)
|
||||
{
|
||||
return $"https://www.natomanga.com/home/search/json?searchword={keyword}";
|
||||
string formattedSeachWord = GetFormattedSearchWord(keyword);
|
||||
|
||||
return $"https://www.natomanga.com/home/search/json?searchword={formattedSeachWord}";
|
||||
}
|
||||
|
||||
private static string GetFormattedSearchWord(string input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
return string.Empty;
|
||||
|
||||
// Convert to lowercase and normalize to decompose accents
|
||||
string normalized = input.ToLowerInvariant()
|
||||
.Normalize(NormalizationForm.FormD);
|
||||
|
||||
// Remove diacritics
|
||||
var sb = new StringBuilder();
|
||||
foreach (var c in normalized)
|
||||
{
|
||||
var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
|
||||
if (unicodeCategory != UnicodeCategory.NonSpacingMark)
|
||||
sb.Append(c);
|
||||
}
|
||||
|
||||
// Replace non-alphanumeric characters with underscores
|
||||
string cleaned = Regex.Replace(sb.ToString(), @"[^a-z0-9]+", "_");
|
||||
|
||||
// Trim and collapse underscores
|
||||
cleaned = Regex.Replace(cleaned, "_{2,}", "_").Trim('_');
|
||||
|
||||
return cleaned;
|
||||
}
|
||||
|
||||
protected override MangaSearchResult[] GetSearchResult(NatoMangaSearchResult[] searchResult)
|
||||
@@ -18,6 +48,7 @@ public class NatoMangaSearchProvider(IHttpService httpService) : MangaSearchProv
|
||||
{
|
||||
Source = "NatoManga",
|
||||
Title = searchResult.Name,
|
||||
Thumbnail = searchResult.Thumb,
|
||||
Url = searchResult.Url
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user