diff --git a/NovelParserBLL/Parsers/Kemono/KemonoParser.cs b/NovelParserBLL/Parsers/Kemono/KemonoParser.cs index c6ab346..661a9c3 100644 --- a/NovelParserBLL/Parsers/Kemono/KemonoParser.cs +++ b/NovelParserBLL/Parsers/Kemono/KemonoParser.cs @@ -50,7 +50,7 @@ public Task LoadChapters(Novel novel, string group, string pattern, bool include chapter.Value.Content = doc.QuerySelector(".post__body")?.InnerHtml ?? ""; if (string.IsNullOrEmpty(chapter.Value.Content)) chapter.Value.Name += " "; - if (includeImages) await LoadImage(chapter.Value); + await UpdateImages(chapter.Value, includeImages); setProgress(nonLoadedChapters.Count, i++); if (cancellationToken.IsCancellationRequested) return; @@ -93,7 +93,7 @@ public async Task ParseCommonInfo(Novel novel, CancellationToken cancella return novel; } - private async Task LoadImage(Chapter chapter) + private async Task UpdateImages(Chapter chapter, bool includeImages) { var content = chapter.Content; @@ -103,36 +103,51 @@ private async Task LoadImage(Chapter chapter) foreach (var img in doc.QuerySelectorAll("img")) { - string? url = img.GetAttribute("src"); + if (includeImages) + { + string? url = img.GetAttribute("src"); - if (!string.IsNullOrEmpty(url)) + if (!string.IsNullOrEmpty(url)) + { + var image = await GetImg(kemonoUrl + img.GetAttribute("src")); + var name = Guid.NewGuid().ToString(); + chapter.Images.Add(name, image); + img.SetAttribute("src", name); + img.RemoveAttribute("data-src"); + } + } + else { - var image = await GetImg(kemonoUrl + img.GetAttribute("src")); - var name = Guid.NewGuid().ToString(); - chapter.Images.Add(name, image); - img.SetAttribute("src", name); - img.RemoveAttribute("data-src"); + img.Remove(); } } foreach (var a in doc.QuerySelectorAll(".fileThumb")) { - string? href = a.GetAttribute("href"); - - if (!string.IsNullOrEmpty(href)) + if (includeImages) { - if (href.StartsWith("/data")) + string? href = a.GetAttribute("href"); + + if (!string.IsNullOrEmpty(href)) { - href = kemonoUrl + href; + if (href.StartsWith("/data")) + { + href = kemonoUrl + href; + } + a.SetAttribute("href", href); } - a.SetAttribute("href", href); } + else + { + a.Remove(); + } + } chapter.Content = doc.Body?.InnerHtml ?? ""; } - chapter.ImagesLoaded = true; + chapter.ImagesLoaded = includeImages; } private string GetName(IDocument doc) => doc.QuerySelector(".user-header__profile")?.TextContent.Trim() ?? ""; diff --git a/NovelParserWPF/NovelParserWPF.csproj b/NovelParserWPF/NovelParserWPF.csproj index 632f946..8920a39 100644 --- a/NovelParserWPF/NovelParserWPF.csproj +++ b/NovelParserWPF/NovelParserWPF.csproj @@ -1,7 +1,7 @@  - Exe + WinExe net6.0-windows enable true @@ -10,6 +10,7 @@ Assets\book.ico true NovelParser + embedded