Moved filenaming to Chapter struct

This commit is contained in:
glax 2023-05-18 20:06:29 +02:00
parent c283cbd9a9
commit f5225f9f29
2 changed files with 10 additions and 8 deletions

View File

@ -1,4 +1,6 @@
namespace Tranga; using System.Globalization;
namespace Tranga;
public struct Chapter public struct Chapter
{ {
@ -10,13 +12,16 @@ public struct Chapter
public string fileName { get; } 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.publication = publication;
this.name = name; this.name = name;
this.volumeNumber = volumeNumber; this.volumeNumber = volumeNumber;
this.chapterNumber = chapterNumber; this.chapterNumber = chapterNumber;
this.url = url; 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}";
} }
} }

View File

@ -149,10 +149,7 @@ public class MangaDex : Connector
? attributes["chapter"]!.GetValue<string>() ? attributes["chapter"]!.GetValue<string>()
: null; : null;
string chapterName = string.Concat((title ?? "").Split(Path.GetInvalidFileNameChars())); chapters.Add(new Chapter(publication, title, volume, chapterNum, chapterId));
string chapterFileName = $"{chapterName} - V{volume}C{chapterNum}";
chapters.Add(new Chapter(publication, title, volume, chapterNum, chapterId, chapterFileName));
} }
} }
@ -191,7 +188,7 @@ public class MangaDex : Connector
public override void DownloadCover(Publication publication) 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<JsonObject>(requestResult.result); JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
if (result is null) if (result is null)
return; return;