-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetflix-go.js
41 lines (30 loc) · 902 Bytes
/
netflix-go.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
#!/usr/bin/env node
var streamapi = require('./lib/streamapi.js');
var utils = require('./lib/utils');
var program = require('commander');
program
.usage('<string>')
.description('Goes directly to netflix for first result')
.parse(process.argv);
var searchTerm = program.args[0];
if(!program.args[0]){
console.log("Please enter a movie title");
}
streamapi.getMovies(searchTerm)
.then(function(movies){
if(movies.length > 0){
var title = movies[0].title;
var movieInfoPromise = streamapi.getMovieDetails( movies[0]._id);
return [ title , movieInfoPromise];
}else{
console.log("Could not find a movie with that title");
}
}).spread(function(title, movie){
if(movie.netflix_instant){
utils.openLink(movie.netflix_instant.direct_url);
}else{
console.log( title + " doesn't appear to be on netflix");
}
}).catch(function(err){
console.log(err);
});