-
Notifications
You must be signed in to change notification settings - Fork 6
/
imdbtr.js
51 lines (40 loc) · 1.18 KB
/
imdbtr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
const chalk = require('chalk');
const figures = require('figures');
const ora = require('ora');
const api = require('./api.js');
const helpers = require('./helpers.js');
const imdbtr = params => {
if (!params) {
return false;
}
const query = helpers.buildQuery(params);
const movie = api(query);
if (!movie) {
return false;
}
const values = Object.values(params).join(', ');
const spinner = ora(`Searching for ${chalk.yellow(values)}`).start();
return movie.then(result => {
spinner.stop();
if (!result) {
return console.log(chalk.yellow.bold('Movie not found on IMDB :('));
}
const movieRes = `
${chalk.black.bgYellow.bold(result.Title)} (${result.Year}) on IMDb:
${chalk.yellow(`${figures.star} ${result.imdbRating}`)}
Duration: .... ${result.Runtime} min
Director: .... ${result.Director}
Writer: ...... ${result.Writer}
Stars: ....... ${result.Actors}
Genre: ....... ${chalk.italic(result.Genre)}
Plot: ... ${result.Plot}
`;
console.log(movieRes);
}).catch(error => {
spinner.stop();
console.error(chalk.red.bold('Something went wrong :('));
console.error(error);
});
};
module.exports = imdbtr;