Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Created July 11, 2012 04:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save max-mapper/3088102 to your computer and use it in GitHub Desktop.
Save max-mapper/3088102 to your computer and use it in GitHub Desktop.
display all pngs from a url in a terminal
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