Created
July 11, 2012 04:53
-
-
Save max-mapper/3088102 to your computer and use it in GitHub Desktop.
display all pngs from a url in a terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cheerio = require('cheerio') | |
var request = require('request') | |
var pictureTube = require('picture-tube') | |
var url = require('url') | |
var async = require('async') | |
var site = process.argv[2] | |
console.log('fetching', site) | |
request(site, function(e,r,b) { | |
var $ = cheerio.load(b) | |
var imgs = $('img') | |
console.log('fetching', imgs.length, 'images') | |
imgs.each(function(i, img) { | |
var href = $(img).attr('src') | |
if (!href || !href.match(/png/)) return | |
var uri = url.resolve(site, href) | |
q.push(uri, function (err) { | |
if (err) console.log('error processing', uri, err) | |
}) | |
}) | |
}) | |
function fetchAndTube(uri, cb) { | |
var tube = pictureTube() | |
tube.pipe(process.stdout) | |
request(uri) | |
.pipe(tube) | |
.on('end', cb) | |
} | |
var q = async.queue(fetchAndTube, 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment