Skip to content

Instantly share code, notes, and snippets.

@gotomypc
Forked from max-mapper/index.js
Created October 28, 2012 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gotomypc/3968037 to your computer and use it in GitHub Desktop.
Save gotomypc/3968037 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