Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Relorer committed Sep 26, 2022
1 parent b83d20f commit f97079e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
47 changes: 31 additions & 16 deletions NovelParserBLL/Parsers/Kemono/KemonoParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 += " <Not loaded>";

if (includeImages) await LoadImage(chapter.Value);
await UpdateImages(chapter.Value, includeImages);
setProgress(nonLoadedChapters.Count, i++);

if (cancellationToken.IsCancellationRequested) return;
Expand Down Expand Up @@ -93,7 +93,7 @@ public async Task<Novel> 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;

Expand All @@ -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() ?? "";
Expand Down
3 changes: 2 additions & 1 deletion NovelParserWPF/NovelParserWPF.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
Expand All @@ -10,6 +10,7 @@
<ApplicationIcon>Assets\book.ico</ApplicationIcon>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
<AssemblyName>NovelParser</AssemblyName>
<DebugType>embedded</DebugType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down

0 comments on commit f97079e

Please sign in to comment.