-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathMoviesAPI.js
113 lines (108 loc) · 2.93 KB
/
MoviesAPI.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var logger = require("./logger");
function getMovies(page, sort_by, amount, callback) {
return;
}
function getMoviesGenre(genre, amount, callback) {
return;
}
function getMovieWithFanart(ID, resolution, callback) {
var page = 1;
var request = require("request")
var url = "";
logger.Debug("=== Getting Movie ===");
logger.Debug(url);
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
var movie = body.data;
logger.Debug(movie);
var Fan = require('./fanartGenerator')
try {
Fan.generateFanart(movie.imdb_code, resolution, function(url){
callback(movie, url);
});
} catch(e) {
movie['rt_audience_score'] = '50';
callback(movie, 'thumbnails/Background_blank_1080.jpg');
}
} else {
logger.warning("Error connecting to website and grabbing json: " + url);
return;
}
})
}
function getMovie(ID, callback) {
return;
}
function searchMovies(query, callback) {
return;
}
function getFanart(imdb, callback){
var request = require('request');
var url = 'https://api-v2launch.trakt.tv/movies/' + imdb + '?extended=images';
logger.Debug("=== Getting Fanart ===");
logger.Debug(url);
request({
url: url,
json: true,
headers: {
'Content-Type': 'application/json',
'trakt-api-version': '2',
'trakt-api-key': '' // Removed Trakt.tv Key
}
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
var fanart = body.images.fanart.full;
logger.Debug(fanart);
callback(fanart);
} else {
logger.warning("Error connecting to trakt.tv and grabbing json: " + url);
return;
}
})
}
function getRelatedMovies(movie_id, callback) {
return;
}
function generateScreenSaverJSON(callback){
var request = require("request")
var url = "";
logger.Debug("=== Getting Movies ===");
logger.Debug(url);
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
var movies = body.data.movies;
logger.Debug(movies);
var json = [];
movies.forEach(function(movie){
json.push({
type: 'photo',
id: 'photo_' + movie.id,
assets: [{
width: 406,
height: 600,
src: movie.medium_cover_image
}]
})
});
logger.Debug(json);
callback(JSON.stringify(json));
} else {
logger.warning("Error connecting to website and grabbing json: " + url);
return;
}
})
}
exports.getMovies = getMovies;
exports.getMovie = getMovie;
exports.getMovieWithFanart = getMovieWithFanart;
exports.searchMovies = searchMovies;
exports.getFanart = getFanart;
exports.getRelatedMovies = getRelatedMovies;
exports.getMoviesGenre = getMoviesGenre;
exports.generateScreenSaverJSON = generateScreenSaverJSON;