From 67e01a1254655c0e9e5618552f3172fe41eb161d Mon Sep 17 00:00:00 2001 From: aiueo-1234 <130837816+aiueo-1234@users.noreply.github.com> Date: Fri, 15 Mar 2024 17:24:35 +0900 Subject: [PATCH 1/7] =?UTF-8?q?#17-1=20Core=E3=81=AE=E3=83=97=E3=83=AD?= =?UTF-8?q?=E3=82=B8=E3=82=A7=E3=82=AF=E3=83=88=E3=82=92Epub=E3=82=BD?= =?UTF-8?q?=E3=83=AA=E3=83=A5=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=AB?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Epub/KoeBook.Epub.sln | 51 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/Epub/KoeBook.Epub.sln b/Epub/KoeBook.Epub.sln index dc90218..732b485 100644 --- a/Epub/KoeBook.Epub.sln +++ b/Epub/KoeBook.Epub.sln @@ -1,4 +1,5 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 + +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.10.34607.79 MinimumVisualStudioVersion = 10.0.40219.1 @@ -6,20 +7,68 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KoeBook.Epub", "KoeBook.Epu EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EpubConsoleApp", "EpubConsoleApp\EpubConsoleApp.csproj", "{DE1F3CE9-4F3B-4428-9293-D18446F333D8}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KoeBook.Core", "..\KoeBook.Core\KoeBook.Core.csproj", "{9F11B1EF-8330-400E-A60C-CFC98E827AA7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|arm64 = Debug|arm64 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|arm64 = Release|arm64 + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Debug|arm64.ActiveCfg = Debug|Any CPU + {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Debug|arm64.Build.0 = Debug|Any CPU + {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Debug|x64.ActiveCfg = Debug|Any CPU + {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Debug|x64.Build.0 = Debug|Any CPU + {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Debug|x86.ActiveCfg = Debug|Any CPU + {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Debug|x86.Build.0 = Debug|Any CPU {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Release|Any CPU.ActiveCfg = Release|Any CPU {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Release|Any CPU.Build.0 = Release|Any CPU + {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Release|arm64.ActiveCfg = Release|Any CPU + {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Release|arm64.Build.0 = Release|Any CPU + {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Release|x64.ActiveCfg = Release|Any CPU + {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Release|x64.Build.0 = Release|Any CPU + {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Release|x86.ActiveCfg = Release|Any CPU + {E8E224F2-D1E9-437E-8222-FF2F33DB3FCD}.Release|x86.Build.0 = Release|Any CPU {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Debug|arm64.ActiveCfg = Debug|Any CPU + {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Debug|arm64.Build.0 = Debug|Any CPU + {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Debug|x64.ActiveCfg = Debug|Any CPU + {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Debug|x64.Build.0 = Debug|Any CPU + {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Debug|x86.ActiveCfg = Debug|Any CPU + {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Debug|x86.Build.0 = Debug|Any CPU {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Release|Any CPU.ActiveCfg = Release|Any CPU {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Release|Any CPU.Build.0 = Release|Any CPU + {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Release|arm64.ActiveCfg = Release|Any CPU + {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Release|arm64.Build.0 = Release|Any CPU + {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Release|x64.ActiveCfg = Release|Any CPU + {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Release|x64.Build.0 = Release|Any CPU + {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Release|x86.ActiveCfg = Release|Any CPU + {DE1F3CE9-4F3B-4428-9293-D18446F333D8}.Release|x86.Build.0 = Release|Any CPU + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Debug|arm64.ActiveCfg = Debug|arm64 + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Debug|arm64.Build.0 = Debug|arm64 + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Debug|x64.ActiveCfg = Debug|x64 + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Debug|x64.Build.0 = Debug|x64 + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Debug|x86.ActiveCfg = Debug|x86 + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Debug|x86.Build.0 = Debug|x86 + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Release|Any CPU.Build.0 = Release|Any CPU + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Release|arm64.ActiveCfg = Release|arm64 + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Release|arm64.Build.0 = Release|arm64 + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Release|x64.ActiveCfg = Release|x64 + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Release|x64.Build.0 = Release|x64 + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Release|x86.ActiveCfg = Release|x86 + {9F11B1EF-8330-400E-A60C-CFC98E827AA7}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From bca75d9e465cc3713143cbc3ba846f184d6fa306 Mon Sep 17 00:00:00 2001 From: aiueo-1234 <130837816+aiueo-1234@users.noreply.github.com> Date: Fri, 15 Mar 2024 18:55:37 +0900 Subject: [PATCH 2/7] =?UTF-8?q?#17-1=20Epub=E4=BD=9C=E6=88=90=E9=83=A8?= =?UTF-8?q?=E5=88=86=E3=81=AEException=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Epub/KoeBook.Epub/Services/EpubGenerateService.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Epub/KoeBook.Epub/Services/EpubGenerateService.cs b/Epub/KoeBook.Epub/Services/EpubGenerateService.cs index 058795d..513b89e 100644 --- a/Epub/KoeBook.Epub/Services/EpubGenerateService.cs +++ b/Epub/KoeBook.Epub/Services/EpubGenerateService.cs @@ -9,10 +9,10 @@ namespace KoeBook.Epub.Services; public class EpubGenerateService(ISoundGenerationService soundGenerationService, IEpubDocumentStoreService epubDocumentStoreService, IEpubCreateService epubCreateService) : IEpubGenerateService { - private ISoundGenerationService _soundGenerationService = soundGenerationService; - private IEpubDocumentStoreService _documentStoreService = epubDocumentStoreService; - private IEpubCreateService _createService = epubCreateService; - + private readonly ISoundGenerationService _soundGenerationService = soundGenerationService; + private readonly IEpubDocumentStoreService _documentStoreService = epubDocumentStoreService; + private readonly IEpubCreateService _createService = epubCreateService; + public async ValueTask GenerateEpubAsync(BookScripts bookScripts, string tempDirectory, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -32,7 +32,8 @@ public async ValueTask GenerateEpubAsync(BookScripts bookScripts, string } else { - throw new EbookException(ExceptionType.EpubCreateError); + EbookException.Throw(ExceptionType.EpubCreateError); + return ""; } } } From 8f2900eeb357170de49ef02ef020171700adab21 Mon Sep 17 00:00:00 2001 From: aiueo-1234 <130837816+aiueo-1234@users.noreply.github.com> Date: Fri, 15 Mar 2024 18:56:50 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Epub/KoeBook.Epub/Services/EpubGenerateService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Epub/KoeBook.Epub/Services/EpubGenerateService.cs b/Epub/KoeBook.Epub/Services/EpubGenerateService.cs index 513b89e..c43dc74 100644 --- a/Epub/KoeBook.Epub/Services/EpubGenerateService.cs +++ b/Epub/KoeBook.Epub/Services/EpubGenerateService.cs @@ -12,7 +12,7 @@ public class EpubGenerateService(ISoundGenerationService soundGenerationService, private readonly ISoundGenerationService _soundGenerationService = soundGenerationService; private readonly IEpubDocumentStoreService _documentStoreService = epubDocumentStoreService; private readonly IEpubCreateService _createService = epubCreateService; - + public async ValueTask GenerateEpubAsync(BookScripts bookScripts, string tempDirectory, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); From fa3f28ce4097fcdfa32ee427117799b0219823ed Mon Sep 17 00:00:00 2001 From: aiueo-1234 <130837816+aiueo-1234@users.noreply.github.com> Date: Fri, 15 Mar 2024 22:05:10 +0900 Subject: [PATCH 4/7] =?UTF-8?q?#17-1=20DI=E8=BF=BD=E5=8A=A0&throw=20except?= =?UTF-8?q?ion=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Epub/KoeBook.Epub/Services/EpubGenerateService.cs | 3 +-- KoeBook/App.xaml.cs | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Epub/KoeBook.Epub/Services/EpubGenerateService.cs b/Epub/KoeBook.Epub/Services/EpubGenerateService.cs index c43dc74..1543f30 100644 --- a/Epub/KoeBook.Epub/Services/EpubGenerateService.cs +++ b/Epub/KoeBook.Epub/Services/EpubGenerateService.cs @@ -32,8 +32,7 @@ public async ValueTask GenerateEpubAsync(BookScripts bookScripts, string } else { - EbookException.Throw(ExceptionType.EpubCreateError); - return ""; + throw new EbookException(ExceptionType.EpubCreateError); } } } diff --git a/KoeBook/App.xaml.cs b/KoeBook/App.xaml.cs index 3b1e62f..0ed636f 100644 --- a/KoeBook/App.xaml.cs +++ b/KoeBook/App.xaml.cs @@ -103,6 +103,7 @@ public App() .AddSingleton() .AddSingleton(); services.AddSingleton(); + services.AddSingleton(); // Views and ViewModels services.AddTransient(); From 29394aadad0ec26a0820d821ec85afef5445e93e Mon Sep 17 00:00:00 2001 From: aiueo-1234 <130837816+aiueo-1234@users.noreply.github.com> Date: Fri, 15 Mar 2024 23:34:21 +0900 Subject: [PATCH 5/7] =?UTF-8?q?#17-1=20EpubDocumentException=E3=81=AE?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Epub/KoeBook.Epub/EpubDocumentException.cs | 13 --------- .../Services/ScrapingAozoraService.cs | 9 ++++--- .../Services/ScrapingNaroService.cs | 27 ++++++++++--------- 3 files changed, 19 insertions(+), 30 deletions(-) delete mode 100644 Epub/KoeBook.Epub/EpubDocumentException.cs diff --git a/Epub/KoeBook.Epub/EpubDocumentException.cs b/Epub/KoeBook.Epub/EpubDocumentException.cs deleted file mode 100644 index d83bb62..0000000 --- a/Epub/KoeBook.Epub/EpubDocumentException.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace KoeBook.Epub -{ - public class EpubDocumentException : Exception - { - public EpubDocumentException(string? message) : base(message) { } - } -} diff --git a/Epub/KoeBook.Epub/Services/ScrapingAozoraService.cs b/Epub/KoeBook.Epub/Services/ScrapingAozoraService.cs index 203bcaa..e1ad47f 100644 --- a/Epub/KoeBook.Epub/Services/ScrapingAozoraService.cs +++ b/Epub/KoeBook.Epub/Services/ScrapingAozoraService.cs @@ -2,6 +2,7 @@ using AngleSharp.Dom; using AngleSharp.Html.Dom; using AngleSharp.Io; +using KoeBook.Core; using KoeBook.Epub.Contracts.Services; using KoeBook.Epub.Models; using static KoeBook.Epub.Utility.ScrapingHelper; @@ -29,11 +30,11 @@ public async ValueTask ScrapingAsync(string url, string coverFileP // title の取得 var bookTitle = doc.QuerySelector(".title") - ?? throw new EpubDocumentException($"Failed to get title properly.\nYou may be able to get proper URL at {GetCardUrl(url)}"); + ?? throw new EbookException(ExceptionType.WebScrapingFailed, $"Failed to get title properly.\nYou may be able to get proper URL at {GetCardUrl(url)}"); // auther の取得 var bookAuther = doc.QuerySelector(".author") - ?? throw new EpubDocumentException($"Failed to get auther properly.\nYou may be able to get proper URL at {GetCardUrl(url)}"); + ?? throw new EbookException(ExceptionType.WebScrapingFailed, $"Failed to get auther properly.\nYou may be able to get proper URL at {GetCardUrl(url)}"); // EpubDocument の生成 var document = new EpubDocument(TextReplace(bookTitle.InnerHtml), TextReplace(bookAuther.InnerHtml), coverFilePath, id) @@ -111,10 +112,10 @@ public async ValueTask ScrapingAsync(string url, string coverFileP if (midashi != null) { if (midashi.Id == null) - throw new EpubDocumentException("Unecpected structure of HTML File: div tag with class=\"midashi_anchor\", but id=\"midashi___\" exist"); + throw new EbookException(ExceptionType.WebScrapingFailed, "Unecpected structure of HTML File: div tag with class=\"midashi_anchor\", but id=\"midashi___\" exist"); if (!int.TryParse(midashi.Id.Replace("midashi", ""), out var midashiId)) - throw new EpubDocumentException($"Unexpected id of Anchor tag was found: id = {midashi.Id}"); + throw new EbookException(ExceptionType.WebScrapingFailed, $"Unexpected id of Anchor tag was found: id = {midashi.Id}"); if (contentsIds.Contains(midashiId)) { diff --git a/Epub/KoeBook.Epub/Services/ScrapingNaroService.cs b/Epub/KoeBook.Epub/Services/ScrapingNaroService.cs index 576c422..9c63cf3 100644 --- a/Epub/KoeBook.Epub/Services/ScrapingNaroService.cs +++ b/Epub/KoeBook.Epub/Services/ScrapingNaroService.cs @@ -3,6 +3,7 @@ using AngleSharp.Dom; using AngleSharp.Html.Dom; using AngleSharp.Io; +using KoeBook.Core; using KoeBook.Epub.Contracts.Services; using KoeBook.Epub.Models; using static KoeBook.Epub.Utility.ScrapingHelper; @@ -26,12 +27,12 @@ public async ValueTask ScrapingAsync(string url, string coverFileP // title の取得 var bookTitleElement = doc.QuerySelector(".novel_title") - ?? throw new EpubDocumentException($"Failed to get title properly.\nUrl may be not collect"); + ?? throw new EbookException(ExceptionType.WebScrapingFailed, $"Failed to get title properly.\nUrl may be not collect"); var bookTitle = bookTitleElement.InnerHtml; // auther の取得 var bookAutherElement = doc.QuerySelector(".novel_writername") - ?? throw new EpubDocumentException($"Failed to get auther properly.\nUrl may be not collect"); + ?? throw new EbookException(ExceptionType.WebScrapingFailed, $"Failed to get auther properly.\nUrl may be not collect"); var bookAuther = string.Empty; if (bookAutherElement.QuerySelector("a") is IHtmlAnchorElement bookAutherAnchorElement) { @@ -54,13 +55,13 @@ public async ValueTask ScrapingAsync(string url, string coverFileP var result = await client.SendAsync(message, ct).ConfigureAwait(false); var test = await result.Content.ReadAsStringAsync(ct).ConfigureAwait(false); if (!result.IsSuccessStatusCode) - throw new EpubDocumentException("Url may be not Correct"); + throw new EbookException(ExceptionType.WebScrapingFailed, "Url may be not Correct"); var content = await result.Content.ReadFromJsonAsync(ct).ConfigureAwait(false); if (content != null) { if (content[1].noveltype == null) - throw new EpubDocumentException("faild to get data by Narou API"); + throw new EbookException(ExceptionType.WebScrapingFailed, "faild to get data by Narou API"); if (content[1].noveltype == 2) { @@ -73,7 +74,7 @@ public async ValueTask ScrapingAsync(string url, string coverFileP } if (allNum == 0) - throw new EpubDocumentException("faild to get data by Narou API"); + throw new EbookException(ExceptionType.WebScrapingFailed, "faild to get data by Narou API"); } var document = new EpubDocument(bookTitle, bookAuther, coverFilePath, id); @@ -91,7 +92,7 @@ public async ValueTask ScrapingAsync(string url, string coverFileP foreach (var sectionWithChapterTitle in SectionWithChapterTitleList) { if (sectionWithChapterTitle == null) - throw new EpubDocumentException("failed to get page"); + throw new EbookException(ExceptionType.WebScrapingFailed, "failed to get page"); if (sectionWithChapterTitle.title != null) { @@ -162,7 +163,7 @@ private static async Task ReadPageAsync(string url, boo } if (sectionTitleElement == null) - throw new EpubDocumentException("Can not find title of page"); + throw new EbookException(ExceptionType.WebScrapingFailed, "Can not find title of page"); var sectionTitle = sectionTitleElement.InnerHtml; @@ -170,12 +171,12 @@ private static async Task ReadPageAsync(string url, boo var main_text = doc.QuerySelector("#novel_honbun") - ?? throw new EpubDocumentException("There is no honbun."); + ?? throw new EbookException(ExceptionType.WebScrapingFailed, "There is no honbun."); foreach (var item in main_text.Children) { if (item is not IHtmlParagraphElement) - throw new EpubDocumentException("Unexpected structure"); + throw new EbookException(ExceptionType.WebScrapingFailed, "Unexpected structure"); if (item.ChildElementCount == 0) { @@ -192,12 +193,12 @@ private static async Task ReadPageAsync(string url, boo if (item.Children[0] is IHtmlAnchorElement aElement) { if (aElement.ChildElementCount != 1) - throw new EpubDocumentException("Unexpected structure"); + throw new EbookException(ExceptionType.WebScrapingFailed, "Unexpected structure"); if (aElement.Children[0] is IHtmlImageElement img) { if (img.Source == null) - throw new EpubDocumentException("Unexpected structure"); + throw new EbookException(ExceptionType.WebScrapingFailed, "Unexpected structure"); // 画像のダウンロード var loader = context.GetService(); @@ -225,7 +226,7 @@ private static async Task ReadPageAsync(string url, boo } } else if (item.Children[0] is not IHtmlBreakRowElement) - throw new EpubDocumentException("Unexpected structure"); + throw new EbookException(ExceptionType.WebScrapingFailed, "Unexpected structure"); } else { @@ -240,7 +241,7 @@ private static async Task ReadPageAsync(string url, boo } if (!isAllRuby) - throw new EpubDocumentException("Unexpected structure"); + throw new EbookException(ExceptionType.WebScrapingFailed, "Unexpected structure"); if (!string.IsNullOrWhiteSpace(item.InnerHtml)) { From 7ff9bd36efd4a1af2e4f3658bf129b7227bdb220 Mon Sep 17 00:00:00 2001 From: aiueo-1234 <130837816+aiueo-1234@users.noreply.github.com> Date: Fri, 15 Mar 2024 23:54:49 +0900 Subject: [PATCH 6/7] =?UTF-8?q?#17-1=20=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=81=AE=E6=97=A5?= =?UTF-8?q?=E6=9C=AC=E8=AA=9E=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/ScrapingAozoraService.cs | 8 +++--- .../Services/ScrapingNaroService.cs | 26 +++++++++---------- KoeBook.Core/EbookException.cs | 8 +++++- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Epub/KoeBook.Epub/Services/ScrapingAozoraService.cs b/Epub/KoeBook.Epub/Services/ScrapingAozoraService.cs index e1ad47f..3516dd9 100644 --- a/Epub/KoeBook.Epub/Services/ScrapingAozoraService.cs +++ b/Epub/KoeBook.Epub/Services/ScrapingAozoraService.cs @@ -30,11 +30,11 @@ public async ValueTask ScrapingAsync(string url, string coverFileP // title の取得 var bookTitle = doc.QuerySelector(".title") - ?? throw new EbookException(ExceptionType.WebScrapingFailed, $"Failed to get title properly.\nYou may be able to get proper URL at {GetCardUrl(url)}"); + ?? throw new EbookException(ExceptionType.WebScrapingFailed, $"タイトルの取得に失敗しました。\n以下のリンクから正しい小説のリンクを取得してください。\n{GetCardUrl(url)}"); // auther の取得 var bookAuther = doc.QuerySelector(".author") - ?? throw new EbookException(ExceptionType.WebScrapingFailed, $"Failed to get auther properly.\nYou may be able to get proper URL at {GetCardUrl(url)}"); + ?? throw new EbookException(ExceptionType.WebScrapingFailed, $"著者の取得に失敗しました。\n以下のリンクから正しい小説のリンクを取得してください。\n{GetCardUrl(url)}"); // EpubDocument の生成 var document = new EpubDocument(TextReplace(bookTitle.InnerHtml), TextReplace(bookAuther.InnerHtml), coverFilePath, id) @@ -112,10 +112,10 @@ public async ValueTask ScrapingAsync(string url, string coverFileP if (midashi != null) { if (midashi.Id == null) - throw new EbookException(ExceptionType.WebScrapingFailed, "Unecpected structure of HTML File: div tag with class=\"midashi_anchor\", but id=\"midashi___\" exist"); + throw new EbookException(ExceptionType.WebScrapingFailed, "予期しないHTMLの構造です。\nclass=\"midashi_anchor\"ではなくid=\"midashi___\"が存在します。"); if (!int.TryParse(midashi.Id.Replace("midashi", ""), out var midashiId)) - throw new EbookException(ExceptionType.WebScrapingFailed, $"Unexpected id of Anchor tag was found: id = {midashi.Id}"); + throw new EbookException(ExceptionType.WebScrapingFailed, $"予期しないアンカータグが見つかりました。id = {midashi.Id}"); if (contentsIds.Contains(midashiId)) { diff --git a/Epub/KoeBook.Epub/Services/ScrapingNaroService.cs b/Epub/KoeBook.Epub/Services/ScrapingNaroService.cs index 9c63cf3..a7dc353 100644 --- a/Epub/KoeBook.Epub/Services/ScrapingNaroService.cs +++ b/Epub/KoeBook.Epub/Services/ScrapingNaroService.cs @@ -27,12 +27,12 @@ public async ValueTask ScrapingAsync(string url, string coverFileP // title の取得 var bookTitleElement = doc.QuerySelector(".novel_title") - ?? throw new EbookException(ExceptionType.WebScrapingFailed, $"Failed to get title properly.\nUrl may be not collect"); + ?? throw new EbookException(ExceptionType.WebScrapingFailed, $"タイトルを取得できませんでした"); var bookTitle = bookTitleElement.InnerHtml; // auther の取得 var bookAutherElement = doc.QuerySelector(".novel_writername") - ?? throw new EbookException(ExceptionType.WebScrapingFailed, $"Failed to get auther properly.\nUrl may be not collect"); + ?? throw new EbookException(ExceptionType.WebScrapingFailed, $"著者を取得できませんでした"); var bookAuther = string.Empty; if (bookAutherElement.QuerySelector("a") is IHtmlAnchorElement bookAutherAnchorElement) { @@ -55,13 +55,13 @@ public async ValueTask ScrapingAsync(string url, string coverFileP var result = await client.SendAsync(message, ct).ConfigureAwait(false); var test = await result.Content.ReadAsStringAsync(ct).ConfigureAwait(false); if (!result.IsSuccessStatusCode) - throw new EbookException(ExceptionType.WebScrapingFailed, "Url may be not Correct"); + throw new EbookException(ExceptionType.WebScrapingFailed, "URLが正しくありません"); var content = await result.Content.ReadFromJsonAsync(ct).ConfigureAwait(false); if (content != null) { if (content[1].noveltype == null) - throw new EbookException(ExceptionType.WebScrapingFailed, "faild to get data by Narou API"); + throw new EbookException(ExceptionType.NarouApiFailed); if (content[1].noveltype == 2) { @@ -74,7 +74,7 @@ public async ValueTask ScrapingAsync(string url, string coverFileP } if (allNum == 0) - throw new EbookException(ExceptionType.WebScrapingFailed, "faild to get data by Narou API"); + throw new EbookException(ExceptionType.NarouApiFailed); } var document = new EpubDocument(bookTitle, bookAuther, coverFilePath, id); @@ -92,7 +92,7 @@ public async ValueTask ScrapingAsync(string url, string coverFileP foreach (var sectionWithChapterTitle in SectionWithChapterTitleList) { if (sectionWithChapterTitle == null) - throw new EbookException(ExceptionType.WebScrapingFailed, "failed to get page"); + throw new EbookException(ExceptionType.WebScrapingFailed, "ページの取得に失敗しました"); if (sectionWithChapterTitle.title != null) { @@ -163,7 +163,7 @@ private static async Task ReadPageAsync(string url, boo } if (sectionTitleElement == null) - throw new EbookException(ExceptionType.WebScrapingFailed, "Can not find title of page"); + throw new EbookException(ExceptionType.WebScrapingFailed, "ページのタイトルが見つかりません"); var sectionTitle = sectionTitleElement.InnerHtml; @@ -171,12 +171,12 @@ private static async Task ReadPageAsync(string url, boo var main_text = doc.QuerySelector("#novel_honbun") - ?? throw new EbookException(ExceptionType.WebScrapingFailed, "There is no honbun."); + ?? throw new EbookException(ExceptionType.WebScrapingFailed, "本文がありません"); foreach (var item in main_text.Children) { if (item is not IHtmlParagraphElement) - throw new EbookException(ExceptionType.WebScrapingFailed, "Unexpected structure"); + throw new EbookException(ExceptionType.UnexpectedStructure); if (item.ChildElementCount == 0) { @@ -193,12 +193,12 @@ private static async Task ReadPageAsync(string url, boo if (item.Children[0] is IHtmlAnchorElement aElement) { if (aElement.ChildElementCount != 1) - throw new EbookException(ExceptionType.WebScrapingFailed, "Unexpected structure"); + throw new EbookException(ExceptionType.UnexpectedStructure); if (aElement.Children[0] is IHtmlImageElement img) { if (img.Source == null) - throw new EbookException(ExceptionType.WebScrapingFailed, "Unexpected structure"); + throw new EbookException(ExceptionType.UnexpectedStructure); // 画像のダウンロード var loader = context.GetService(); @@ -226,7 +226,7 @@ private static async Task ReadPageAsync(string url, boo } } else if (item.Children[0] is not IHtmlBreakRowElement) - throw new EbookException(ExceptionType.WebScrapingFailed, "Unexpected structure"); + throw new EbookException(ExceptionType.UnexpectedStructure); } else { @@ -241,7 +241,7 @@ private static async Task ReadPageAsync(string url, boo } if (!isAllRuby) - throw new EbookException(ExceptionType.WebScrapingFailed, "Unexpected structure"); + throw new EbookException(ExceptionType.UnexpectedStructure); if (!string.IsNullOrWhiteSpace(item.InnerHtml)) { diff --git a/KoeBook.Core/EbookException.cs b/KoeBook.Core/EbookException.cs index e8590e8..474eb5d 100644 --- a/KoeBook.Core/EbookException.cs +++ b/KoeBook.Core/EbookException.cs @@ -45,5 +45,11 @@ public enum ExceptionType Gpt4TalkerAndStyleSettingFailed, [EnumMember(Value = "webページの解析に失敗しました")] - WebScrapingFailed + WebScrapingFailed, + + [EnumMember(Value = "小説情報の取得に失敗しました")] + NarouApiFailed, + + [EnumMember(Value = "予期しない構造です")] + UnexpectedStructure } From 3adc1d44d2a8219d7114efa123422eaa08234105 Mon Sep 17 00:00:00 2001 From: aiueo-1234 <130837816+aiueo-1234@users.noreply.github.com> Date: Sat, 16 Mar 2024 09:03:07 +0900 Subject: [PATCH 7/7] =?UTF-8?q?#17-1=20=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=81=AE=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Epub/KoeBook.Epub/Services/ScrapingNaroService.cs | 2 +- KoeBook.Core/EbookException.cs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Epub/KoeBook.Epub/Services/ScrapingNaroService.cs b/Epub/KoeBook.Epub/Services/ScrapingNaroService.cs index a7dc353..c04694f 100644 --- a/Epub/KoeBook.Epub/Services/ScrapingNaroService.cs +++ b/Epub/KoeBook.Epub/Services/ScrapingNaroService.cs @@ -55,7 +55,7 @@ public async ValueTask ScrapingAsync(string url, string coverFileP var result = await client.SendAsync(message, ct).ConfigureAwait(false); var test = await result.Content.ReadAsStringAsync(ct).ConfigureAwait(false); if (!result.IsSuccessStatusCode) - throw new EbookException(ExceptionType.WebScrapingFailed, "URLが正しくありません"); + throw new EbookException(ExceptionType.HttpResponseError, $"URLが正しいかどうかやインターネットに正常に接続されているかどうかを確認してください。\nステータスコード: {result.StatusCode}\nメッセージ:{test}"); var content = await result.Content.ReadFromJsonAsync(ct).ConfigureAwait(false); if (content != null) diff --git a/KoeBook.Core/EbookException.cs b/KoeBook.Core/EbookException.cs index 474eb5d..9b5b4e1 100644 --- a/KoeBook.Core/EbookException.cs +++ b/KoeBook.Core/EbookException.cs @@ -50,6 +50,9 @@ public enum ExceptionType [EnumMember(Value = "小説情報の取得に失敗しました")] NarouApiFailed, - [EnumMember(Value = "予期しない構造です")] - UnexpectedStructure + [EnumMember(Value = "Webページが予期しない構造です")] + UnexpectedStructure, + + [EnumMember(Value = "HTTPリクエストエラー")] + HttpResponseError }