mirror of
https://github.com/CakesTwix/Smakolykytl2Epub.git
synced 2025-01-01 22:21:36 -05:00
core: Implement System.CommandLine
This commit is contained in:
parent
91d1c74d78
commit
de398badab
2 changed files with 61 additions and 37 deletions
39
Program.cs
39
Program.cs
|
@ -1,17 +1,37 @@
|
||||||
using EpubSharp;
|
using EpubSharp;
|
||||||
|
using System.CommandLine;
|
||||||
using Smakolykytl2Epub.Models;
|
using Smakolykytl2Epub.Models;
|
||||||
using Smakolykytl2Epub.Utils;
|
using Smakolykytl2Epub.Utils;
|
||||||
|
|
||||||
var client = new HttpClient();
|
// CLI
|
||||||
|
var titleIDOption = new Option<int>(
|
||||||
|
aliases: ["--title", "-t"],
|
||||||
|
description: "Title ID, can be taken from the link"
|
||||||
|
) {IsRequired = true};
|
||||||
|
|
||||||
int titleId = int.Parse(args[0]);
|
var chapterIDOption = new Option<int>(
|
||||||
int chapsterId = int.Parse(args[1]) - 1;
|
aliases: ["--chapter", "-c"],
|
||||||
|
description: "Chapter ID, can be taken from the link"
|
||||||
|
) {IsRequired = true};
|
||||||
|
|
||||||
var projectTitle = await Ranobe.GetById(titleId);
|
var rootCommand = new RootCommand("A simple ranobe loader for Smakolykytl :)");
|
||||||
if (projectTitle != null)
|
rootCommand.AddOption(titleIDOption);
|
||||||
{
|
rootCommand.AddOption(chapterIDOption);
|
||||||
|
|
||||||
|
// Run main program
|
||||||
|
rootCommand.SetHandler(DownloadTitleAsync, titleIDOption, chapterIDOption);
|
||||||
|
|
||||||
|
return rootCommand.InvokeAsync(args).Result;
|
||||||
|
|
||||||
|
// Main Program
|
||||||
|
static async Task DownloadTitleAsync(int titleID, int chapterID){
|
||||||
|
var client = new HttpClient();
|
||||||
|
var projectTitle = await Ranobe.GetById(titleID);
|
||||||
|
if (projectTitle.project != null)
|
||||||
|
{
|
||||||
// Print
|
// Print
|
||||||
var project = projectTitle.project;
|
var project = projectTitle.project;
|
||||||
|
|
||||||
Console.WriteLine(project.title);
|
Console.WriteLine(project.title);
|
||||||
Console.WriteLine(project.alternatives);
|
Console.WriteLine(project.alternatives);
|
||||||
Console.WriteLine(project.description);
|
Console.WriteLine(project.description);
|
||||||
|
@ -28,8 +48,8 @@ if (projectTitle != null)
|
||||||
writer.SetCover(imageBytes, ImageFormat.Png);
|
writer.SetCover(imageBytes, ImageFormat.Png);
|
||||||
}
|
}
|
||||||
|
|
||||||
Books? books = await Ranobe.GetChaptersById(titleId);
|
Books? books = await Ranobe.GetChaptersById(titleID);
|
||||||
Book? book = books.books[chapsterId];
|
Book? book = books.books[chapterID];
|
||||||
|
|
||||||
if (book != null)
|
if (book != null)
|
||||||
{
|
{
|
||||||
|
@ -46,4 +66,7 @@ if (projectTitle != null)
|
||||||
writer.Write(fileName);
|
writer.Write(fileName);
|
||||||
Console.WriteLine("Файл збережено як: {0}", fileName);
|
Console.WriteLine("Файл збережено як: {0}", fileName);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Console.WriteLine("Нічого не знайшли :(");
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,9 +8,10 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AngleSharp" Version="1.1.2"/>
|
<PackageReference Include="AngleSharp" Version="1.1.2" />
|
||||||
<PackageReference Include="EpubSharp.dll" Version="1.1.5"/>
|
<PackageReference Include="EpubSharp.dll" Version="1.1.5" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Reference in a new issue