Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
4,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. // imgchili album downloader
  2. // downloads full images for a given link to working folder
  3. // run like...
  4. // `node script.js http://imgchili.net/album/abc123`
  5.  
  6. var request=require('request');
  7. var fs=require('fs');
  8.  
  9. var download = function(uri, filename, callback){
  10. request.head(uri, function(err, res, body){
  11. request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
  12. });
  13. };
  14.  
  15. var link=process.argv[2];
  16.  
  17. request(link, function(e,r,b){
  18.  
  19. var img_links = b.match(/a\shref\=['"]show(.*?)['"]\</ig);
  20.  
  21. img_links.forEach(function(linka){
  22.  
  23. linka = linka.replace(/a\shref\=['"](show.*?)['"]\</ig, '$1');
  24. linka = "http://imgchili.net/"+linka
  25.  
  26. request(linka, function(e,r,b){
  27. var image_link = b.match(/id="show_image.*?\n.*?src="(.*?)"/ig);
  28. image_link = image_link[0].replace(/id="show_image.*?\n.*?src="(.*?)"/, "$1");
  29.  
  30. download(image_link, image_link.slice(image_link.length - 20, image_link.length)+'.jpg', function(){
  31. console.log(image_link.slice(image_link.length - 20, image_link.length)+'.jpg'+' done.');
  32. })
  33. });
  34. });
  35. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement