Compare commits
No commits in common. "fdea3659f1c9b3f63a93af8835a4573aea75002e" and "3456fc656404ce497e669df26210e06603e106ed" have entirely different histories.
fdea3659f1
...
3456fc6564
@ -8,12 +8,13 @@ namespace Tranga.MangaConnectors;
|
|||||||
|
|
||||||
internal class ChromiumDownloadClient : DownloadClient
|
internal class ChromiumDownloadClient : DownloadClient
|
||||||
{
|
{
|
||||||
private static readonly IBrowser Browser = StartBrowser().Result;
|
private IBrowser browser { get; set; }
|
||||||
private const int StartTimeoutMs = 10000;
|
private const int StartTimeoutMs = 30000;
|
||||||
private readonly HttpDownloadClient _httpDownloadClient;
|
private readonly HttpDownloadClient _httpDownloadClient;
|
||||||
|
|
||||||
private static async Task<IBrowser> StartBrowser()
|
private async Task<IBrowser> StartBrowser()
|
||||||
{
|
{
|
||||||
|
Log($"Starting Browser. ({StartTimeoutMs}ms timeout)");
|
||||||
return await Puppeteer.LaunchAsync(new LaunchOptions
|
return await Puppeteer.LaunchAsync(new LaunchOptions
|
||||||
{
|
{
|
||||||
Headless = true,
|
Headless = true,
|
||||||
@ -28,6 +29,7 @@ internal class ChromiumDownloadClient : DownloadClient
|
|||||||
|
|
||||||
public ChromiumDownloadClient(GlobalBase clone) : base(clone)
|
public ChromiumDownloadClient(GlobalBase clone) : base(clone)
|
||||||
{
|
{
|
||||||
|
this.browser = StartBrowser().Result;
|
||||||
_httpDownloadClient = new(this);
|
_httpDownloadClient = new(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +43,7 @@ internal class ChromiumDownloadClient : DownloadClient
|
|||||||
|
|
||||||
private RequestResult MakeRequestBrowser(string url, string? referrer = null, string? clickButton = null)
|
private RequestResult MakeRequestBrowser(string url, string? referrer = null, string? clickButton = null)
|
||||||
{
|
{
|
||||||
IPage page = Browser.NewPageAsync().Result;
|
IPage page = this.browser.NewPageAsync().Result;
|
||||||
page.DefaultTimeout = 10000;
|
page.DefaultTimeout = 10000;
|
||||||
IResponse response;
|
IResponse response;
|
||||||
try
|
try
|
||||||
@ -52,7 +54,6 @@ internal class ChromiumDownloadClient : DownloadClient
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log($"Could not load Page:\n{e.Message}");
|
Log($"Could not load Page:\n{e.Message}");
|
||||||
page.CloseAsync();
|
|
||||||
return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null);
|
return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,4 +84,9 @@ internal class ChromiumDownloadClient : DownloadClient
|
|||||||
page.CloseAsync();
|
page.CloseAsync();
|
||||||
return new RequestResult(response.Status, document, stream, false, "");
|
return new RequestResult(response.Status, document, stream, false, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Close()
|
||||||
|
{
|
||||||
|
this.browser.CloseAsync();
|
||||||
|
}
|
||||||
}
|
}
|
@ -41,4 +41,5 @@ internal abstract class DownloadClient : GlobalBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal 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();
|
||||||
}
|
}
|
@ -72,4 +72,9 @@ internal class HttpDownloadClient : DownloadClient
|
|||||||
|
|
||||||
return new RequestResult(response.StatusCode, document, stream);
|
return new RequestResult(response.StatusCode, document, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Close()
|
||||||
|
{
|
||||||
|
Log("Closing.");
|
||||||
|
}
|
||||||
}
|
}
|
@ -15,6 +15,11 @@ public abstract class MangaConnector : GlobalBase
|
|||||||
{
|
{
|
||||||
internal DownloadClient downloadClient { get; init; } = null!;
|
internal DownloadClient downloadClient { get; init; } = null!;
|
||||||
|
|
||||||
|
public void StopDownloadClient()
|
||||||
|
{
|
||||||
|
downloadClient.Close();
|
||||||
|
}
|
||||||
|
|
||||||
protected MangaConnector(GlobalBase clone, string name) : base(clone)
|
protected MangaConnector(GlobalBase clone, string name) : base(clone)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -229,10 +234,7 @@ public abstract class MangaConnector : GlobalBase
|
|||||||
Directory.CreateDirectory(directoryPath);
|
Directory.CreateDirectory(directoryPath);
|
||||||
|
|
||||||
if (File.Exists(saveArchiveFilePath)) //Don't download twice.
|
if (File.Exists(saveArchiveFilePath)) //Don't download twice.
|
||||||
{
|
|
||||||
progressToken?.Complete();
|
|
||||||
return HttpStatusCode.Created;
|
return HttpStatusCode.Created;
|
||||||
}
|
|
||||||
|
|
||||||
//Create a temporary folder to store images
|
//Create a temporary folder to store images
|
||||||
string tempFolder = Directory.CreateTempSubdirectory("trangatemp").FullName;
|
string tempFolder = Directory.CreateTempSubdirectory("trangatemp").FullName;
|
||||||
|
Loading…
Reference in New Issue
Block a user