diff --git a/DanEngine.cs b/DanEngine.cs index 8070063..3998ac3 100644 --- a/DanEngine.cs +++ b/DanEngine.cs @@ -42,6 +42,8 @@ private void downloadImage(string url, string tags, bool keepOriginalNames) { using (WebClient wc = new WebClient()) { + wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; " + + "Windows NT 5.2; .NET CLR 1.0.3705;)"); if (keepOriginalNames) wc.DownloadFileAsync(new System.Uri(url), "./out/" + FnameFromURL(url)); else diff --git a/Form1.cs b/Form1.cs index 6f604b9..34cd18c 100644 --- a/Form1.cs +++ b/Form1.cs @@ -73,9 +73,10 @@ private async void downloadButton_Click(object sender, EventArgs e) { statusLabel.ForeColor = Color.Blue; statusLabel.Text = "Downloading..."; - for (int i = 0; i < postCount; i++) + for (int i = 1; i < postCount; i++) { await Task.Run(() => engine.downloadPosts(domainBox.Text, tagsBox.Text, i, checkBox1.Checked)); + statusLabel.Text = "Downloading..." + Convert.ToString(postCount - i); } statusLabel.ForeColor = Color.Green; statusLabel.Text = "Ready."; @@ -87,6 +88,7 @@ private async void downloadButton_Click(object sender, EventArgs e) GelEngine engine = new GelEngine(); int postCount = engine.getPostCount(domainBox.Text, tagsBox.Text); + Console.WriteLine(postCount); if (postCount == 0) { Console.WriteLine("No posts found by tag " + tagsBox.Text); @@ -100,6 +102,7 @@ private async void downloadButton_Click(object sender, EventArgs e) for (int i = 0; i < postCount; i++) { await Task.Run(() => engine.downloadPosts(domainBox.Text, tagsBox.Text, i, checkBox1.Checked)); + statusLabel.Text = "Downloading..." + Convert.ToString(postCount - i); } statusLabel.ForeColor = Color.Green; statusLabel.Text = "Ready."; diff --git a/GelEngine.cs b/GelEngine.cs index 8b4b31f..45ec76a 100644 --- a/GelEngine.cs +++ b/GelEngine.cs @@ -19,6 +19,9 @@ class GelEngine XmlElement root; string url; + [DllImport("kernel32.dll", SetLastError = true)] + static extern bool AllocConsole(); + string ExtFromURL(string line) { var ext = ""; @@ -41,6 +44,8 @@ private void downloadImage(string url, string tags, bool keepOriginalNames) { using (WebClient wc = new WebClient()) { + wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; " + + "Windows NT 5.2; .NET CLR 1.0.3705;)"); if (keepOriginalNames) wc.DownloadFileAsync(new System.Uri(url), "./out/" + FnameFromURL(url)); else @@ -52,7 +57,7 @@ public int getPostCount(string domain, string tags) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(domain + "/index.php?page=dapi&s=post&q=index&limit=1&tags=" + tags); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); - //AllocConsole(); + AllocConsole(); string result = ""; using (Stream stream = response.GetResponseStream()) { @@ -85,6 +90,7 @@ public string downloadPosts(string domain, string tags, int page, bool keepOrigi url = root.Attributes["file_url"].Value; tags = root.Attributes["tags"].Value; + Console.WriteLine(url); downloadImage(url, tags, keepOriginalNames); } return url;