├── screen.gif ├── .editorconfig ├── README.md ├── .gitignore ├── package.json ├── LICENSE └── cli.js /screen.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mayankchd/movie/HEAD/screen.gif -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_size = 2 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # movie-cli 2 | A CLI for getting information about a movies and comparing two movies 3 | 4 | ``` 5 | npm i -g movie-cli 6 | ``` 7 | 8 | ``` 9 | movie Into The Wild // For infomation about a movie 10 | movie Into The Wild :: Wild // For comparing two movies 11 | ``` 12 | ![Example GIF](https://raw.githubusercontent.com/mayankchd/movie/master/screen.gif) 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | .DS_Store -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "movie-cli", 3 | "version": "1.0.6", 4 | "description": "A CLI for getting information about a movie and comparing two movies", 5 | "bin": { 6 | "movie": "./cli.js" 7 | }, 8 | "preferGlobal": true, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/mayankchd/movie-cli.git" 12 | }, 13 | "author": "Mayank ", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/mayankchd/movie-cli/issues" 17 | }, 18 | "homepage": "https://github.com/mayankchd/movie-cli#readme", 19 | "dependencies": { 20 | "chalk": "^2.3.0", 21 | "commander": "^2.13.0", 22 | "elegant-spinner": "^1.0.1", 23 | "es6-promise": "^4.2.4", 24 | "isomorphic-fetch": "^3.0.0", 25 | "log-update": "^2.3.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Mayank Chandola 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. 22 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | 4 | const program = require('commander'); 5 | const chalk = require('chalk'); 6 | const elegantSpinner = require('elegant-spinner'); 7 | const logUpdate = require('log-update'); 8 | const fetch = require('isomorphic-fetch'); 9 | const Promise = require('es6-promise').Promise; 10 | 11 | const frame = elegantSpinner(); 12 | 13 | const propsToShow = [ 14 | 'Title', 'Year', 'Released', 'Runtime', 15 | 'Genre', 'Director', 'Writer', 'Actors', 16 | 'Plot', 'Language', 'Country', 'Awards', 17 | 'Metascore', 'imdbRating', 'tomatoMeter', 18 | 'BoxOffice', 'Production' 19 | ]; 20 | 21 | const propsToCompare = [ 22 | 'Title', 'Year', 'Released', 'Runtime', 23 | 'Genre', 'Metascore', 'imdbRating', 'tomatoMeter', 24 | 'BoxOffice', 'Production' 25 | ]; 26 | 27 | const defaultKey = '5e540903'; 28 | 29 | const initialUrl = 'http://www.omdbapi.com/?apikey='; 30 | 31 | program 32 | .description('Get information about a movie or tv series or compare two movies!') 33 | .parse(process.argv); 34 | 35 | if(program.args.length < 1) { 36 | console.log(chalk.red('Please give a movie name!!')); 37 | process.exit(1); 38 | } 39 | 40 | if(program.args.join().toUpperCase().indexOf('::') !== -1) { 41 | const interval1 = setInterval(function() { 42 | logUpdate("Loading..." + chalk.cyan.bold.dim(frame())); 43 | }, 50) 44 | const movies = program.args.join(" ").toUpperCase().split("::"); 45 | const urls = movies.map(function(mov) { 46 | return `${initialUrl}${defaultKey}&t='${mov.trim().replace(/ /g,"+")}` 47 | }); 48 | 49 | Promise.all(urls.map(fetch)). 50 | then(function(res) { return Promise.all(res.map(function(res) { return res.json()})) }). 51 | then(function(movies) { 52 | clearInterval(interval1); 53 | logUpdate.clear(); 54 | compareInfo(movies) 55 | }); 56 | } 57 | else { 58 | const interval = setInterval(function() { 59 | logUpdate("Loading..." + chalk.cyan.bold.dim(frame())); 60 | }, 50) 61 | fetch(`${initialUrl}${defaultKey}&t=${program.args.join().trim().replace(/ /g,"+")}`) 62 | .then(function(res) { return res.json()}) 63 | .then(function(mov) { 64 | clearInterval(interval); 65 | logUpdate.clear(); 66 | printInfo(mov)}); 67 | } 68 | 69 | function compareInfo(movies) { 70 | if(movies[0].Response === 'False' || movies[1].Response === 'False') { 71 | console.log(chalk.red('Movie not found!')); 72 | process.exit(1); 73 | } 74 | 75 | propsToCompare.forEach(function(prop, i, arr) { 76 | if(movies[0][prop] === 'N/A' && movies[1][prop] === 'N/A') { 77 | return ; 78 | } 79 | console.log(chalk.bold.cyan(prop), " ".repeat(13-prop.length), movies[0][prop], "", 80 | " ".repeat(50-movies[0][prop].length), movies[1][prop], "" 81 | ); 82 | }); 83 | 84 | } 85 | 86 | function printInfo(movie) { 87 | if(movie.Response === 'False') { 88 | console.log(chalk.red(movie.Error)); 89 | process.exit(1); 90 | } 91 | 92 | propsToShow.forEach(function(prop, i, arr) { 93 | if(movie[prop] !== 'N/A'){ 94 | console.log(chalk.bold.cyan(prop), " ".repeat(13-prop.length)," ::", movie[prop], ""); 95 | } 96 | }); 97 | } 98 | 99 | --------------------------------------------------------------------------------