From 73df8ad2137a566b59068ec8baaac1f5223f6005 Mon Sep 17 00:00:00 2001 From: glax <--local> Date: Thu, 18 May 2023 16:21:54 +0200 Subject: [PATCH] Added functionality to DownloadChapter in Mangadex --- Tranga/Connectors/MangaDex.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Tranga/Connectors/MangaDex.cs b/Tranga/Connectors/MangaDex.cs index 5297124..aa16fa7 100644 --- a/Tranga/Connectors/MangaDex.cs +++ b/Tranga/Connectors/MangaDex.cs @@ -145,6 +145,20 @@ public class MangaDex : Connector public override void DownloadChapter(Publication publication, Chapter chapter) { - throw new NotImplementedException(); + DownloadClient.RequestResult requestResult = + _downloadClient.GetPage($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'"); + JsonObject? result = JsonSerializer.Deserialize(requestResult.result); + if (result is null) + return; + + string baseUrl = result["baseUrl"]!.GetValue(); + string hash = result["chapter"]!["hash"].GetValue(); + JsonArray imageFileNamesObject = result["chapter"]!["data"]!.AsArray(); + HashSet imageFileNames = new(); + foreach (JsonObject imageFileNameObject in imageFileNamesObject) + imageFileNames.Add(imageFileNameObject!.GetValue()); + + foreach(string imageFileName in imageFileNames) + DownloadChapter($"{baseUrl}/{hash}/imageFileName"); } } \ No newline at end of file