Skip to content

Commit

Permalink
Updated to use new links on site.
Browse files Browse the repository at this point in the history
  • Loading branch information
fireshaper committed Nov 3, 2018
1 parent b7c5c3c commit 19ed3ae
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 66 deletions.
183 changes: 117 additions & 66 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public partial class Form1 : Form

private MegaApiClient mClient = new MegaApiClient();

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

private CancellationTokenSource cts;
Expand Down Expand Up @@ -108,9 +109,8 @@ private void btnSearch_Click(object sender, EventArgs e)
string node = n.InnerHtml;
string[] a = node.Split('"');

string aTitle = a[5];
string title = aTitle.Replace("&#8211;", "-");

string title = replaceASCII(a[5]);

lbComics.Items.Add(title);
}

Expand All @@ -130,7 +130,8 @@ private void lbComics_SelectedIndexChanged(object sender, EventArgs e)
string descNode = d.InnerHtml;
string[] b = descNode.Split('"');
string[] c = b[16].Split('\n');
string[] desc = c[1].Split('<');
string[] preDesc = c[0].Split('>');
string[] desc = preDesc[6].Split('<');

tbDesc.Text = desc[0];
}
Expand All @@ -156,8 +157,6 @@ private void btnOpenLink_Click(object sender, EventArgs e)
{
MessageBox.Show("You must search for a comic first.");
}


}

private void btnDownload_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -198,82 +197,130 @@ 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("href=\"https://mega.nz/.+\"", RegexOptions.IgnoreCase);
Regex regex = new Regex("(?<=go.php-url=)(.*)Mega", RegexOptions.IgnoreCase);
Match match;

for (match = regex.Match(data); match.Success; match = match.NextMatch())
if (regex.Match(data).Success != false)
{
foreach (Group group in match.Groups)
for (match = regex.Match(data); match.Success; match = match.NextMatch())
{
string[] g1 = group.ToString().Split('"');
string lastEV = "";

if (g1[3] == "aio-purple")
foreach (Group group in match.Groups)
{
downloadList.Add(group);
string[] g1 = group.ToString().Split(new string[] { "<a" }, StringSplitOptions.None);
int lastURL = g1.Length - 1;
string[] g2 = g1[lastURL].Split('"');

if (g2[7] == "aio-purple")
{
string gcURL = g2[5];
string[] gcURLArray = gcURL.Split('/');

string encodedValue = gcURLArray[4];

HtmlNode tn = nodes.ElementAt(lbComics.SelectedIndex);
string tnode = n.InnerHtml;
string[] ta = node.Split('"');
if (lastEV != encodedValue)
{
byte[] urlData = Convert.FromBase64String(encodedValue);
string decodedURL = Encoding.UTF8.GetString(urlData);

string aTitle = ta[5];
string title = aTitle.Replace("&#8211;", "-");

downloadList.Add(decodedURL);

//add item to listview
AddLVItem("0", title);
HtmlNode tn = nodes.ElementAt(lbComics.SelectedIndex);
string tnode = n.InnerHtml;
string[] ta = node.Split('"');

titleList.Add(title);
}
else
{
ulNodes = doc.DocumentNode.Descendants("ul");
int id = 0;
string title = replaceASCII(ta[5]);

//add item to listview
AddLVItem("0", title);

titleList.Add(title);

foreach (HtmlNode u in ulNodes)
lastEV = encodedValue;
}

}
else
{
string ulNode = u.InnerHtml;
string[] b = ulNode.Split(new[] { "<li>" }, StringSplitOptions.None);
ulNodes = doc.DocumentNode.Descendants("ul");
int id = 0;

for (int i = 1; i < b.Count(); i++)
foreach (HtmlNode u in ulNodes)
{
String[] c = b[i].Split('"');
string ulNode = u.InnerHtml;
string[] b = ulNode.Split(new[] { "<li>" }, StringSplitOptions.None);

if (c[3] == "_blank&quot;")
for (int i = 1; i < b.Count(); i++)
{
string[] t0 = b[i].Split('>');
int index = 0;
int fIndex = t0[0].LastIndexOf('(');
int length = fIndex - index;
String[] c = b[i].Split('"');

string titleSub = t0[0].Substring(index, length - 1);
if (c[7] == "_blank&quot;")
{
string[] t0 = b[i].Split('>');
int index = 0;
int fIndex = t0[0].LastIndexOf('(');
int length = fIndex - index;

string title = titleSub.Replace("&#8211;", "-");
string titleSub = t0[0].Substring(index, length - 1);

Regex iRegex = new Regex("href=\"https://mega.nz/.+\"", RegexOptions.IgnoreCase);
Match iMatch;
string title = replaceASCII(titleSub);

for (iMatch = iRegex.Match(b[i]); iMatch.Success; iMatch = iMatch.NextMatch())
{
foreach (Group iGroup in iMatch.Groups)
Regex iRegex = new Regex("(?<=go.php-url=)(.*)Mega", RegexOptions.IgnoreCase);
Match iMatch;

if (regex.Match(data).Success != false)
{
downloadList.Add(iGroup);
for (iMatch = iRegex.Match(b[i]); iMatch.Success; iMatch = iMatch.NextMatch())
{
foreach (Group iGroup in iMatch.Groups)
{
string[] g01 = iGroup.ToString().Split(new string[] { "<a" }, StringSplitOptions.None);
int lastURLa = g01.Length - 1;
string[] g02 = g01[lastURLa].Split('"');

string gcURL = g02[5];
string[] gcURLArray = gcURL.Split('/');

string encodedValue = gcURLArray[4];

if (lastEV != encodedValue)
{
byte[] urlData = Convert.FromBase64String(encodedValue);
string decodedURL = Encoding.UTF8.GetString(urlData);

//add item to listview
AddLVItem(id.ToString(),title);
id++;
downloadList.Add(decodedURL);

titleList.Add(title);
//add item to listview
AddLVItem(id.ToString(), title);
id++;

Console.WriteLine(title);
titleList.Add(title);

Console.WriteLine(title);

lastEV = encodedValue;
}


}
}
}
else
MessageBox.Show("No downloads available, go to the comic's page to download.");

}
}
}
}
}
break;
}
break;
}
else
MessageBox.Show("No download link available. Go to comic's page and download manually.");


if (downloadList.Count > 0)
{
Expand All @@ -285,7 +332,6 @@ private void btnDownload_Click(object sender, EventArgs e)
{
MessageBox.Show("You must search for a comic first.");
}

}

private void AddLVItem(string id, string title)
Expand Down Expand Up @@ -313,21 +359,17 @@ async private void DownloadComic(int idCount)
complete = 1;
status = true;
String id = idCount.ToString();
Group group = downloadList[0];
string[] g1 = group.ToString().Split('"');

string title = titleList[0];
//string filename = title + ".cbr";

Uri myStringWebResource = new Uri(g1[1]);
String url = downloadList[0];

Uri myStringWebResource = new Uri(url);

INodeInfo node = mClient.GetNodeFromLink(myStringWebResource);
string filename = node.Name;
downloadPath = Properties.Settings.Default.DownloadLocation + filename;
downloadPath = Properties.Settings.Default.DownloadLocation + "\\" + filename;

IProgress<double> progressHandler = new Progress<double>(x => UpdateItemValue(id, (int)x));

Console.WriteLine("Downloading " + filename);
Console.WriteLine("Downloading: " + downloadPath);
btnCancel.Enabled = true;

cts = new CancellationTokenSource();
Expand Down Expand Up @@ -370,8 +412,6 @@ async private void DownloadComic(int idCount)
{
DownloadComplete();
}


}

private void UpdateItemValue(string id, int value)
Expand All @@ -394,9 +434,7 @@ private void UpdateItemValue(string id, int value)
lvDownloads.Controls.Remove(pb);
complete = 1;
}

}

}

private void CancelDownload(string path)
Expand Down Expand Up @@ -516,7 +554,6 @@ private void DownloadCancelled()
{
DownloadComic(idCount);
}

}

private void DownloadComplete()
Expand All @@ -535,5 +572,19 @@ private void DownloadComplete()
btnCancel.Enabled = false;
}
}

private string replaceASCII(string title)
{
if (title.Contains("&#8211;"))
title = title.Replace("&#8211;", "-");

if (title.Contains("&#8217;"))
title = title.Replace("&#8217;", "'");

if (title.Contains("&#038;"))
title = title.Replace("&#038;", "&");

return title;
}
}
}
15 changes: 15 additions & 0 deletions Settings.Designer.cs

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

8 changes: 8 additions & 0 deletions Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,13 @@ private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}

private void btnBrowse_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
tbDLocation.Text = folderBrowserDialog1.SelectedPath;
}
}
}
}
3 changes: 3 additions & 0 deletions Settings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down

0 comments on commit 19ed3ae

Please sign in to comment.