diff --git a/Tranga/MangaConnectors/ChromiumDownloadClient.cs b/Tranga/MangaConnectors/ChromiumDownloadClient.cs index 3f07229..78a1534 100644 --- a/Tranga/MangaConnectors/ChromiumDownloadClient.cs +++ b/Tranga/MangaConnectors/ChromiumDownloadClient.cs @@ -58,7 +58,7 @@ internal class ChromiumDownloadClient : DownloadClient this.browser = DownloadBrowser().Result; } - protected override RequestResult MakeRequestInternal(string url, string? referrer = null) + protected override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null) { IPage page = this.browser.NewPageAsync().Result; page.DefaultTimeout = 10000; @@ -72,6 +72,8 @@ internal class ChromiumDownloadClient : DownloadClient { if (content.Contains("text/html")) { + if(clickButton is not null) + page.ClickAsync(clickButton).Wait(); string htmlString = page.GetContentAsync().Result; stream = new MemoryStream(Encoding.Default.GetBytes(htmlString)); document = new (); diff --git a/Tranga/MangaConnectors/DownloadClient.cs b/Tranga/MangaConnectors/DownloadClient.cs index 50d2578..2e19f98 100644 --- a/Tranga/MangaConnectors/DownloadClient.cs +++ b/Tranga/MangaConnectors/DownloadClient.cs @@ -16,7 +16,7 @@ internal abstract class DownloadClient : GlobalBase _rateLimit.Add(limit.Key, TimeSpan.FromMinutes(1).Divide(limit.Value)); } - public RequestResult MakeRequest(string url, byte requestType, string? referrer = null) + public RequestResult MakeRequest(string url, byte requestType, string? referrer = null, string? clickButton = null) { if (_rateLimit.TryGetValue(requestType, out TimeSpan value)) _lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(value)); @@ -35,11 +35,11 @@ internal abstract class DownloadClient : GlobalBase Thread.Sleep(rateLimitTimeout); } - RequestResult result = MakeRequestInternal(url, referrer); + RequestResult result = MakeRequestInternal(url, referrer, clickButton); _lastExecutedRateLimit[requestType] = DateTime.Now; return result; } - protected abstract RequestResult MakeRequestInternal(string url, string? referrer = null); + protected abstract RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null); public abstract void Close(); } \ No newline at end of file diff --git a/Tranga/MangaConnectors/HttpDownloadClient.cs b/Tranga/MangaConnectors/HttpDownloadClient.cs index fca0dc1..d8a3d40 100644 --- a/Tranga/MangaConnectors/HttpDownloadClient.cs +++ b/Tranga/MangaConnectors/HttpDownloadClient.cs @@ -24,8 +24,10 @@ internal class HttpDownloadClient : DownloadClient } - protected override RequestResult MakeRequestInternal(string url, string? referrer = null) + protected override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null) { + if(clickButton is not null) + Log("Can not click button on static site."); HttpResponseMessage? response = null; while (response is null) { diff --git a/Tranga/MangaConnectors/MangaLife.cs b/Tranga/MangaConnectors/MangaLife.cs index 6eb2cca..006d815 100644 --- a/Tranga/MangaConnectors/MangaLife.cs +++ b/Tranga/MangaConnectors/MangaLife.cs @@ -133,7 +133,7 @@ public class MangaLife : MangaConnector public override Chapter[] GetChapters(Manga manga, string language="en") { Log($"Getting chapters {manga}"); - RequestResult result = downloadClient.MakeRequest($"https://manga4life.com/manga/{manga.publicationId}", 1); + RequestResult result = downloadClient.MakeRequest($"https://manga4life.com/manga/{manga.publicationId}", 1, clickButton:"[class*='ShowAllChapters']"); if ((int)result.statusCode < 200 || (int)result.statusCode >= 300 || result.htmlDocument is null) { return Array.Empty(); @@ -150,9 +150,9 @@ public class MangaLife : MangaConnector Match rexMatch = urlRex.Match(url); string volumeNumber = "1"; - if (rexMatch.Groups.Count == 4) - volumeNumber = rexMatch.Groups[3].ToString(); - string chapterNumber = rexMatch.Groups[1].ToString(); + if (rexMatch.Groups[3].Value.Length > 1) + volumeNumber = rexMatch.Groups[3].Value; + string chapterNumber = rexMatch.Groups[1].Value; string fullUrl = $"https://manga4life.com{url}"; fullUrl = fullUrl.Replace(Regex.Match(url,"(-page-[0-9])").Value,""); chapters.Add(new Chapter(manga, "", volumeNumber, chapterNumber, fullUrl));