Merge pull request #2 from MrIkso/main

fixed #1
This commit is contained in:
CakesTwix 2024-08-02 00:31:22 +03:00 committed by GitHub
commit 3e1200af18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 12 deletions

View file

@ -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);
}
}

View file

@ -18,7 +18,7 @@ public class Mark
public class TextJson
{
public string type { get; set; }
public List<Content> content { get; set; }
public List<Content?> content { get; set; }
}
public class HtmlConverter
@ -40,12 +40,22 @@ public class HtmlConverter
else if (token is JObject)
{
var text = JsonConvert.DeserializeObject<TextJson>(token.ToString());
foreach (var str in text?.content!)
for (int i = 0; i < text?.content?.Count; i++)
{
if (str.type == "hardBreak") html += "<br>";
html += str.text;
Content str = text.content[i];
if (str != null)
{
html += str.text;
}
if (str.type == "hardBreak")
{
html += "<br>";
}
if (str.type == "paragraph")
{
html += "<p>";
}
}
html += "<br>";
}
else