Skip to content

Instantly share code, notes, and snippets.

@Mygod
Created February 9, 2014 13:00
Show Gist options
  • Save Mygod/8898722 to your computer and use it in GitHub Desktop.
Save Mygod/8898722 to your computer and use it in GitHub Desktop.
Goomod Downloader
/* Here's the script that I used to fetch ALL the goomods from goofans.com. Enjoy. *
* Copyleft © 2014 Mygod (studio.mygod.tk) */
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;
using System.Windows.Forms;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using System.Net;
class Script
{
public static readonly WebClient Client = new WebClient();
public static readonly Regex DownloadFinder = new Regex("\"(/download/\\d.*?)\"", RegexOptions.Compiled);
[STAThread]
public static void Main(string[] args)
{
using (var logger = new StreamWriter(@"M:\Products\Scripts\GoomodDownloader\output.log", false) { AutoFlush = true })
{
var i = 144;
while (true)
{
HttpWebResponse response = null;
Console.WriteLine("Fetching data for node #{0}...", ++i);
try
{
var request = WebRequest.Create("http://goofans.com/node/" + i);
request.Proxy = new WebProxy("127.0.0.1", 8087);
request.Timeout = 10000;
response = (HttpWebResponse) request.GetResponse();
if (200 != (int) response.StatusCode) throw new WebException("WTF?", null, WebExceptionStatus.Success, response);
var url = response.ResponseUri.ToString();
Console.WriteLine(url);
if (!url.StartsWith("http://goofans.com/download/")) continue;
try
{
foreach (Match match in DownloadFinder.Matches(new StreamReader(response.GetResponseStream()).ReadToEnd()))
{
var target = "http://goofans.com" + match.Groups[1].Value;
Console.WriteLine("Trying to download: " + target);
try
{
var dir = Path.Combine(@"M:\Products\Scripts\GoomodDownloader\Downloaded", Path.GetFileName(Path.GetDirectoryName(target)));
Directory.CreateDirectory(dir);
Client.DownloadFile(target, Path.Combine(dir, Path.GetFileName(target)));
File.WriteAllText(Path.Combine(dir, "Learn more.url"), "[InternetShortcut]\r\nURL=" + url);
Console.WriteLine("Download successfully.", Path.GetFileName(target));
}
catch (Exception exc)
{
var str = string.Format("Unable to fetch goomod: {0}{1}Message: {2}", target, Environment.NewLine, exc.Message);
Console.WriteLine(str);
logger.WriteLine(str);
}
}
}
catch (Exception exc)
{
var str = string.Format("Unable to fetch the page: {0}{1}Message: {2}", url, Environment.NewLine, exc.Message);
Console.WriteLine(str);
logger.WriteLine(str);
}
}
catch (WebException exc)
{
var code = (int) ((HttpWebResponse) exc.Response).StatusCode;
var str = string.Format("Fetching node #{0} failed. Return code #{1}. Message: {2}", i, code, exc.Message);
Console.WriteLine(str);
logger.WriteLine(str);
//if (code == 404) return;
}
catch (Exception exc)
{
var str = string.Format("Fetching node #{0} failed. Unknown error. Message: {1}", i, exc.Message);
Console.WriteLine(str);
logger.WriteLine(str);
}
finally
{
if (response != null) response.Dispose();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment