From 412389eb2e73ceaa123d1d5d3e5c268187f2524f Mon Sep 17 00:00:00 2001 From: Wise Colt Date: Tue, 31 Mar 2020 22:10:53 +0300 Subject: [PATCH] video trailer add result update --- lib/index.js | 17 ++++++++++++----- lib/module.js | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/lib/index.js b/lib/index.js index 2660b34..0df9624 100644 --- a/lib/index.js +++ b/lib/index.js @@ -66,7 +66,7 @@ class FlixInfo { request(tmdbURL, (err, resultBody, body) => { // Api find all result (for get tmdb id) const getJson = JSON.parse(resultBody.body); - + if (getJson.status_code > 1) { // if wrong api key error returnResult = { error: 1, errorMsg: 'tmdb find id wrong api key error' }; @@ -93,8 +93,8 @@ class FlixInfo { var thmdbId = getJson.tv_results[0].id; } // Get detail info - modules.getDetails(thmdbId, watchParameter, tmdbApiKey, language,(err, getDetailResult) => { - + modules.getDetails(thmdbId, watchParameter, tmdbApiKey, language, (err, getDetailResult) => { + if (err) { returnResult = { error: 1, errorMsg: err }; reject(returnResult); @@ -114,8 +114,15 @@ class FlixInfo { reject(returnResult); } else { - returnResult = { result: 1, error: 0, watch: watchParameter, details: getDetailResult, credits: getCreditsResult, images: getImagesResult }; - resolve(returnResult); + modules.getTrailers(thmdbId, watchParameter, tmdbApiKey, (err, getTrailersResult) => { + if (err) { + returnResult = { error: 1, errorMsg: err }; + reject(returnResult); + } else { + returnResult = { result: 1, error: 0, watch: watchParameter, details: getDetailResult, credits: getCreditsResult, images: getImagesResult, trailers: getTrailersResult }; + resolve(returnResult); + } + }); } }); } diff --git a/lib/module.js b/lib/module.js index 098b66c..d0ef2f6 100644 --- a/lib/module.js +++ b/lib/module.js @@ -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') {