Added abstraction layeer IHtmlLoader. Finished reorganizing test project folder structure.

This commit is contained in:
2025-06-09 00:09:59 -04:00
parent b5d22c3c7e
commit c26ed11bfc
30 changed files with 1966 additions and 132 deletions

View File

@@ -1,4 +1,4 @@
using MangaReader.Core.HttpService;
using MangaReader.Core.Http;
using System.Text;
using System.Text.Json;

View File

@@ -50,7 +50,16 @@ public class MangaDexMetadataProvider(IMangaDexClient mangaDexClient) : IMangaMe
return mangaGuid;
}
private static string GetTitle(MangaAttributes attributes)
private static SourceMangaTitle GetTitle(MangaAttributes attributes)
{
return new()
{
Name = GetTileName(attributes),
Language = Language.English
};
}
private static string GetTileName(MangaAttributes attributes)
{
if (attributes.Title.TryGetValue("en", out string? title))
return title;
@@ -81,7 +90,7 @@ public class MangaDexMetadataProvider(IMangaDexClient mangaDexClient) : IMangaMe
SourceMangaTitle sourceMangaTitle = new()
{
Title = alternateTitle[alternateTitleKey],
Name = alternateTitle[alternateTitleKey],
Language = language
};

View File

@@ -1,23 +1,28 @@
using HtmlAgilityPack;
using MangaReader.Core.Common;
using MangaReader.Core.Http;
using MangaReader.Core.Metadata;
using System.Text;
using System.Web;
namespace MangaReader.Core.Sources.MangaNato.Metadata;
public class MangaNatoWebCrawler : MangaWebCrawler
public class MangaNatoWebCrawler(IHtmlLoader htmlLoader) : MangaWebCrawler
{
public override string SourceId => "MangaNato";
public override async Task<SourceManga?> GetMangaAsync(string url, CancellationToken cancellationToken)
{
HtmlDocument document = await GetHtmlDocumentAsync(url, cancellationToken);
HtmlDocument document = await htmlLoader.GetHtmlDocumentAsync(url, cancellationToken);
MangaNatoMangaDocument node = new(document);
SourceManga manga = new()
{
Title = node.TitleNode?.InnerText ?? string.Empty,
Title = new()
{
Name = node.TitleNode?.InnerText ?? string.Empty,
Language = Language.Unknown
},
AlternateTitles = GetAlternateTitles(node.AlternateTitlesNode),
Contributors = GetContributors(node.AuthorsNode),
Status = GetStatus(node.StatusNode),
@@ -26,7 +31,11 @@ public class MangaNatoWebCrawler : MangaWebCrawler
RatingPercent = GetRatingPercent(node.AverageRatingNode, node.BestRatingNode),
Votes = node.VotesNode != null ? int.Parse(node.VotesNode.InnerText) : 0,
Views = GetViews(node.ViewsNode),
Description = GetTextFromNodes(node.StoryDescriptionTextNodes),
Description = new()
{
Name = GetTextFromNodes(node.StoryDescriptionTextNodes),
Language = Language.Unknown
},
Chapters = GetChapters(node.ChapterNodes)
};
@@ -46,7 +55,7 @@ public class MangaNatoWebCrawler : MangaWebCrawler
{
SourceMangaTitle sourceMangaTitle = new()
{
Title = title,
Name = title,
Language = Language.Unknown
};

View File

@@ -1,4 +1,4 @@
using MangaReader.Core.HttpService;
using MangaReader.Core.Http;
using System.Globalization;
using System.Text;
using System.Text.Json;

View File

@@ -1,20 +1,25 @@
using HtmlAgilityPack;
using MangaReader.Core.Http;
using MangaReader.Core.Metadata;
namespace MangaReader.Core.Sources.NatoManga.Metadata;
public class NatoMangaWebCrawler : MangaWebCrawler
public class NatoMangaWebCrawler(IHtmlLoader htmlLoader) : MangaWebCrawler
{
public override string SourceId => "NatoManga";
public override async Task<SourceManga?> GetMangaAsync(string url, CancellationToken cancellationToken)
{
HtmlDocument document = await GetHtmlDocumentAsync(url, cancellationToken);
HtmlDocument document = await htmlLoader.GetHtmlDocumentAsync(url, cancellationToken);
NatoMangaHtmlDocument node = new(document);
SourceManga manga = new()
{
Title = node.TitleNode?.InnerText ?? string.Empty,
Title = new()
{
Name = node.TitleNode?.InnerText ?? string.Empty,
Language = Common.Language.Unknown
},
Genres = GetGenres(node.GenresNode),
Chapters = GetChapters(node.ChapterNodes)
};