video trailer add result update

This commit is contained in:
Wise Colt
2020-03-31 22:10:53 +03:00
parent b860fec36f
commit 412389eb2e
2 changed files with 54 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ module.exports.getDetails = function (detailsId, movieOrTv, tmdbApiKey, language
if (movieOrTv == 'movie' || movieOrTv == 'tv') {
const detailURL = config.theMovieDbURL + movieOrTv + '/' + detailsId + '?api_key=' + tmdbApiKey + '&language=' + language + '&append_to_response=videos';
const detailURL = config.theMovieDbURL + movieOrTv + '/' + detailsId + '?api_key=' + tmdbApiKey + '&language=' + language;
request(detailURL, (err, resultBody, body) => {
if (resultBody != '') {
@@ -83,6 +83,47 @@ module.exports.getCredits = function (detailsId, movieOrTv, tmdbApiKey, cb) {
}
}
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') {