Skip to content

Commit

Permalink
* seperated the logic from the form
Browse files Browse the repository at this point in the history
* created the ImageScrape class that includes all the scraping (obviously lol)
* added a label to the progeess bar
* made it possible to make custom filter options
* filteroptions are saved and loaded into a simple .txt
* rearranged the form layout (changing it is not equal better, it still looks horrible lol)
  • Loading branch information
Administrator authored and Administrator committed Nov 28, 2017
1 parent 30d1ca9 commit e5f301f
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 159 deletions.
36 changes: 18 additions & 18 deletions ImageScraper/Form1.Designer.cs

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

193 changes: 55 additions & 138 deletions ImageScraper/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@
using System.IO;
using System.Diagnostics;
using System.IO.Compression;
using _ImageScraper;

namespace _4chanDumper
namespace _ImageScraper
{
public partial class MainFormImageScraper : Form
{
public List<string> urlList = new List<string>();
public List<Image> dumpedList = new List<Image>();
public int currentShow = 0;
public int maxShow = 0;
public Random rnd = new Random();
public string currentDumpedCode = "No code dumped yet.";

public MainFormImageScraper()
{
Expand All @@ -30,56 +28,9 @@ public MainFormImageScraper()

private void Form1_Load(object sender, EventArgs e)
{
ImageScrape.LoadFilter();
}

public List<string> DumpImageFormat(string format, string dumpedCode)
{
List<string> imageurls = new List<string>();
while (dumpedCode.Contains(format))
{
int indx = dumpedCode.IndexOf(format);
string firstMarker = "";
for (int i = 0; i < format.Length; i++)
{
firstMarker = firstMarker + dumpedCode[indx + i].ToString();
}
string imagelink = "";
for (int i = indx - 1; i > 0; i--)
{
if (dumpedCode[i] != '"')
imagelink = dumpedCode[i] + imagelink;
else
i = 0;
}
if (imagelink != "")
{
if (imagelink[0] != 'h' && imagelink[1] != 't' && imagelink[2] != 't' && imagelink[3] != 'p')
{
imagelink = textBox_url.Text + imagelink;
}
}
imageurls.Add(imagelink + firstMarker);
dumpedCode = dumpedCode.Remove(0, indx + 3);
}
return imageurls;
}

public void GetImageFromURL(string url)
{
try
{
WebRequest req = WebRequest.Create(url);
WebResponse resp = req.GetResponse();
Bitmap img = new Bitmap(resp.GetResponseStream());
dumpedList.Add(img);
pictureBox_preview.Image = img;
pictureBox_preview.Update();
}
catch(Exception)
{

}
}


void DumpNLogEverything(List<List<string>> imageLists)
{
Expand All @@ -95,83 +46,58 @@ void DumpNLogEverything(List<List<string>> imageLists)
{
textBox_log.Text = textBox_log.Text + Environment.NewLine + listItem;
textBox_log.Update();
GetImageFromURL(listItem);
Bitmap tmp = ImageScrape.GetImageFromURL(listItem);
ImageScrape.DumpedList.Add(tmp);
pictureBox_preview.Image = tmp;
pictureBox_preview.Update();
progessBar_dump.Value = progessBar_dump.Value + 1;
progessBar_dump.Update();
label_progress.Text = progessBar_dump.Value + "/" + GetMaxCount(imageLists);
label_progress.Update();
}
}
}


private void button1_Click(object sender, EventArgs e)
int GetMaxCount(List<List<string>> list)
{
progessBar_dump.Value = 0;
dumpedList = new List<Image>();
string txtUrl = textBox_url.Text;
if(txtUrl[4] == 's')
int count = 0;
foreach(var item in list)
{
txtUrl = txtUrl.Remove(4,1);
}
if(txtUrl[txtUrl.Length-1] == '/')
{
txtUrl = txtUrl.Remove(txtUrl.Length - 1);
foreach(var itemlist in item)
{
count = count + 1;
}
}
textBox_url.Text = txtUrl;


return count;
}

private void button1_Click(object sender, EventArgs e)
{
progessBar_dump.Value = 0;
string webUrl = ImageScrape.PrepareUrl(textBox_url.Text);
textBox_log.Text = "";
string dumpedCode = DumpHTML(textBox_url.Text);
currentDumpedCode = dumpedCode;
string dumpedCode = ImageScrape.DumpHTML(webUrl);
System.IO.File.WriteAllText("dumpedCode.txt", dumpedCode);
System.IO.Directory.CreateDirectory("dumpedImages");

List<string> dumpedPngs = DumpImageFormat(".png", dumpedCode);
List<string> dumpedJpgs = DumpImageFormat(".jpg", dumpedCode);
List<string> dumpedGifs = DumpImageFormat(".gif", dumpedCode);

List<List<string>> dumpingList = new List<List<string>>();
dumpingList.Add(dumpedPngs);
dumpingList.Add(dumpedJpgs);
dumpingList.Add(dumpedGifs);
List<List<string>> dumpingList = ImageScrape.GetAllImageLinks();

label_progress.Text = "0/" + GetMaxCount(dumpingList);


DumpNLogEverything(dumpingList);

if(check_openDirectory.Checked == true)
if (check_openDirectory.Checked == true)
Process.Start("dumpedImages");
pictureBox_preview.Image = dumpedList[0];

maxShow = dumpedList.Count;

pictureBox_preview.Image = ImageScrape.DumpedList[0];

}
maxShow = ImageScrape.DumpedList.Count;

public string DumpHTML(string url)
{
string urlAddress = url;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string code = "";
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));
}

code = readStream.ReadToEnd();
response.Close();
readStream.Close();
}
return code;
}

private void button2_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -212,81 +138,72 @@ private void dataGridView1_CellContentClick(object sender, DataGridViewCellEvent

private void button5_Click(object sender, EventArgs e)
{
try
if (ImageScrape.DumpedList.Count > 0)
{
currentShow = currentShow - 1;
if (currentShow < 0)
currentShow = dumpedList.Count - 1;
if (currentShow > dumpedList.Count)
currentShow = ImageScrape.DumpedList.Count - 1;
if (currentShow > ImageScrape.DumpedList.Count)
currentShow = 0;

pictureBox_preview.Image = dumpedList[currentShow];
}
catch (Exception ex)
{

pictureBox_preview.Image = ImageScrape.DumpedList[currentShow];
}
}

private void button6_Click(object sender, EventArgs e)
{
try
if (ImageScrape.DumpedList.Count > 0)
{
currentShow = currentShow + 1;
if (currentShow < 0)
currentShow = dumpedList.Count - 1;
if (currentShow > dumpedList.Count)
currentShow = 0;

pictureBox_preview.Image = dumpedList[currentShow];
}catch(Exception ex)
{
currentShow = ImageScrape.DumpedList.Count - 1;
if (currentShow > ImageScrape.DumpedList.Count)
currentShow = 1;

pictureBox_preview.Image = ImageScrape.DumpedList[currentShow - 1];
}

}

private void button7_Click(object sender, EventArgs e)
{
foreach(var item in dumpedList)
foreach(var item in ImageScrape.DumpedList)
{
item.Save("dumpedImages/" + System.IO.Directory.GetFiles("dumpedImages").Length + ".png");
}
}

private void button8_Click(object sender, EventArgs e)
{
try {
if(pictureBox_preview.Image != null)
pictureBox_preview.Image.Save("dumpedImages/" + System.IO.Directory.GetFiles("dumpedImages").Length + ".png");
}catch(Exception ex)
{
// lmao dont be stoopid
}
}

private void button10_Click(object sender, EventArgs e)
{
pictureBox_preview.Image = null;
dumpedList = new List<Image>();
ImageScrape.ResetDumpedList();

}

private void button9_Click(object sender, EventArgs e)
{
try
{
int tmp = rnd.Next(0, dumpedList.Count - 1);

pictureBox_preview.Image = dumpedList[tmp];
}catch(Exception ex)
if (ImageScrape.DumpedList.Count > 0)
{
// lmao dont be stoopid
int tmp = rnd.Next(0, ImageScrape.DumpedList.Count - 1);
pictureBox_preview.Image = ImageScrape.DumpedList[tmp];
}
}

private void button1_Click_1(object sender, EventArgs e)
{
MessageBox.Show(currentDumpedCode);
MessageBox.Show(ImageScrape.DumpedCode);
}

private void button_addFilter_Click(object sender, EventArgs e)
{
ImageScrape.FilterList.Add(textBox_filter.Text);
ImageScrape.SaveFilter();
textBox_filter.Text = "";
}
}
}
Loading

1 comment on commit e5f301f

@realTobby
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started to make this application to scrape images off of 4chan. But I liked the idea to use this tool globally a bit more

Please sign in to comment.