Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

Commit

Permalink
add cookies and better loading bar
Browse files Browse the repository at this point in the history
  • Loading branch information
RustingRobot committed Apr 2, 2021
1 parent 49d777a commit 8f7a543
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Kea/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using iTextSharp.text.pdf;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -165,6 +166,7 @@ private async Task GetChapterAsync(string line)
{
i++;
processInfo.Invoke((MethodInvoker)delegate { processInfo.Text = $"scoping tab {i}"; }); //run on the UI thread
client.Headers.Add("Cookie", "pagGDPR=true;"); //add cookies to bypass age verification
string html = await client.DownloadStringTaskAsync(line.Substring(0, urlEnd) + "&page=" + i);
var doc = new HtmlAgilityPack.HtmlDocument(); //HtmlAgility magic
doc.LoadHtml(html);
Expand Down Expand Up @@ -219,11 +221,17 @@ private void downloadComic(int t)
float startNr = int.Parse(QueueGrid.Rows[t].Cells[1].Value.ToString()) - 1;
float endNr = (QueueGrid.Rows[t].Cells[2].Value.ToString() == "end") ? ToonChapters[t].Length : int.Parse(QueueGrid.Rows[t].Cells[2].Value.ToString());
if (endNr > ToonChapters[t].Length) endNr = ToonChapters[t].Length;
processInfo.Invoke((MethodInvoker)delegate
{
progressBar.Minimum = (int)startNr;
progressBar.Maximum = (int)endNr * 100;
});
for (int i = (int)startNr; i < endNr; i++) //...and for each chapter in that comic...
{
processInfo.Invoke((MethodInvoker)delegate { processInfo.Text = $"grabbing the html of {ToonChapters[t][i]}"; try { progressBar.Value = (int)((i - startNr) + 1 / (endNr - startNr) * 100); } catch { } }); //run on the UI thread
processInfo.Invoke((MethodInvoker)delegate { processInfo.Text = $"grabbing the html of {ToonChapters[t][i]}"; try { progressBar.Value = i * 100; } catch { } }); //run on the UI thread
using (WebClient client = new WebClient())
{
client.Headers.Add("Cookie", "pagGDPR=true;"); //add cookies to bypass age verification
string html = client.DownloadString(ToonChapters[t][i]);
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
Expand All @@ -239,6 +247,7 @@ private void downloadComic(int t)
string imgName = $"{curName} Ch{i + 1}.{j / 2}";
if (chapterFoldersCB.Checked || PDFcb.Checked) { client.DownloadFile(new Uri(childNodes[j].Attributes["data-url"].Value), $"{savePath}\\({i+1}) {ToonChapterNames[t][i]}\\{imgName}.jpg"); }
else { client.DownloadFile(new Uri(childNodes[j].Attributes["data-url"].Value), $"{savePath}\\{imgName}.jpg"); }
processInfo.Invoke((MethodInvoker)delegate { try { progressBar.Value = i * 100 + (int)(j / (float)childNodes.Count * 100); } catch { } });
}
}
}
Expand Down

0 comments on commit 8f7a543

Please sign in to comment.