#96 Added single click to load all chapters.

This commit is contained in:
glax 2024-01-03 18:37:29 +01:00
parent d986c808e3
commit 05573f65f9
4 changed files with 13 additions and 9 deletions

View File

@ -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 ();

View File

@ -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();
}

View File

@ -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)
{

View File

@ -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<Chapter>();
@ -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));