Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into feat/#31-2
Browse files Browse the repository at this point in the history
  • Loading branch information
aiueo-1234 committed Feb 24, 2024
2 parents 2adf310 + c0e9d24 commit 1532925
Showing 1 changed file with 1 addition and 45 deletions.
46 changes: 1 addition & 45 deletions Epub/KoeBook.Epub/ScrapingAozora.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public async Task<EpubDocument> ScrapingAsync(string url, string coverFilePath,
checkSection(document, chapterNum);
document.Chapters[chapterNum].Sections[sectionNum].Elements.Add(new Paragraph());
}

}
else if (element.TagName == "DIV")
{
Expand Down Expand Up @@ -180,7 +179,6 @@ public async Task<EpubDocument> ScrapingAsync(string url, string coverFilePath,
}
document.Chapters[chapterNum].Sections[sectionNum].Elements.Add(new Paragraph());
}

}
}
}
Expand Down Expand Up @@ -251,7 +249,6 @@ public async Task<EpubDocument> ScrapingAsync(string url, string coverFilePath,
}
}
}

}
else if (element.TagName == "IMG")
{
Expand Down Expand Up @@ -333,7 +330,6 @@ public async Task<EpubDocument> ScrapingAsync(string url, string coverFilePath,
paragraph.Text = TextProcess(element) + "の画像";
}
}

}
else if (element.ClassName == "notes")
{
Expand Down Expand Up @@ -490,7 +486,6 @@ public async Task<EpubDocument> ScrapingAsync(string url, string coverFilePath,
paragraph2.Text += split[^1];
}
}

}
else
{
Expand All @@ -504,48 +499,12 @@ public async Task<EpubDocument> ScrapingAsync(string url, string coverFilePath,
}
}

// 末尾の空のparagraphを削除
document.Chapters[^1].Sections[^1].Elements.RemoveAt(document.Chapters[^1].Sections[^1].Elements.Count - 1);

if (checkEpubDocument(document))
{
Console.WriteLine("Success");
}
else
{
Console.WriteLine("False");
}
return document;
}

private bool checkEpubDocument(EpubDocument document)
{
foreach (var chapter in document.Chapters)
{
foreach (var section in chapter.Sections)
{
foreach (var element in section.Elements)
{
if (element is Paragraph paragraph)
{
if (paragraph.Text == null)
{
Console.WriteLine($"{document.Chapters.IndexOf(chapter)}, {chapter.Sections.IndexOf(section)}, {section.Elements.IndexOf(element)}");
return false;
}
}
else if (element is Picture picture)
{
if (picture.PictureFilePath == null)
{
Console.WriteLine($"{document.Chapters.IndexOf(chapter)}, {chapter.Sections.IndexOf(section)}, {section.Elements.IndexOf(element)}");
return false;
}
}
}
}
}
return true;
}

private static string TextProcess(IElement element)
{
Expand Down Expand Up @@ -655,8 +614,5 @@ private static string GetCardUrl(string url)

[System.Text.RegularExpressions.GeneratedRegex(@"http.{1,}/([^/]{0,}\.[^/]{1,})")]
private static partial System.Text.RegularExpressions.Regex FileUrlToFileName();

[System.Text.RegularExpressions.GeneratedRegex(@"<ruby><rb>(.{1,})</rb><rp>(</rp><rt>(.{1,})</rt><rp>)</rp></ruby>")]
private static partial System.Text.RegularExpressions.Regex RubyToText();
}
}

0 comments on commit 1532925

Please sign in to comment.