Permalink
Browse files

Initial release

  • Loading branch information...
1 parent 42a174f commit a6581f96d1f0a12a088ea876cd9ed8249f2045b1 hackerman committed Mar 25, 2017
Showing with 108 additions and 0 deletions.
  1. +66 −0 index.js
  2. +42 −0 package.json
View
@@ -0,0 +1,66 @@
+var request = require('request')
+var fs = require('fs');
+var https = require("https")
+var path = require("path")
+var program = require("commander")
+
+program
+ .version('1.0.0')
+ .option('--amount [limit]', 'Amount of pictures to download (Default is 10)')
+ .option('--folder [name]', 'Name of the folder you want to save the images to (Default is "images")')
+ .option('--width [w]', 'Width of images (Default is 1200)')
+ .option('--height [h]', 'Height of images (Default is 800)')
+ .option('-g, --grayscale', 'Enable grayscale for images (disabled by default)')
+ .option('-b, --blur', 'Blur images (disabled by default)')
+ .parse(process.argv);
+
+if(!program.amount){
+ program.amount = 10
+}
+
+if(!program.folder){
+ program.folder = "images"
+}
+
+if(!program.width){
+ program.width = 1200
+}
+
+if(!program.height){
+ program.height = 800
+}
+
+console.log("Downloading " + program.amount + " random images :)")
+var ProgressBar = require('progress');
+var bar = new ProgressBar(':bar', { total: parseInt(program.amount) });
+
+function download(url, dest, dirname) {
+ var dir = './' + dirname;
+ if (!fs.existsSync(dir)){
+ fs.mkdirSync(dir)
+ }
+
+ var file = fs.createWriteStream(dest);
+ var request = https.get(url, function(response) {
+ response.pipe(file)
+ file.on('finish', function() {
+ bar.tick()
+ })
+ }).on('error', function(err) {
+ fs.unlink(dest)
+ });
+};
+
+for (i = 0; i < program.amount; i++){
+ if(program.grayscale){
+ var url = "https://unsplash.it/g/" + program.width + "/" + program.height + "/?random"
+ } else{
+ var url = "https://unsplash.it/" + program.width + "/" + program.height + "/?random"
+ }
+
+ if(program.blur){
+ var url = url + "&blur"
+ }
+
+ download(url, path.join(__dirname, "/" + program.folder + "/image-" + (i+1) + ".jpg"), program.folder)
+}
View
@@ -0,0 +1,42 @@
+{
+ "name": "unsplash-bulk-downloader",
+ "version": "1.0.0",
+ "description": "A simple command line tool that lets you bulk download images from Unsplash",
+ "main": "main.js",
+ "dependencies": {
+ "commander": "^2.9.0",
+ "fs": "^0.0.1-security",
+ "https": "^1.0.0",
+ "nodeJs-zip": "^1.0.4",
+ "path": "^0.12.7",
+ "request": "^2.81.0"
+ },
+ "devDependencies": {
+ "nodeJs-zip": "^1.0.4",
+ "progress": "^1.1.8",
+ "zip-folder": "^1.0.0"
+ },
+ "scripts": {
+ "test": "node main.js"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/MehediH/UnsplashBulkDownloader.git"
+ },
+ "keywords": [
+ "unsplash",
+ "unsplash",
+ "bulk",
+ "unsplash",
+ "bulk",
+ "downloader",
+ "stock",
+ "images"
+ ],
+ "author": "Mehedi Hassan",
+ "license": "GPL-3.0",
+ "bugs": {
+ "url": "https://github.com/MehediH/UnsplashBulkDownloader/issues"
+ },
+ "homepage": "https://github.com/MehediH/UnsplashBulkDownloader#readme"
+}

0 comments on commit a6581f9

Please sign in to comment.