From 553f56ecaf1dff1a0573abd20616962f173dc293 Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 4 Dec 2024 19:49:26 +0100 Subject: [PATCH 1/4] Longer ExceptionMessage when Chapter comparison fails #289 --- Tranga/Chapter.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index d2fc000..5409096 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -75,7 +75,11 @@ public readonly struct Chapter : IComparable _ => chapterNumberFloat.CompareTo(otherChapterNumberFloat) }; } - else throw new FormatException($"Value could not be parsed"); + else throw new FormatException($"Value could not be parsed.\n" + + $"\tVolumeNumber: '{volumeNumber}' ChapterNumber: '{chapterNumber}'\n" + + $"\tOther-VolumeNumber: '{otherChapter.volumeNumber}' Other-ChapterNumber: '{otherChapter.chapterNumber}'\n" + + $"\t{this}\n" + + $"\t{otherChapter}"); } /// From 85d7c07b13943d94dfe3903faaaf75b6f365cfc7 Mon Sep 17 00:00:00 2001 From: Glax Date: Wed, 4 Dec 2024 19:55:31 +0100 Subject: [PATCH 2/4] Mangaworld add decimal-chapters (686.5) to regex #289 --- Tranga/MangaConnectors/Mangaworld.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tranga/MangaConnectors/Mangaworld.cs b/Tranga/MangaConnectors/Mangaworld.cs index 4096ccd..71f5581 100644 --- a/Tranga/MangaConnectors/Mangaworld.cs +++ b/Tranga/MangaConnectors/Mangaworld.cs @@ -150,7 +150,7 @@ public class Mangaworld: MangaConnector "//div[contains(concat(' ',normalize-space(@class),' '),'chapters-wrapper')]"); Regex volumeRex = new(@"[Vv]olume ([0-9]+).*"); - Regex chapterRex = new(@"[Cc]apitolo ([0-9]+).*"); + Regex chapterRex = new(@"[Cc]apitolo ([0-9]+(?:\.[0-9]+)?).*"); Regex idRex = new(@".*\/read\/([a-z0-9]+)(?:[?\/].*)?"); if (chaptersWrapper.Descendants("div").Any(descendant => descendant.HasClass("volume-element"))) { From 463f3608080d491c56e4b5e5103937e259245118 Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 12 Dec 2024 21:28:58 +0100 Subject: [PATCH 3/4] Dependency updates --- CLI/CLI.csproj | 2 +- Tranga/Tranga.csproj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CLI/CLI.csproj b/CLI/CLI.csproj index f4f37e2..becebd5 100644 --- a/CLI/CLI.csproj +++ b/CLI/CLI.csproj @@ -9,7 +9,7 @@ - + diff --git a/Tranga/Tranga.csproj b/Tranga/Tranga.csproj index fece562..1ca1c49 100644 --- a/Tranga/Tranga.csproj +++ b/Tranga/Tranga.csproj @@ -10,9 +10,9 @@ - + - + From 747df0bde5d463592914584baafcd492fbceb321 Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 12 Dec 2024 21:42:21 +0100 Subject: [PATCH 4/4] Add Puppeteer Logger --- .../MangaConnectors/ChromiumDownloadClient.cs | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/Tranga/MangaConnectors/ChromiumDownloadClient.cs b/Tranga/MangaConnectors/ChromiumDownloadClient.cs index c94f0bd..f48b2ed 100644 --- a/Tranga/MangaConnectors/ChromiumDownloadClient.cs +++ b/Tranga/MangaConnectors/ChromiumDownloadClient.cs @@ -2,18 +2,20 @@ using System.Text; using System.Text.RegularExpressions; using HtmlAgilityPack; +using Microsoft.Extensions.Logging; using PuppeteerSharp; namespace Tranga.MangaConnectors; internal class ChromiumDownloadClient : DownloadClient { - private static readonly IBrowser Browser = StartBrowser().Result; + private static IBrowser? _browser; private const int StartTimeoutMs = 10000; private readonly HttpDownloadClient _httpDownloadClient; - private static async Task StartBrowser() + private static async Task StartBrowser(Logging.Logger? logger = null) { + logger?.WriteLine("Starting ChromiumDownloadClient Puppeteer"); return await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true, @@ -23,12 +25,37 @@ internal class ChromiumDownloadClient : DownloadClient "--disable-setuid-sandbox", "--no-sandbox"}, Timeout = StartTimeoutMs - }); + }, new LoggerFactory([new LogProvider(logger)])); + } + + private class LogProvider : GlobalBase, ILoggerProvider + { + public LogProvider(Logging.Logger? logger) : base(logger) { } + + public void Dispose() { } + + public ILogger CreateLogger(string categoryName) => new Logger(logger); + } + + private class Logger : GlobalBase, ILogger + { + public Logger(Logging.Logger? logger) : base(logger) { } + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) + { + logger?.WriteLine("Puppeteer", formatter.Invoke(state, exception)); + } + + public bool IsEnabled(LogLevel logLevel) => true; + + public IDisposable? BeginScope(TState state) where TState : notnull => null; } public ChromiumDownloadClient(GlobalBase clone) : base(clone) { _httpDownloadClient = new(this); + if(_browser is null) + _browser = StartBrowser(this.logger).Result; } private readonly Regex _imageUrlRex = new(@"https?:\/\/.*\.(?:p?jpe?g|gif|a?png|bmp|avif|webp)(\?.*)?"); @@ -41,7 +68,7 @@ internal class ChromiumDownloadClient : DownloadClient private RequestResult MakeRequestBrowser(string url, string? referrer = null, string? clickButton = null) { - IPage page = Browser.NewPageAsync().Result; + IPage page = _browser.NewPageAsync().Result; page.DefaultTimeout = 10000; IResponse response; try