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)