Added NatoManga page provider logic. Fixed UI font configuration.
This commit is contained in:
@@ -22,18 +22,22 @@ public static class ServiceCollectionExtensions
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:139.0) Gecko/20100101 Firefox/139.0");
|
||||
});
|
||||
|
||||
// Http
|
||||
services.AddScoped<IHttpService, HttpService>();
|
||||
services.AddScoped<IHtmlLoader, HtmlLoader>();
|
||||
|
||||
// NatoManga
|
||||
//services.AddScoped<INatoMangaClient, NatoMangaClient>();
|
||||
services.AddScoped<IMangaDexClient, MangaDexClient>();
|
||||
|
||||
//services.AddScoped<IMangaSearchProvider, NatoMangaSearchProvider>();
|
||||
services.AddScoped<IMangaSearchProvider, MangaDexSearchProvider>();
|
||||
services.AddScoped<IMangaSearchCoordinator, MangaSearchCoordinator>();
|
||||
//services.AddScoped<IMangaMetadataProvider, NatoMangaWebCrawler>();
|
||||
|
||||
///services.AddScoped<IMangaMetadataProvider, NatoMangaWebCrawler>();
|
||||
// MangaDex
|
||||
services.AddScoped<IMangaDexClient, MangaDexClient>();
|
||||
services.AddScoped<IMangaSearchProvider, MangaDexSearchProvider>();
|
||||
services.AddScoped<IMangaMetadataProvider, MangaDexMetadataProvider>();
|
||||
|
||||
services.AddScoped<IMangaSearchCoordinator, MangaSearchCoordinator>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
8
MangaReader.Core/Pages/IMangaPageProvider.cs
Normal file
8
MangaReader.Core/Pages/IMangaPageProvider.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using MangaReader.Core.Sources;
|
||||
|
||||
namespace MangaReader.Core.Pages;
|
||||
|
||||
public interface IMangaPageProvider : IMangaSourceComponent
|
||||
{
|
||||
Task<IReadOnlyList<string>> GetPageImageUrlsAsync(string chapterUrl, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using HtmlAgilityPack;
|
||||
using MangaReader.Core.Http;
|
||||
using MangaReader.Core.Pages;
|
||||
|
||||
namespace MangaReader.Core.Sources.NatoManga.Pages;
|
||||
|
||||
public class NatoMangaPageProvider(IHtmlLoader htmlLoader) : IMangaPageProvider
|
||||
{
|
||||
public string SourceId => "NatoManga";
|
||||
|
||||
public async Task<IReadOnlyList<string>> GetPageImageUrlsAsync(string chapterUrl, CancellationToken cancellationToken)
|
||||
{
|
||||
List<string> imageUrlCollection = [];
|
||||
|
||||
HtmlDocument document = await htmlLoader.GetHtmlDocumentAsync(chapterUrl, cancellationToken);
|
||||
HtmlNodeCollection? htmlNodeCollection = GetImageNodeCollection(document);
|
||||
|
||||
if (htmlNodeCollection == null)
|
||||
return imageUrlCollection;
|
||||
|
||||
foreach (var htmlNode in htmlNodeCollection)
|
||||
{
|
||||
string imageSourceUrl = htmlNode.GetAttributeValue<string>("src", string.Empty);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(imageSourceUrl))
|
||||
continue;
|
||||
|
||||
imageUrlCollection.Add(imageSourceUrl);
|
||||
}
|
||||
|
||||
return imageUrlCollection;
|
||||
}
|
||||
|
||||
private static HtmlNodeCollection? GetImageNodeCollection(HtmlDocument document)
|
||||
{
|
||||
HtmlNode? chapterReaderNode = document.DocumentNode.SelectSingleNode(".//div[@class='container-chapter-reader']");
|
||||
|
||||
if (chapterReaderNode == null)
|
||||
return null;
|
||||
|
||||
return chapterReaderNode.SelectNodes(".//img");
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@
|
||||
<EmbeddedResource Include="Sources\MangaDex\Api\Manga-Cover-Art-Response.json" />
|
||||
<EmbeddedResource Include="Sources\MangaDex\Api\Manga-Search-Response-2.json" />
|
||||
<EmbeddedResource Include="Sources\MangaDex\Api\Manga-Search-Response.json" />
|
||||
<EmbeddedResource Include="Sources\NatoManga\Metadata\Manga-Chapter-Response.html" />
|
||||
<EmbeddedResource Include="Sources\NatoManga\Pages\Manga-Chapter-Response.html" />
|
||||
<EmbeddedResource Include="Sources\NatoManga\Api\Manga-Search-Response.json" />
|
||||
<EmbeddedResource Include="Sources\MangaDex\Api\Manga-Feed-Response.json" />
|
||||
<EmbeddedResource Include="Sources\MangaDex\Api\Manga-Response.json" />
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using MangaReader.Core.Http;
|
||||
using MangaReader.Core.Sources.NatoManga.Pages;
|
||||
using MangaReader.Tests.Utilities;
|
||||
using NSubstitute;
|
||||
using Shouldly;
|
||||
|
||||
namespace MangaReader.Tests.Sources.NatoManga.Pages;
|
||||
|
||||
public class NatoMangaPageTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Get_Pages()
|
||||
{
|
||||
string mangaHtml = await ReadJsonResourceAsync("Manga-Chapter-Response.html");
|
||||
|
||||
IHttpService httpService = Substitute.For<IHttpService>();
|
||||
|
||||
httpService.GetStringAsync(Arg.Any<string>(), CancellationToken.None)
|
||||
.Returns(Task.FromResult(mangaHtml));
|
||||
|
||||
HtmlLoader htmlLoader = new(httpService);
|
||||
|
||||
NatoMangaPageProvider pageProvider = new(htmlLoader);
|
||||
IReadOnlyList<string> pageImageUrls = await pageProvider.GetPageImageUrlsAsync("/test-url", CancellationToken.None);
|
||||
|
||||
pageImageUrls.Count.ShouldBe(13);
|
||||
pageImageUrls[0].ShouldBe("https://img-r1.2xstorage.com/gal-cant-be-kind-to-otaku/69/0.webp");
|
||||
pageImageUrls[12].ShouldBe("https://img-r1.2xstorage.com/gal-cant-be-kind-to-otaku/69/12.webp");
|
||||
}
|
||||
|
||||
private static async Task<string> ReadJsonResourceAsync(string resourceName)
|
||||
{
|
||||
return await ResourceHelper.ReadJsonResourceAsync($"MangaReader.Tests.Sources.NatoManga.Pages.{resourceName}");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:MangaReader.WinUI.ViewModels">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<FontFamily x:Key="PoppinsRegular">ms-appx:///Assets/Fonts/Poppins-Regular.ttf#Poppins Regular</FontFamily>
|
||||
<FontFamily x:Key="PoppinsMedium">ms-appx:///Assets/Fonts/Poppins-Medium.ttf#Poppins Medium</FontFamily>
|
||||
<FontFamily x:Key="PoppinsSemiBold">ms-appx:///Assets/Fonts/Poppins-SemiBold.ttf#Poppins SemiBold</FontFamily>
|
||||
<FontFamily x:Key="PoppinsRegular">ms-appx:///Assets/Fonts/Poppins-Regular.otf#Poppins Regular</FontFamily>
|
||||
<FontFamily x:Key="PoppinsMedium">ms-appx:///Assets/Fonts/Poppins-Medium.otf#Poppins Medium</FontFamily>
|
||||
<FontFamily x:Key="PoppinsSemiBold">ms-appx:///Assets/Fonts/Poppins-SemiBold.otf#Poppins SemiBold</FontFamily>
|
||||
|
||||
</ResourceDictionary>
|
||||
Reference in New Issue
Block a user