mirror of
https://github.com/CakesTwix/Smakolykytl2Epub.git
synced 2025-01-01 22:21:36 -05:00
fixed #1
This commit is contained in:
parent
146eb8dfdb
commit
4d5cfb36c4
2 changed files with 31 additions and 12 deletions
21
Program.cs
21
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)
|
||||
{
|
||||
Console.WriteLine(item.title);
|
||||
foreach (var item in book.chapters)
|
||||
{
|
||||
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");
|
||||
var fileName = string.Format("{0} - {1}.epub", project.title, book.title);
|
||||
writer.Write(fileName);
|
||||
Console.WriteLine("Файл збережено як: {0}", fileName);
|
||||
}
|
||||
}
|
|
@ -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++)
|
||||
{
|
||||
Content str = text.content[i];
|
||||
if (str != null)
|
||||
{
|
||||
if (str.type == "hardBreak") html += "<br>";
|
||||
html += str.text;
|
||||
}
|
||||
|
||||
if (str.type == "hardBreak")
|
||||
{
|
||||
html += "<br>";
|
||||
}
|
||||
if (str.type == "paragraph")
|
||||
{
|
||||
html += "<p>";
|
||||
}
|
||||
}
|
||||
html += "<br>";
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue