From 6588cadf3af4175dc4ecb3fd38e0bf2a6361fed1 Mon Sep 17 00:00:00 2001 From: Jonathan Troyer <jonathantroyer@outlook.com> Date: Thu, 29 Oct 2020 22:35:44 -0500 Subject: [PATCH] Add color option --- README.md | 2 ++ index.js | 6 ++++-- package-lock.json | 2 +- package.json | 2 +- questions.js | 15 +++++++++++++++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8103bb9..066c7b6 100755 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Prompts in the terminal will guide you through the options for downloading image * `How many images (up to 50)?` - The number of images to retrieve. _Defaults to 20_ * `Only featured images?` - Should it only get featured images, curated by Unsplash? _Defaults to `Yes`_ * `What orientation?` - What orientation should the images be? The options are `Mixed`, `Portrait`, `Landscape`, `Squarish`, or `Custom`. `Mixed` will get images regardless of orientation, while `Custom` allows you to choose a specific width and height. _Defaults to `Mixed`_ +* `What color?` - What color should the images be? The options are `Any`, `Black and white`, `Black`, `White`, `Yellow`, `Orange`, `Red`, `Purple`, `Magenta`, `Green`, `Teal`, or `Blue`. _Defaults to `Any`_ * `Width?` - For any orientation, choose the width of the returned images. This is required when the `Custom` orientation is selected. _Defaults to blank for original size_ * `Height?` - For `Custom` orientation, specify a height. This option is not displayed if the orientation is not * `Export the credits for the photos to a .json file?` - Whether to generate the `bulksplash-credits.json` file with all the details about hte photographers. _Defaults to yes_ @@ -55,6 +56,7 @@ Available options: * `--w`: the width of the images. * `--h`: the height of the images. * `--o`: the orientation of the images ("landscape", "portrait", "squarish") +* `--r`: the color of the images ("black and white", "black", "white", "yellow", "orange", "red", "purple", "magenta", "green", "teal", "blue") * `--f`: whether you want to download featured images. * `--j`: whether you want to generate a credits file. --- diff --git a/index.js b/index.js index f2a73ed..da64fae 100644 --- a/index.js +++ b/index.js @@ -133,6 +133,7 @@ const bulksplash = async (args) => { options.width = args["w"] && parseInt(args["w"]) > 0 ? parseInt(args["w"]) : null options.height = args["h"] && parseInt(args["h"]) > 0 ? parseInt(args["h"]) : null options.orientation = args["o"] && ["landscape", "portrait", "squarish"].includes(args["o"]) ? args["o"] : "" + options.color = args["r"] && ["black and white", "black", "white", "yellow", "orange", "red", "purple", "magenta", "green", "teal", "blue"].includes(args["r"]) ? args["r"] : "" options.featured = args["f"] ? args["f"] : false options.saveCredits = args["j"] ? args["j"] : false } else{ @@ -145,7 +146,7 @@ const bulksplash = async (args) => { // console.log(options) - const buildUrl = ({ featured, orientation, search, width, height, amount, random, collection}) => { + const buildUrl = ({ featured, orientation, color, search, width, height, amount, random, collection}) => { let base; if(random){ @@ -160,10 +161,11 @@ const bulksplash = async (args) => { const a = random ? (amount > 30 ? `&count=30` : `&count=${amount}`) : "" const p = !random && collection ? (amount > 30 ? `&per_page=30` : `&per_page=${amount}`) : "" const o = orientation ? `&orientation=${orientation}` : '' + const c = color ? `&color=${color}` : '' const s = search && random ? `&query=${search}` : '' const w = width ? `&w=${width}` : '' const h = height ? `&h=${height}` : '' - return `${base}${a}${p}${o}${f}${w}${h}${s}${clientId}` + return `${base}${a}${p}${o}${c}${f}${w}${h}${s}${clientId}` } let url; diff --git a/package-lock.json b/package-lock.json index 9e36e02..43231f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bulksplash", - "version": "2.0.0", + "version": "2.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a2135f4..d4e42ad 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bulksplash", - "version": "2.0.2", + "version": "2.1.0", "description": "A simple command line tool that lets you bulk download images from Unsplash", "main": "main.js", "dependencies": { diff --git a/questions.js b/questions.js index 8eff7d7..0b85184 100644 --- a/questions.js +++ b/questions.js @@ -4,6 +4,7 @@ const DEFAULTS = { featured: true, width: 2400, height: 1600, + color: null } const requiredQuestions = { @@ -49,6 +50,20 @@ const requiredQuestions = { return val.toLowerCase() }, }, + + color: { + type: 'list', + name: 'color', + message: '🎨 What color?', + choices: ['Any', 'Black and white', 'Black', 'White', 'Yellow', 'Orange', 'Red', 'Purple', 'Magenta', 'Green', 'Teal', 'Blue'], + filter: function(val) { + val = val.toLowerCase().split(' ').join('_') + if(val === 'any') + val = null + return val + }, + default: DEFAULTS.color + }, } const conditionalQuestions = {