Skip to content

Commit

Permalink
https://github.com/OnlyFart/Elib2Ebook/issues/120
Browse files Browse the repository at this point in the history
  • Loading branch information
OnlyFart committed Oct 16, 2024
1 parent 0faa6e4 commit acdbdf9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latestmajor</LangVersion>
<PackageId>Core</PackageId>
<Version>2.4.0</Version>
<Version>2.4.1</Version>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>

Expand Down
23 changes: 13 additions & 10 deletions Core/Logic/Getters/LitsovetGetter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
Expand Down Expand Up @@ -49,7 +50,7 @@ public override async Task<Book> Get(Uri url) {

var book = new Book(url) {
Cover = await GetCover(doc, url),
Chapters = await FillChapters(doc, url),
Chapters = await FillChapters(url),
Title = doc.GetTextBySelector("h1"),
Author = GetAuthor(doc),
Annotation = doc.QuerySelector("div.book-informate div.item-descr")?.InnerHtml
Expand All @@ -60,28 +61,30 @@ public override async Task<Book> Get(Uri url) {

private Author GetAuthor(HtmlDocument doc) {
var a = doc.QuerySelector("div.p-book-author a");
return new Author(a.GetText(), SystemUrl.MakeRelativeUri(a.Attributes["href"].Value));
return new Author(a.QuerySelector("span").GetText(), SystemUrl.MakeRelativeUri(a.Attributes["href"].Value));
}

private IEnumerable<UrlChapter> GetToc(HtmlDocument doc, Uri url) {
private async Task<IEnumerable<UrlChapter>> GetToc(Uri url) {
var doc = await Config.Client.GetHtmlDocWithTriesAsync(url.AppendSegment("/read/"));

var result = new List<UrlChapter>();
foreach (var block in doc.QuerySelectorAll("div.card-glava div.item-center")) {
var a = block.QuerySelector("a");
result.Add(a == default
? new UrlChapter(null, block.GetTextBySelector("div.item-name span"))
: new UrlChapter(url.MakeRelativeUri(a.Attributes["href"].Value), a.GetText().ReplaceNewLine()));
foreach (var a in doc.QuerySelectorAll("div.book-navi-list li a")) {
var href = a.Attributes["onclick"]?.Value?.Split(" ").FirstOrDefault(s => s.Contains("books"))?.Trim('\'');
result.Add(string.IsNullOrEmpty(href)
? new UrlChapter(null, a.GetText().ReplaceNewLine())
: new UrlChapter(url.MakeRelativeUri(href), a.GetText().ReplaceNewLine()));
}

return SliceToc(result, c => c.Title);
}

private async Task<IEnumerable<Chapter>> FillChapters(HtmlDocument doc, Uri url) {
private async Task<IEnumerable<Chapter>> FillChapters(Uri url) {
var result = new List<Chapter>();
if (Config.Options.NoChapters) {
return result;
}

foreach (var urlChapter in GetToc(doc, url)) {
foreach (var urlChapter in await GetToc(url)) {
Config.Logger.LogInformation($"Загружаю главу {urlChapter.Title.CoverQuotes()}");
var chapter = new Chapter {
Title = urlChapter.Title
Expand Down

0 comments on commit acdbdf9

Please sign in to comment.