├── .gitignore ├── LICENSE ├── README.md ├── bin └── meinv ├── index.js ├── lib ├── display.js ├── tags_code.json └── utils.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 金马 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | meinv 2 | ===== 3 | 4 | [![NPM version](https://badge.fury.io/js/meinv.png)](http://badge.fury.io/js/meinv) 5 | [![David Status](https://david-dm.org/lijinma/meinv.png)](https://david-dm.org/lijinma/meinv) 6 | 7 | A tool to get pretty girls images in your command line. 8 | 9 | 10 | ![meinv](http://i.imgur.com/mYHjF4g.png) 11 | 12 | 13 | 使用终端获取百度美女图片。 14 | 15 | ## Install 16 | 17 | ```bash 18 | $ npm install meinv -g 19 | ``` 20 | 21 | ## Usage 22 | 23 | $ meinv 5 24 | 25 | 5 is the number of girls images you want to get. 26 | 27 | ## LICENSE 28 | 29 | MIT. 30 | -------------------------------------------------------------------------------- /bin/meinv: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var rmdir = require('rimraf') 3 | , utils = require('../lib/utils'); 4 | 5 | require('colorful').toxic(); 6 | if (!process.argv[2]) { 7 | console.log(''); 8 | console.log(' meinv ~ ' + require('../package').version.green + '\n'); 9 | console.log(' ' + require('../package').description.grey + '\n'); 10 | console.log(' (1)获取n张美女图片'.grey + '\n'); 11 | console.log(' $ '.cyan + 'meinv 5' + '\n'); 12 | console.log(' (2)删除所有图片'.grey + '\n'); 13 | console.log(' $ '.cyan + 'meinv rm' + '\n'); 14 | return; 15 | } 16 | 17 | if (process.argv[2] == 'rm') { 18 | 19 | rmdir(utils.home()+'/meinvImages', function(err) { 20 | if (err) { 21 | console.log('Error remove : ' + utils.home() + '/meinvImages'); 22 | return; 23 | } else { 24 | console.log('美女图片删除干净,可以安心写代码了'); 25 | return; 26 | } 27 | }); 28 | } 29 | 30 | var meinv = require('..'); 31 | meinv(process.argv[2], process.argv[3]); 32 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var request = require('request'), 2 | tagsCode = require('./lib/tags_code.json'), 3 | display = require('./lib/display'); 4 | utils = require('./lib/utils'); 5 | 6 | module.exports = function(imagesCount) { 7 | //Baidu image 8 | var pn = Math.floor(Math.random() * 200); 9 | //console.log ('pn : ' + pn); 10 | var randomTag = utils.getRandomString(10); 11 | var url = 'http://image.baidu.com/channel/listjson?pn=' + pn + '&rn=200&tag1=美女&tag2=全部'; 12 | request.get(url + '&ftags=' + randomTag, function (error, response, data) { 13 | if (!error && response.statusCode == 200) { 14 | // console.log('data: ' + data); 15 | display.images(data, imagesCount); 16 | } 17 | }); 18 | }; 19 | -------------------------------------------------------------------------------- /lib/display.js: -------------------------------------------------------------------------------- 1 | var mkdirp = require('mkdirp'), 2 | wget = require('wget'), 3 | utils = require('./utils'); 4 | 5 | var images = []; 6 | 7 | exports.images = function(data, imagesCount) { 8 | var imagesDir = utils.home() + '/meinvImages/'; 9 | mkdirp(imagesDir, function (err) { 10 | if (err) console.error(err) 11 | }); 12 | 13 | 14 | var jsonData = JSON.parse(data), 15 | girls = jsonData.data, 16 | randomNumber = Math.random() * (girls.length - 1); 17 | for( var i = 1; i <= imagesCount; i ++) { 18 | downloadImages(girls[Math.floor(randomNumber) + i].image_url, imagesDir, imagesCount); 19 | } 20 | 21 | 22 | 23 | }; 24 | 25 | function downloadImages(imageSource, imagesDir, imagesCount) { 26 | imageName = utils.getRandomString(8) + '.jpg'; 27 | 28 | var output = imagesDir + imageName; 29 | var download = wget.download(imageSource, output); 30 | download.on('error', function(err) { 31 | images.push(null); 32 | if(images.length == imagesCount) { 33 | var imagesString = images.join(' ').toString(); 34 | var open; 35 | if(process.platform === 'win32'){ 36 | open = 'start'; 37 | }else if(process.platform === 'darwin'){ 38 | open = 'open'; 39 | } 40 | else if(process.platform === 'linux'){ 41 | open='xdg-open'; 42 | }else{ 43 | console.log('当前平台不支持命令打开图片,请到'+imagesDir+'下自撸'); 44 | return; 45 | } 46 | var openImageCmd = open + ' ' + imagesString; 47 | require('child_process').exec(openImageCmd, function (error, stdout, stderr) { }); 48 | } 49 | console.log(err); 50 | }); 51 | download.on('end', function(output) { 52 | console.log(' * * * * * * 努力下载了一张* * * * * * * * '); 53 | images.push(output); 54 | if(images.length == imagesCount) { 55 | var imagesString = images.join(' ').toString(); 56 | var open; 57 | if(process.platform === 'win32'){ 58 | open = 'start'; 59 | }else if(process.platform === 'darwin'){ 60 | open = 'open'; 61 | } 62 | else if(process.platform === 'linux'){ 63 | open='xdg-open'; 64 | }else{ 65 | console.log('当前平台不支持命令打开图片,请到'+imagesDir+'下自撸'); 66 | return; 67 | } 68 | var openImageCmd = open + ' ' + imagesString; 69 | require('child_process').exec(openImageCmd, function (error, stdout, stderr) { }); 70 | } 71 | 72 | 73 | }); 74 | } 75 | -------------------------------------------------------------------------------- /lib/tags_code.json: -------------------------------------------------------------------------------- 1 | { 2 | } -------------------------------------------------------------------------------- /lib/utils.js: -------------------------------------------------------------------------------- 1 | var open = (process.platform === 'win32') ? 'start' : 'open'; 2 | 3 | 4 | exports.home = function() { 5 | return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']; 6 | } 7 | 8 | exports.getRandomString = function(length) { 9 | var originalString = "0123456789qwertyuioplkjhgfdsazxcvbnm"; 10 | var randomString = ""; 11 | for(var i=0;i", 11 | "license": "MIT", 12 | "bin": { 13 | "meinv": "./bin/meinv" 14 | }, 15 | "keywords": [ 16 | "girls", 17 | "baidu images", 18 | "meinv" 19 | ], 20 | "engines": { 21 | "node": ">= 0.8.1" 22 | }, 23 | "readmeFilename": "README.md", 24 | "dependencies": { 25 | "request": "~2.34.0", 26 | "colorful": "~2.1.0", 27 | "mkdirp": "0.3.5", 28 | "wget": "0.0.1", 29 | "rimraf": "^2.2.6" 30 | } 31 | } 32 | --------------------------------------------------------------------------------