Smakolykytl2Epub/Program.cs

49 lines
1.5 KiB
C#
Raw Normal View History

2023-08-13 07:44:06 -04:00
using EpubSharp;
2024-08-01 17:27:02 -04:00
using Smakolykytl2Epub.Models;
2023-08-13 06:59:16 -04:00
using Smakolykytl2Epub.Utils;
var client = new HttpClient();
2024-08-01 17:27:02 -04:00
int titleId = int.Parse(args[0]);
int chapsterId = int.Parse(args[1]) - 1;
2023-08-13 06:59:16 -04:00
2024-08-01 17:27:02 -04:00
var projectTitle = await Ranobe.GetById(titleId);
2023-08-13 06:59:16 -04:00
if (projectTitle != null)
{
// Print
2023-08-13 07:44:06 -04:00
var project = projectTitle.project;
2023-08-13 06:59:16 -04:00
Console.WriteLine(project.title);
Console.WriteLine(project.alternatives);
Console.WriteLine(project.description);
// Basic Info
2023-08-13 07:44:06 -04:00
var writer = new EpubWriter();
2023-08-13 06:59:16 -04:00
writer.AddAuthor(project.author);
writer.SetTitle(project.title);
2023-08-13 07:44:06 -04:00
2023-08-13 06:59:16 -04:00
// Add Cover Image
using (var response = await client.GetAsync(project.image.url))
{
2023-08-13 07:44:06 -04:00
var imageBytes = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
2023-08-13 06:59:16 -04:00
writer.SetCover(imageBytes, ImageFormat.Png);
}
2023-08-13 07:44:06 -04:00
2024-08-01 17:27:02 -04:00
Books? books = await Ranobe.GetChaptersById(titleId);
Book? book = books.books[chapsterId];
if (book != null)
{
foreach (var item in book.chapters)
2023-08-13 06:59:16 -04:00
{
2024-08-01 17:27:02 -04:00
Console.WriteLine("Завантаження розділу: {0}", item.title);
2023-08-13 07:44:06 -04:00
var content = (await Ranobe.GetChapterById(item.id))!.chapter.content;
2023-08-13 06:59:16 -04:00
writer.AddChapter(item.title, HtmlConverter.ConvertJsonToHtml(content));
Thread.Sleep(1000);
}
2024-08-01 17:27:02 -04:00
// Done
var fileName = string.Format("{0} - {1}.epub", project.title, book.title);
writer.Write(fileName);
Console.WriteLine("Файл збережено як: {0}", fileName);
}
2023-08-13 06:59:16 -04:00
}