Skip to content

Commit

Permalink
nullables wtf
Browse files Browse the repository at this point in the history
  • Loading branch information
Yucked committed Nov 14, 2023
1 parent b48551e commit 5adf235
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Grimoire.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
41 changes: 37 additions & 4 deletions src/Sources/OmegaScansSource.cs
Original file line number Diff line number Diff line change
@@ -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<OmegaScansSource> logger) : IGrimoireSource {
public string Name
=> "Omega Scans";

Expand All @@ -14,14 +17,44 @@ public string Url
public string Icon
=> "https://omegascans.org/icon.png";

private readonly HttpHandler _httpHandler;
private readonly Dictionary<string, (string Name, string Cover, string Genre)> _apiCache = new();

public async Task<IReadOnlyList<Manga>> 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<Manga> 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<Chapter> FetchChapterAsync(Chapter chapter) {
Expand Down

0 comments on commit 5adf235

Please sign in to comment.