Skip to content

Commit

Permalink
Add retry mechanism for doujin download
Browse files Browse the repository at this point in the history
  • Loading branch information
Xwilarg committed Sep 22, 2024
1 parent 14a4ccf commit 73f92fd
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions Sanara/Module/Utility/EHentai.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,25 @@ public static async Task EHentaiDownloadAsync(IContext ctx, IServiceProvider pro
{
if (img.HasClass("gdtm")) // Get all images to download them
{
var node = img.FirstChild.FirstChild.Attributes["href"].Value;
var image = web.Load(node).GetElementbyId("img").Attributes["src"].Value;
File.WriteAllBytes($"Saves/Download/{dirName}/{pageIndex:000}{Path.GetExtension(image)}",
await provider.GetRequiredService<HttpClient>().GetByteArrayAsync(image));
pageIndex++;
System.Exception err = null;
for (int c = 0; c < 2; c++)
{
try
{
var node = img.FirstChild.FirstChild.Attributes["href"].Value;
var image = web.Load(node).GetElementbyId("img").Attributes["src"].Value;
File.WriteAllBytes($"Saves/Download/{dirName}/{pageIndex:000}{Path.GetExtension(image)}",
await provider.GetRequiredService<HttpClient>().GetByteArrayAsync(image));
pageIndex++;
err = null;
break;
}
catch (System.Exception e)
{
err = e;
}
}
if (err != null) throw err;
}
}

Expand Down

0 comments on commit 73f92fd

Please sign in to comment.