2023-08-13 07:44:06 -04:00
|
|
|
|
using EpubSharp;
|
2024-08-02 03:29:51 -04:00
|
|
|
|
using System.CommandLine;
|
2024-08-01 17:27:02 -04:00
|
|
|
|
using Smakolykytl2Epub.Models;
|
2023-08-13 06:59:16 -04:00
|
|
|
|
using Smakolykytl2Epub.Utils;
|
|
|
|
|
|
2024-08-02 03:29:51 -04:00
|
|
|
|
// CLI
|
|
|
|
|
var titleIDOption = new Option<int>(
|
|
|
|
|
aliases: ["--title", "-t"],
|
|
|
|
|
description: "Title ID, can be taken from the link"
|
|
|
|
|
) {IsRequired = true};
|
|
|
|
|
|
|
|
|
|
var chapterIDOption = new Option<int>(
|
|
|
|
|
aliases: ["--chapter", "-c"],
|
|
|
|
|
description: "Chapter ID, can be taken from the link"
|
|
|
|
|
) {IsRequired = true};
|
2023-08-13 06:59:16 -04:00
|
|
|
|
|
2024-08-02 03:29:51 -04:00
|
|
|
|
var rootCommand = new RootCommand("A simple ranobe loader for Smakolykytl :)");
|
|
|
|
|
rootCommand.AddOption(titleIDOption);
|
|
|
|
|
rootCommand.AddOption(chapterIDOption);
|
2023-08-13 06:59:16 -04:00
|
|
|
|
|
2024-08-02 03:29:51 -04:00
|
|
|
|
// Run main program
|
|
|
|
|
rootCommand.SetHandler(DownloadTitleAsync, titleIDOption, chapterIDOption);
|
2023-08-13 06:59:16 -04:00
|
|
|
|
|
2024-08-02 03:29:51 -04:00
|
|
|
|
return rootCommand.InvokeAsync(args).Result;
|
2023-08-13 07:44:06 -04:00
|
|
|
|
|
2024-08-02 03:29:51 -04:00
|
|
|
|
// Main Program
|
|
|
|
|
static async Task DownloadTitleAsync(int titleID, int chapterID){
|
|
|
|
|
var client = new HttpClient();
|
|
|
|
|
var projectTitle = await Ranobe.GetById(titleID);
|
|
|
|
|
if (projectTitle.project != null)
|
2023-08-13 06:59:16 -04:00
|
|
|
|
{
|
2024-08-02 03:29:51 -04:00
|
|
|
|
// Print
|
|
|
|
|
var project = projectTitle.project;
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(project.title);
|
|
|
|
|
Console.WriteLine(project.alternatives);
|
|
|
|
|
Console.WriteLine(project.description);
|
2023-08-13 07:44:06 -04:00
|
|
|
|
|
2024-08-02 03:29:51 -04:00
|
|
|
|
// Basic Info
|
|
|
|
|
var writer = new EpubWriter();
|
|
|
|
|
writer.AddAuthor(project.author);
|
|
|
|
|
writer.SetTitle(project.title);
|
2024-08-01 17:27:02 -04:00
|
|
|
|
|
2024-08-02 03:29:51 -04:00
|
|
|
|
// Add Cover Image
|
|
|
|
|
using (var response = await client.GetAsync(project.image.url))
|
2023-08-13 06:59:16 -04:00
|
|
|
|
{
|
2024-08-02 03:29:51 -04:00
|
|
|
|
var imageBytes = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
|
|
|
|
|
writer.SetCover(imageBytes, ImageFormat.Png);
|
2023-08-13 06:59:16 -04:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 03:29:51 -04:00
|
|
|
|
Books? books = await Ranobe.GetChaptersById(titleID);
|
|
|
|
|
Book? book = books.books[chapterID];
|
|
|
|
|
|
|
|
|
|
if (book != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in book.chapters)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Завантаження розділу: {0}", item.title);
|
|
|
|
|
var content = (await Ranobe.GetChapterById(item.id))!.chapter.content;
|
2024-08-02 05:59:26 -04:00
|
|
|
|
|
|
|
|
|
writer.AddChapter(item.title, HtmlConverter.ConvertJsonToHtml(content, writer));
|
2024-08-02 03:29:51 -04:00
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Done
|
|
|
|
|
var fileName = string.Format("{0} - {1}.epub", project.title, book.title);
|
|
|
|
|
Console.WriteLine("Файл збережено як: {0}", fileName);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Console.WriteLine("Нічого не знайшли :(");
|
2024-08-01 17:27:02 -04:00
|
|
|
|
}
|
2024-08-02 03:29:51 -04:00
|
|
|
|
}
|