parent
34dd78810d
commit
21af75f410
@ -1,5 +1,6 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
using PuppeteerSharp;
|
using PuppeteerSharp;
|
||||||
using PuppeteerSharp.Input;
|
using PuppeteerSharp.Input;
|
||||||
@ -11,10 +12,11 @@ internal class ChromiumDownloadClient : DownloadClient
|
|||||||
private IBrowser browser { get; set; }
|
private IBrowser browser { get; set; }
|
||||||
private const string ChromiumVersion = "1154303";
|
private const string ChromiumVersion = "1154303";
|
||||||
private const int StartTimeoutMs = 30000;
|
private const int StartTimeoutMs = 30000;
|
||||||
|
private HttpDownloadClient _httpDownloadClient;
|
||||||
|
|
||||||
private async Task<IBrowser> DownloadBrowser()
|
private async Task<IBrowser> DownloadBrowser()
|
||||||
{
|
{
|
||||||
BrowserFetcher browserFetcher = new BrowserFetcher();
|
BrowserFetcher browserFetcher = new ();
|
||||||
foreach(string rev in browserFetcher.LocalRevisions().Where(rev => rev != ChromiumVersion))
|
foreach(string rev in browserFetcher.LocalRevisions().Where(rev => rev != ChromiumVersion))
|
||||||
browserFetcher.Remove(rev);
|
browserFetcher.Remove(rev);
|
||||||
if (!browserFetcher.LocalRevisions().Contains(ChromiumVersion))
|
if (!browserFetcher.LocalRevisions().Contains(ChromiumVersion))
|
||||||
@ -58,9 +60,18 @@ internal class ChromiumDownloadClient : DownloadClient
|
|||||||
public ChromiumDownloadClient(GlobalBase clone) : base(clone)
|
public ChromiumDownloadClient(GlobalBase clone) : base(clone)
|
||||||
{
|
{
|
||||||
this.browser = DownloadBrowser().Result;
|
this.browser = DownloadBrowser().Result;
|
||||||
|
_httpDownloadClient = new(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
private readonly Regex _imageUrlRex = new(@"https?:\/\/.*\.(?:p?jpe?g|gif|a?png|bmp|avif|webp)(\?.*)?");
|
||||||
|
internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
||||||
|
{
|
||||||
|
return _imageUrlRex.IsMatch(url)
|
||||||
|
? _httpDownloadClient.MakeRequestInternal(url, referrer)
|
||||||
|
: MakeRequestBrowser(url, referrer, clickButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RequestResult MakeRequestBrowser(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;
|
||||||
|
@ -40,6 +40,6 @@ internal abstract class DownloadClient : GlobalBase
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null);
|
internal abstract RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null);
|
||||||
public abstract void Close();
|
public abstract void Close();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user