From f5225f9f29c63c86eb0b3faa3db7a9bc91de170f Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 18 May 2023 20:06:29 +0200 Subject: [PATCH] Moved filenaming to Chapter struct --- Tranga/Chapter.cs | 11 ++++++++--- Tranga/Connectors/MangaDex.cs | 7 ++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index a326624..c3e0331 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -1,4 +1,6 @@ -namespace Tranga; +using System.Globalization; + +namespace Tranga; public struct Chapter { @@ -10,13 +12,16 @@ public struct Chapter public string fileName { get; } - public Chapter(Publication publication, string? name, string? volumeNumber, string? chapterNumber, string url, string fileName) + public Chapter(Publication publication, string? name, string? volumeNumber, string? chapterNumber, string url) { this.publication = publication; this.name = name; this.volumeNumber = volumeNumber; this.chapterNumber = chapterNumber; this.url = url; - this.fileName = fileName; + string chapterName = string.Concat((name ?? "").Split(Path.GetInvalidFileNameChars())); + double multiplied = Convert.ToDouble(chapterName, new NumberFormatInfo() { NumberDecimalSeparator = "." }) * + Convert.ToInt32(volumeNumber); + this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {multiplied}"; } } \ No newline at end of file diff --git a/Tranga/Connectors/MangaDex.cs b/Tranga/Connectors/MangaDex.cs index b904e2d..6ffadd2 100644 --- a/Tranga/Connectors/MangaDex.cs +++ b/Tranga/Connectors/MangaDex.cs @@ -149,10 +149,7 @@ public class MangaDex : Connector ? attributes["chapter"]!.GetValue() : null; - string chapterName = string.Concat((title ?? "").Split(Path.GetInvalidFileNameChars())); - string chapterFileName = $"{chapterName} - V{volume}C{chapterNum}"; - - chapters.Add(new Chapter(publication, title, volume, chapterNum, chapterId, chapterFileName)); + chapters.Add(new Chapter(publication, title, volume, chapterNum, chapterId)); } } @@ -191,7 +188,7 @@ public class MangaDex : Connector public override void DownloadCover(Publication publication) { - DownloadClient.RequestResult requestResult = _downloadClient.MakeRequest($"https://uploads.mangadex.org/cover/{publication.posterUrl}"); + DownloadClient.RequestResult requestResult = _downloadClient.MakeRequest($"https://api.mangadex.org/cover/{publication.posterUrl}"); JsonObject? result = JsonSerializer.Deserialize(requestResult.result); if (result is null) return;