mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-23 15:50:13 +01:00
#96 Added single click to load all chapters.
This commit is contained in:
parent
d986c808e3
commit
05573f65f9
@ -58,7 +58,7 @@ internal class ChromiumDownloadClient : DownloadClient
|
|||||||
this.browser = DownloadBrowser().Result;
|
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;
|
IPage page = this.browser.NewPageAsync().Result;
|
||||||
page.DefaultTimeout = 10000;
|
page.DefaultTimeout = 10000;
|
||||||
@ -72,6 +72,8 @@ internal class ChromiumDownloadClient : DownloadClient
|
|||||||
{
|
{
|
||||||
if (content.Contains("text/html"))
|
if (content.Contains("text/html"))
|
||||||
{
|
{
|
||||||
|
if(clickButton is not null)
|
||||||
|
page.ClickAsync(clickButton).Wait();
|
||||||
string htmlString = page.GetContentAsync().Result;
|
string htmlString = page.GetContentAsync().Result;
|
||||||
stream = new MemoryStream(Encoding.Default.GetBytes(htmlString));
|
stream = new MemoryStream(Encoding.Default.GetBytes(htmlString));
|
||||||
document = new ();
|
document = new ();
|
||||||
|
@ -16,7 +16,7 @@ internal abstract class DownloadClient : GlobalBase
|
|||||||
_rateLimit.Add(limit.Key, TimeSpan.FromMinutes(1).Divide(limit.Value));
|
_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))
|
if (_rateLimit.TryGetValue(requestType, out TimeSpan value))
|
||||||
_lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(value));
|
_lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(value));
|
||||||
@ -35,11 +35,11 @@ internal abstract class DownloadClient : GlobalBase
|
|||||||
Thread.Sleep(rateLimitTimeout);
|
Thread.Sleep(rateLimitTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestResult result = MakeRequestInternal(url, referrer);
|
RequestResult result = MakeRequestInternal(url, referrer, clickButton);
|
||||||
_lastExecutedRateLimit[requestType] = DateTime.Now;
|
_lastExecutedRateLimit[requestType] = DateTime.Now;
|
||||||
return result;
|
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();
|
public abstract void Close();
|
||||||
}
|
}
|
@ -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;
|
HttpResponseMessage? response = null;
|
||||||
while (response is null)
|
while (response is null)
|
||||||
{
|
{
|
||||||
|
@ -133,7 +133,7 @@ public class MangaLife : MangaConnector
|
|||||||
public override Chapter[] GetChapters(Manga manga, string language="en")
|
public override Chapter[] GetChapters(Manga manga, string language="en")
|
||||||
{
|
{
|
||||||
Log($"Getting chapters {manga}");
|
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)
|
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300 || result.htmlDocument is null)
|
||||||
{
|
{
|
||||||
return Array.Empty<Chapter>();
|
return Array.Empty<Chapter>();
|
||||||
@ -150,9 +150,9 @@ public class MangaLife : MangaConnector
|
|||||||
Match rexMatch = urlRex.Match(url);
|
Match rexMatch = urlRex.Match(url);
|
||||||
|
|
||||||
string volumeNumber = "1";
|
string volumeNumber = "1";
|
||||||
if (rexMatch.Groups.Count == 4)
|
if (rexMatch.Groups[3].Value.Length > 1)
|
||||||
volumeNumber = rexMatch.Groups[3].ToString();
|
volumeNumber = rexMatch.Groups[3].Value;
|
||||||
string chapterNumber = rexMatch.Groups[1].ToString();
|
string chapterNumber = rexMatch.Groups[1].Value;
|
||||||
string fullUrl = $"https://manga4life.com{url}";
|
string fullUrl = $"https://manga4life.com{url}";
|
||||||
fullUrl = fullUrl.Replace(Regex.Match(url,"(-page-[0-9])").Value,"");
|
fullUrl = fullUrl.Replace(Regex.Match(url,"(-page-[0-9])").Value,"");
|
||||||
chapters.Add(new Chapter(manga, "", volumeNumber, chapterNumber, fullUrl));
|
chapters.Add(new Chapter(manga, "", volumeNumber, chapterNumber, fullUrl));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user