Skip to content

Commit

Permalink
Pagination in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
fireshaper committed Dec 14, 2018
1 parent 750c08b commit eb0aeb7
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 5 deletions.
30 changes: 29 additions & 1 deletion Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

165 changes: 161 additions & 4 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public partial class Form1 : Form
private bool status;
private String pbID;
private int idCount = 0;
private int page = 1;

private IEnumerable<HtmlNode> nodes, descNodes, ulNodes, liNodes;
private IEnumerable<HtmlNode> nodes, descNodes, ulNodes, newpageNodes, oldpageNodes;

private System.Net.WebClient client = new System.Net.WebClient();

private MegaApiClient mClient = new MegaApiClient();

//private List<Group> downloadList = new List<Group>();
private List<String> downloadList = new List<String>();
private List<String> titleList = new List<String>();

Expand Down Expand Up @@ -102,6 +102,19 @@ private void btnSearch_Click(object sender, EventArgs e)
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(data);

var npNodes = doc.DocumentNode.Descendants(0).Where(n => n.HasClass("pagination-newer"));
var opNodes = doc.DocumentNode.Descendants(0).Where(n => n.HasClass("pagination-older"));

if (opNodes.Count() > 0)
{
btnNextPage.Enabled = true;
}

if (npNodes.Count() > 0)
{
btnLastPage.Enabled = true;
}

nodes = doc.DocumentNode.Descendants(0).Where(n => n.HasClass("post-header-image"));

foreach (HtmlNode n in nodes)
Expand Down Expand Up @@ -197,7 +210,6 @@ private void btnDownload_Click(object sender, EventArgs e)
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(data);

//Regex regex = new Regex("href=\"https://mega.nz/.+\"", RegexOptions.IgnoreCase);
Regex regex = new Regex("(?<=go.php-url=)(.*)Mega", RegexOptions.IgnoreCase);
Match match;

Expand Down Expand Up @@ -246,7 +258,6 @@ private void btnDownload_Click(object sender, EventArgs e)
else
{
ulNodes = doc.DocumentNode.Descendants("ul");
//liNodes = doc.DocumentNode.Descendants("li");
int id = 0;


Expand Down Expand Up @@ -465,6 +476,8 @@ private void btnClear_Click(object sender, EventArgs e)
lbComics.Items.Clear();
tbDesc.Text = "";
pbCover.Image = Properties.Resources.omnibus_preview_image;
btnLastPage.Enabled = false;
btnNextPage.Enabled = false;
}

private void button1_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -540,6 +553,150 @@ private ListViewItem GetLVItemById(string id)
return lvi;
}

private void btnNextPage_Click(object sender, EventArgs e)
{
page++;

lbComics.Items.Clear();
pbCover.Image = Properties.Resources.omnibus_preview_image;

string search = tbComicSearch.Text;
string searchURL = "https://getcomics.info/page/" + page + "/?s=" + search;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(searchURL);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

if (response.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null;

if (response.CharacterSet == null)
{
readStream = new StreamReader(receiveStream);
}
else
{
readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
}

string data = readStream.ReadToEnd();

response.Close();
readStream.Close();

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(data);

var npNodes = doc.DocumentNode.Descendants(0).Where(n => n.HasClass("pagination-newer"));
var opNodes = doc.DocumentNode.Descendants(0).Where(n => n.HasClass("pagination-older"));

if (opNodes.Count() > 0)
{
btnNextPage.Enabled = true;
}
else
{
btnNextPage.Enabled = false;
}

if (npNodes.Count() > 0)
{
btnLastPage.Enabled = true;
}
else
{
btnLastPage.Enabled = false;
}

nodes = doc.DocumentNode.Descendants(0).Where(n => n.HasClass("post-header-image"));

foreach (HtmlNode n in nodes)
{
string node = n.InnerHtml;
string[] a = node.Split('"');

string title = replaceASCII(a[5]);

lbComics.Items.Add(title);
}

descNodes = doc.DocumentNode.Descendants(0).Where(n => n.HasClass("post-info"));
}
}

private void btnLastPage_Click(object sender, EventArgs e)
{
page--;

lbComics.Items.Clear();
pbCover.Image = Properties.Resources.omnibus_preview_image;

string search = tbComicSearch.Text;
string searchURL = "https://getcomics.info/page/" + page + "/?s=" + search;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(searchURL);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

if (response.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null;

if (response.CharacterSet == null)
{
readStream = new StreamReader(receiveStream);
}
else
{
readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
}

string data = readStream.ReadToEnd();

response.Close();
readStream.Close();

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(data);

var npNodes = doc.DocumentNode.Descendants(0).Where(n => n.HasClass("pagination-newer"));
var opNodes = doc.DocumentNode.Descendants(0).Where(n => n.HasClass("pagination-older"));

if (opNodes.Count() > 0)
{
btnNextPage.Enabled = true;
}
else
{
btnNextPage.Enabled = false;
}

if (npNodes.Count() > 0)
{
btnLastPage.Enabled = true;
}
else
{
btnLastPage.Enabled = false;
}

nodes = doc.DocumentNode.Descendants(0).Where(n => n.HasClass("post-header-image"));

foreach (HtmlNode n in nodes)
{
string node = n.InnerHtml;
string[] a = node.Split('"');

string title = replaceASCII(a[5]);

lbComics.Items.Add(title);
}

descNodes = doc.DocumentNode.Descendants(0).Where(n => n.HasClass("post-info"));
}
}

private ProgressBar GetPBById(string id)
{
ProgressBar pb = lvDownloads.Controls.OfType<ProgressBar>().FirstOrDefault(q => q.Name == id);
Expand Down

0 comments on commit eb0aeb7

Please sign in to comment.