From 4d5cfb36c4365c1827bbd00818f1cccfa1521413 Mon Sep 17 00:00:00 2001 From: MrIkso Date: Fri, 2 Aug 2024 00:27:02 +0300 Subject: [PATCH] fixed #1 --- Program.cs | 23 ++++++++++++++++------- Utils/Json2HTML.cs | 20 +++++++++++++++----- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Program.cs b/Program.cs index 2ae668d..3a1e8b5 100644 --- a/Program.cs +++ b/Program.cs @@ -1,10 +1,13 @@ using EpubSharp; +using Smakolykytl2Epub.Models; using Smakolykytl2Epub.Utils; var client = new HttpClient(); +int titleId = int.Parse(args[0]); +int chapsterId = int.Parse(args[1]) - 1; -var projectTitle = await Ranobe.GetById(int.Parse(args[0])); +var projectTitle = await Ranobe.GetById(titleId); if (projectTitle != null) { // Print @@ -25,16 +28,22 @@ if (projectTitle != null) writer.SetCover(imageBytes, ImageFormat.Png); } - var books = (await Ranobe.GetChaptersById(int.Parse(args[0])))?.books[int.Parse(args[1]) - 1]; - if (books != null) - foreach (var item in books.chapters) + Books? books = await Ranobe.GetChaptersById(titleId); + Book? book = books.books[chapsterId]; + + if (book != null) + { + foreach (var item in book.chapters) { - Console.WriteLine(item.title); + Console.WriteLine("Завантаження розділу: {0}", item.title); var content = (await Ranobe.GetChapterById(item.id))!.chapter.content; writer.AddChapter(item.title, HtmlConverter.ConvertJsonToHtml(content)); Thread.Sleep(1000); } - // Done - writer.Write("new.epub"); + // Done + var fileName = string.Format("{0} - {1}.epub", project.title, book.title); + writer.Write(fileName); + Console.WriteLine("Файл збережено як: {0}", fileName); + } } \ No newline at end of file diff --git a/Utils/Json2HTML.cs b/Utils/Json2HTML.cs index 21261b4..5d1743d 100644 --- a/Utils/Json2HTML.cs +++ b/Utils/Json2HTML.cs @@ -18,7 +18,7 @@ public class Mark public class TextJson { public string type { get; set; } - public List content { get; set; } + public List content { get; set; } } public class HtmlConverter @@ -40,12 +40,22 @@ public class HtmlConverter else if (token is JObject) { var text = JsonConvert.DeserializeObject(token.ToString()); - foreach (var str in text?.content!) + for (int i = 0; i < text?.content?.Count; i++) { - if (str.type == "hardBreak") html += "
"; - html += str.text; + Content str = text.content[i]; + if (str != null) + { + html += str.text; + } + if (str.type == "hardBreak") + { + html += "
"; + } + if (str.type == "paragraph") + { + html += "

"; + } } - html += "
"; } else