Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
OnlyFart committed Sep 29, 2024
1 parent bac68e2 commit 3f8c718
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
47 changes: 37 additions & 10 deletions Core/Logic/Getters/GetterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Core.Configs;
using Core.Extensions;
using Core.Types.Book;
Expand Down Expand Up @@ -137,7 +138,7 @@ private static int GetIndexByName<T>(ICollection<T> toc, Func<T, string> selecto
private static HtmlDocument SliceBook(EpubBook epubBook, EpubChapter epubChapter) {
var doc = new HtmlDocument();

var startChapter = epubBook.Resources.Html.First(h => h.AbsolutePath == epubChapter.AbsolutePath);
var startChapter = epubBook.Resources.Html.First(h => HttpUtility.UrlDecode(h.AbsolutePath) == HttpUtility.UrlDecode(epubChapter.AbsolutePath));
var startIndex = epubBook.Resources.Html.IndexOf(startChapter);

var chapter = epubBook.Resources.Html[startIndex].TextContent.AsHtmlDoc();
Expand Down Expand Up @@ -168,20 +169,46 @@ protected async Task<IEnumerable<Chapter>> FillChaptersFromEpub(TempFile shortFi

await using var stream = shortFile.GetStream();
var epubBook = EpubReader.Read(stream, true, Encoding.UTF8);
var current = epubBook.TableOfContents.First();

do {
Config.Logger.LogInformation($"Загружаю главу {current.Title.CoverQuotes()}");

if (epubBook.TableOfContents.Count > 0) {
var current = epubBook.TableOfContents.First();

do {
Config.Logger.LogInformation($"Загружаю главу {current.Title.CoverQuotes()}");

var chapter = new Chapter {
Title = current.Title
};

var content = GetContent(epubBook, current);
chapter.Images = await GetImages(content, epubBook);
chapter.Content = content.DocumentNode.RemoveNodes("h1, h2, h3").InnerHtml;
result.Add(chapter);
} while ((current = current.Next) != default);
} else {
Config.Logger.LogInformation($"Загружаю главу {epubBook.Title.CoverQuotes()}");

var sb = new StringBuilder();
foreach (var textFile in epubBook.SpecialResources.HtmlInReadingOrder) {
var textFileDoc = textFile.TextContent.AsHtmlDoc();
var body = textFileDoc.DocumentNode.QuerySelector("body");
if (body != default) {
textFileDoc = body.InnerHtml.AsHtmlDoc();
}

sb.Append(textFileDoc.DocumentNode.InnerHtml);

}

var chapter = new Chapter {
Title = current.Title
Title = epubBook.Title
};

var content = GetContent(epubBook, current);
var content = sb.AsHtmlDoc();
chapter.Images = await GetImages(content, epubBook);
chapter.Content = content.DocumentNode.RemoveNodes("h1, h2, h3").InnerHtml;
chapter.Content = content.DocumentNode.InnerHtml;
result.Add(chapter);
} while ((current = current.Next) != default);
}

return result;
}
Expand Down
11 changes: 9 additions & 2 deletions Core/Logic/Getters/LitresGetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private Uri GetFullUri(LitresArt art, string path, LitresFile file) {
}

// Аудиокнига
return new Uri($"https://mvideo.litres.ru/pages/download_book_subscr/{art.Id}/{file.Id}.mp3?sid={_authData.Sid}");
return new Uri($"https://ios.litres.ru/pages/{path}/{art.Id}/{file.Id}.mp3?sid={_authData.Sid}&uilang=ru&libapp={APP}&timestamp={ts}&md5={Convert.ToHexString(hashBytes).ToLower()}");
}

private LitresAuthResponseData _authData = new(){
Expand Down Expand Up @@ -312,13 +312,20 @@ private async Task<HttpResponseMessage> GetFileResponse(LitresArt art, LitresFil
Config.Logger.LogInformation($"Дополнительный файл доступен по ссылке {uri}");
return response;
}

uri = GetFullUri(art, "download_book_subscr", file);
response = await Config.Client.GetAsync(uri);
if (response.StatusCode == HttpStatusCode.OK && response.Headers.AcceptRanges.Any()) {
Config.Logger.LogInformation($"Дополнительный файл доступен по ссылке {uri}");
return response;
}

uri = GetFullUri(art, "download_my_book_j", file);
response = await Config.Client.GetAsync(uri);
if (response.StatusCode == HttpStatusCode.OK && response.Headers.AcceptRanges.Any()) {
Config.Logger.LogInformation($"Дополнительный файл доступен по ссылке {uri}");
return response;
}
}

return default;
Expand Down

0 comments on commit 3f8c718

Please sign in to comment.