From a3520dfd77836dd8ef449345d08cbdf3c9c73abf Mon Sep 17 00:00:00 2001 From: glax Date: Sat, 20 May 2023 00:19:04 +0200 Subject: [PATCH] Now adding ComicInfo.xml to chapterse --- Tranga/Connector.cs | 16 +++++++++++++++- Tranga/Connectors/MangaDex.cs | 5 ++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs index 6b55450..31fd505 100644 --- a/Tranga/Connector.cs +++ b/Tranga/Connector.cs @@ -1,5 +1,6 @@ using System.IO.Compression; using System.Net; +using System.Xml.Linq; namespace Tranga; @@ -66,6 +67,16 @@ public abstract class Connector if(!File.Exists(seriesInfoPath)) File.WriteAllText(seriesInfoPath,publication.GetSeriesInfo()); } + + public static string CreateComicInfo(Publication publication, Chapter chapter) + { + XElement comicInfo = new XElement("ComicInfo", + new XElement("Tags", string.Join(',',publication.tags)), + new XElement("LanguageISO", publication.originalLanguage), + new XElement("Title", chapter.name) + ); + return comicInfo.ToString(); + } /// /// Downloads Image from URL and saves it to the given path(incl. fileName) @@ -87,7 +98,7 @@ public abstract class Connector /// List of URLs to download Images from /// Full path to save archive to (without file ending .cbz) /// DownloadClient of the connector - protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient) + protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, string? comicInfoPath = null) { //Check if Publication Directory already exists string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar); @@ -111,6 +122,9 @@ public abstract class Connector DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), downloadClient); } + if(comicInfoPath is not null) + File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml")); + //ZIP-it and ship-it ZipFile.CreateFromDirectory(tempFolder, fullPath); Directory.Delete(tempFolder, true); //Cleanup diff --git a/Tranga/Connectors/MangaDex.cs b/Tranga/Connectors/MangaDex.cs index bf96163..601a223 100644 --- a/Tranga/Connectors/MangaDex.cs +++ b/Tranga/Connectors/MangaDex.cs @@ -197,8 +197,11 @@ public class MangaDex : Connector foreach (JsonNode? image in imageFileNames) imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue()}"); + string comicInfoPath = Path.GetTempFileName(); + File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter)); + //Download Chapter-Images - DownloadChapterImages(imageUrls.ToArray(), Path.Join(downloadLocation, publication.folderName, chapter.fileName), this.downloadClient); + DownloadChapterImages(imageUrls.ToArray(), Path.Join(downloadLocation, publication.folderName, chapter.fileName), this.downloadClient, comicInfoPath); } public override void DownloadCover(Publication publication)