diff --git a/src/Grimoire.csproj b/src/Grimoire.csproj index c252547..765a99e 100644 --- a/src/Grimoire.csproj +++ b/src/Grimoire.csproj @@ -3,6 +3,7 @@ net8.0 enable + enable diff --git a/src/Sources/OmegaScansSource.cs b/src/Sources/OmegaScansSource.cs index 5d1af0e..61ae90c 100644 --- a/src/Sources/OmegaScansSource.cs +++ b/src/Sources/OmegaScansSource.cs @@ -1,10 +1,13 @@ +using System.Text.Json; using Grimoire.Handlers; using Grimoire.Models; using Grimoire.Sources.Interfaces; namespace Grimoire.Sources; -public class OmegaScansSource : IGrimoireSource { +public class OmegaScansSource( + HttpHandler httpHandler, + ILogger logger) : IGrimoireSource { public string Name => "Omega Scans"; @@ -14,14 +17,44 @@ public string Url public string Icon => "https://omegascans.org/icon.png"; - private readonly HttpHandler _httpHandler; + private readonly Dictionary _apiCache = new(); public async Task> GetMangasAsync() { - throw new NotImplementedException(); + var stream = + await httpHandler.GetStreamAsync($"{Url}/query?visibility=Public&series_type=All&perPage=100"); + using var document = await JsonDocument.ParseAsync(stream!); + if (!document.RootElement.TryGetProperty("data", out var dataElement)) { + logger.LogError("Unable to fetch JSON data from source!"); + return null; + } + + var tasks = dataElement + .EnumerateArray() + .AsParallel() + .Select(x => { + var slug = x.GetProperty("series_slug").GetString()!; + _apiCache.Add(slug, + (x.GetProperty("title").GetString()!, + x.GetProperty("thumbnail").GetString()!, + x.GetProperty("series_type").GetString()!)); + + return GetMangaAsync($"https://omegascans.org/series/{slug}"); + }); + + var mangas = await Task.WhenAll(tasks); + _apiCache.Clear(); + return mangas; } public async Task GetMangaAsync(string url) { - throw new NotImplementedException(); + var document = await httpHandler.ParseAsync(url); + var manga = new Manga { + Summary = document + .QuerySelector("div.bg-gray-800 > p") + .TextContent + }; + + return manga; } public async Task FetchChapterAsync(Chapter chapter) {