var async = require('async');
var cheerio = require('cheerio');
var crypto = require('crypto');
var request = require('request');

async.map(['http://bukk.it', 'http://wil.to/_', 'http://misatkes.com'],
    function (origin, mapCallback) {
        mapCallback(null, function (seriesCallback) {
            request(origin, function (err, res, body) {
                var $ = cheerio.load(body);
                var selector = 'a[href$=".gif"], a[href$=".jpg"], a[href$=".jpeg"], a[href$=".png"]';
                var links = [];
                $(selector).each(function () {
                    var name = $(this).attr('href');
                    var url = origin + '/' + name;
                    links.push({
                        id: crypto.createHash('md5').update(url).digest('hex'),
                        url: url,
                        name: name,
                        origin: origin
                    });
                });
                seriesCallback(null, links);
            });
        });
    },
    function (err, results) {
        if (err || !results || !results.length) return console.log('async.map: %s - %s', err, results);
        var images;
        async.series(results, function (err, results) {
            if (err || !results || !results.length) return console.log('async.series: %s - %s', err, results);
            var i, len, args = [];
            for (i = 1, len = results.length; i < len; i++) {
                args.push(results[i]);
            }
            images = Array.prototype.concat.apply(results[0], args).sort(function (a, b) {
                if (a.name < b.name) return -1;
                if (a.name > b.name) return 1;
                return 0;
            });
            console.log(images);
        });
    }
);


@@ -85,24 +85,48 @@
 ('crypto');%0A
+var fs = require('fs');%0A
 var request 
@@ -1770,24 +1770,185 @@
 og(images);%0A
+            console.log('Processed ' + images.length + ' images');%0A            images = JSON.stringify(images);%0A            fs.writeFile('images.json', images);%0A
         %7D);%0A

Write out image information to file