big change in the results returned by the api
This commit is contained in:
191
lib/module.js
191
lib/module.js
@@ -1,169 +1,54 @@
|
||||
const config = require('../config');
|
||||
const request = require('request');
|
||||
|
||||
module.exports.getDetails = function (detailsId, movieOrTv, tmdbApiKey, language, cb) {
|
||||
module.exports.getTmdbDetails = function (getParamaters, thmdbId, type, tmdbApiKey, language) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (movieOrTv == 'movie' || movieOrTv == 'tv') {
|
||||
if (type == 'movie' || type == 'tv') {
|
||||
|
||||
const detailURL = config.theMovieDbURL + movieOrTv + '/' + detailsId + '?api_key=' + tmdbApiKey + '&language=' + language;
|
||||
let url
|
||||
|
||||
request(detailURL, (err, resultBody, body) => {
|
||||
if (resultBody != '') {
|
||||
const getJson = JSON.parse(resultBody.body);
|
||||
|
||||
if (getJson.status_code > 1) {
|
||||
// if wrong api key error
|
||||
const error = 'tmdb get detail wrong api key error';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
}
|
||||
else {
|
||||
if (err) {
|
||||
// if thmdb api connection error
|
||||
const error = 'tmdb get detail api connection error';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
}
|
||||
else {
|
||||
const error = null;
|
||||
const result = getJson;
|
||||
cb(error, result);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const error = 'tmdb get detail api connection error';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
switch (getParamaters) {
|
||||
case 'details':
|
||||
url = config.theMovieDbURL + type + '/' + thmdbId + '?api_key=' + tmdbApiKey + '&language=' + language;
|
||||
break;
|
||||
case 'credits':
|
||||
url = config.theMovieDbURL + type + '/' + thmdbId + '/credits?api_key=' + tmdbApiKey + '&language=en-US';
|
||||
break;
|
||||
case 'trailers':
|
||||
url = config.theMovieDbURL + type + '/' + thmdbId + '/videos?api_key=' + tmdbApiKey;
|
||||
break;
|
||||
case 'images':
|
||||
url = config.theMovieDbURL + type + '/' + thmdbId + '/images?api_key=' + tmdbApiKey + '&language=en-US&include_image_language=en,null';
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
const error = 'tmdb get detail wrong watch parameter';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.getCredits = function (detailsId, movieOrTv, tmdbApiKey, cb) {
|
||||
request(encodeURI(url), (err, resultBody, body) => {
|
||||
|
||||
if (movieOrTv == 'movie' || movieOrTv == 'tv') {
|
||||
|
||||
const creditsURL = config.theMovieDbURL + movieOrTv + '/' + detailsId + '/credits?api_key=' + tmdbApiKey + '&language=en-US';
|
||||
|
||||
request(creditsURL, (err, resultBody, body) => {
|
||||
|
||||
const getJson = JSON.parse(resultBody.body);
|
||||
|
||||
if (getJson.status_code > 1) {
|
||||
// if wrong api key error
|
||||
const error = 'tmdb get credits wrong api key error';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
}
|
||||
else {
|
||||
if (err) {
|
||||
// if thmdb api connection error
|
||||
const error = 'tmdb get credits api connection error';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
reject('tmdb get detail api connection error');
|
||||
}
|
||||
else {
|
||||
const error = null;
|
||||
const result = getJson;
|
||||
cb(error, result);
|
||||
}
|
||||
}
|
||||
if (resultBody != '') {
|
||||
const getJson = JSON.parse(resultBody.body);
|
||||
|
||||
});
|
||||
}
|
||||
else {
|
||||
const error = 'tmdb get credits wrong watch parameter';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.getTrailers = function (detailsId, movieOrTv, tmdbApiKey, cb) {
|
||||
|
||||
if (movieOrTv == 'movie' || movieOrTv == 'tv') {
|
||||
|
||||
// https://api.themoviedb.org/3/movie/157336/videos?api_key=API-KEY
|
||||
const trailersURL = config.theMovieDbURL + movieOrTv + '/' + detailsId + '/videos?api_key=' + tmdbApiKey;
|
||||
|
||||
request(trailersURL, (err, resultBody, body) => {
|
||||
|
||||
const getJson = JSON.parse(resultBody.body);
|
||||
|
||||
if (getJson.status_code > 1) {
|
||||
// if wrong api key error
|
||||
const error = 'tmdb get credits wrong api key error';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
}
|
||||
else {
|
||||
if (err) {
|
||||
// if thmdb api connection error
|
||||
const error = 'tmdb get trailers api connection error';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
}
|
||||
else {
|
||||
const error = null;
|
||||
const result = getJson;
|
||||
|
||||
cb(error, result);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
else {
|
||||
const error = 'tmdb get trailers wrong watch parameter';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.getImages = function (detailsId, movieOrTv, tmdbApiKey, cb) {
|
||||
|
||||
if (movieOrTv == 'movie' || movieOrTv == 'tv') {
|
||||
|
||||
const creditsURL = config.theMovieDbURL + movieOrTv + '/' + detailsId + '/images?api_key=' + tmdbApiKey + '&language=en-US&include_image_language=en,null';
|
||||
|
||||
request(creditsURL, (err, resultBody, body) => {
|
||||
|
||||
if (resultBody != []) {
|
||||
const getJson = JSON.parse(resultBody.body);
|
||||
if (getJson.status_code > 1) {
|
||||
// if wrong api key error
|
||||
const error = 'tmdb get images wrong api key error';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
}
|
||||
else {
|
||||
if (err) {
|
||||
// if thmdb api connection error
|
||||
const error = 'tmdb get images api connection error';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
}
|
||||
else {
|
||||
const error = null;
|
||||
const result = getJson;
|
||||
cb(error, result);
|
||||
if (getJson.status_code > 1) {
|
||||
// if wrong api key error
|
||||
reject('tmdb get detail wrong api key error');
|
||||
}
|
||||
else {
|
||||
resolve(getJson);
|
||||
}
|
||||
} else {
|
||||
// request sonucu boş dönmüşse null döndür
|
||||
resolve(null)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if wrong api key error
|
||||
const error = 'error getting data';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
const error = 'tmdb get images wrong watch parameter';
|
||||
const result = null;
|
||||
cb(error, result);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
reject('tmdb get detail wrong watch parameter');
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user