get movie detail, get image and get cast added
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
var config= {
|
var config = {
|
||||||
// Filexible URL
|
// Filexible URL
|
||||||
filexibleURL: 'https://flixable.com/title/',
|
filexibleURL: 'https://flixable.com/title/',
|
||||||
// Tmdb URL
|
// Tmdb URL
|
||||||
theMovieDbURL: 'https://api.themoviedb.org/3/find/'
|
theMovieDbURL: 'https://api.themoviedb.org/3/',
|
||||||
}
|
// Tmdb image URL
|
||||||
module.exports = config;
|
theMovieDbImageURL: 'https://image.tmdb.org/t/p/original/',
|
||||||
|
}
|
||||||
|
module.exports = config;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const GetFlix = require('../index');
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const getflix = new GetFlix('f29e56ff85f361ff01b5c5403a343021');
|
const getflix = new GetFlix('f29e56ff85f361ff01b5c5403a343021');
|
||||||
getflix.getInfo('70143836', (res) => {
|
getflix.getInfo('70242311', (res) => {
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
console.log(res.errorMsg);
|
console.log(res.errorMsg);
|
||||||
}
|
}
|
||||||
@@ -14,4 +14,3 @@ try {
|
|||||||
catch (error) {
|
catch (error) {
|
||||||
console.log(error.message)
|
console.log(error.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
98
lib/index.js
98
lib/index.js
@@ -3,6 +3,8 @@ const cheerio = require('cheerio');
|
|||||||
const request = require('request');
|
const request = require('request');
|
||||||
// Config
|
// Config
|
||||||
const config = require('../config');
|
const config = require('../config');
|
||||||
|
// Modules
|
||||||
|
const modules = require('./module');
|
||||||
|
|
||||||
class FlixInfo {
|
class FlixInfo {
|
||||||
|
|
||||||
@@ -20,13 +22,12 @@ class FlixInfo {
|
|||||||
const theMovieDbURL = config.theMovieDbURL;
|
const theMovieDbURL = config.theMovieDbURL;
|
||||||
// API Key
|
// API Key
|
||||||
const tmdbApiKey = this.tmdbApiKey;
|
const tmdbApiKey = this.tmdbApiKey;
|
||||||
|
// Result Object
|
||||||
var returnResult = {};
|
var returnResult = {};
|
||||||
|
|
||||||
request(flixableURL, (err, response, body) => {
|
request(flixableURL, (err, response, body) => {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
returnResult = { error: 1, errorMsg: 'flixable.com error' };
|
returnResult = { error: 1, errorMsg: 'flixable.com connection error' };
|
||||||
cb(returnResult)
|
cb(returnResult)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -41,62 +42,71 @@ class FlixInfo {
|
|||||||
$('[class="imdbRatingPlugin"]').each(function (i, element) {
|
$('[class="imdbRatingPlugin"]').each(function (i, element) {
|
||||||
|
|
||||||
const imdbId = $(this).attr('data-title');
|
const imdbId = $(this).attr('data-title');
|
||||||
const tmdbURL = theMovieDbURL + imdbId + '?api_key=' + tmdbApiKey + '&language=en-EN&external_source=imdb_id'
|
|
||||||
|
const tmdbURL = theMovieDbURL + 'find/' + imdbId + '?api_key=' + tmdbApiKey + '&language=en-EN&external_source=imdb_id'
|
||||||
|
|
||||||
request(tmdbURL, (err, resultBody, body) => {
|
request(tmdbURL, (err, resultBody, body) => {
|
||||||
|
|
||||||
const getJson = JSON.parse(resultBody.body);
|
const getJson = JSON.parse(resultBody.body);
|
||||||
|
|
||||||
if(getJson.status_code > 1){
|
if (getJson.status_code > 1) {
|
||||||
// if wrong api key error
|
// if wrong api key error
|
||||||
returnResult = { error: 1, errorMsg: 'tmdb wrong api key error' };
|
returnResult = { error: 1, errorMsg: 'tmdb find id wrong api key error' };
|
||||||
cb(returnResult)
|
cb(returnResult)
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
// if thmdb api connection error
|
// if thmdb api connection error
|
||||||
returnResult = { error: 1, errorMsg: 'tmdb api error' };
|
returnResult = { error: 1, errorMsg: 'tmdb find id connection api error' };
|
||||||
cb(returnResult)
|
cb(returnResult)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (getJson.tv_results.length) {
|
if (getJson.tv_results.length || getJson.movie_results.length) {
|
||||||
// If result is tv
|
|
||||||
var result = getJson.tv_results[0];
|
if (getJson.movie_results.length) {
|
||||||
var originalName = result.original_name;
|
var watchParameter = 'movie';
|
||||||
var name = result.name;
|
var thmdbId = getJson.movie_results[0].id;
|
||||||
var year = result.first_air_date;
|
|
||||||
if (result.poster_path != null) {
|
|
||||||
var poster = 'https://image.tmdb.org/t/p/original/' + result.poster_path;
|
|
||||||
}
|
}
|
||||||
if (result.poster_path != null) {
|
else if (getJson.tv_results.length) {
|
||||||
var backdrop = 'https://image.tmdb.org/t/p/original/' + result.backdrop_path;
|
var watchParameter = 'tv';
|
||||||
|
var thmdbId = getJson.tv_results[0].id;
|
||||||
}
|
}
|
||||||
var country = result.origin_country[0];
|
// Get detail info
|
||||||
var rate = result.vote_average;
|
modules.getDetails(thmdbId, watchParameter, tmdbApiKey, (err, getDetailResult) => {
|
||||||
var overviewEN = result.overview;
|
if (err) {
|
||||||
|
returnResult = { error: 1, errorMsg: err };
|
||||||
|
cb(returnResult);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Get credits info
|
||||||
|
modules.getCredits(thmdbId, watchParameter, tmdbApiKey, (err, getCreditsResult) => {
|
||||||
|
if (err) {
|
||||||
|
returnResult = { error: 1, errorMsg: err };
|
||||||
|
cb(returnResult);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Get images info
|
||||||
|
modules.getImages(thmdbId, watchParameter, tmdbApiKey, (err, getImagesResult) => {
|
||||||
|
if (err) {
|
||||||
|
returnResult = { error: 1, errorMsg: err };
|
||||||
|
cb(returnResult);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
returnResult = { result: 1, error: 0, tv_results: getDetailResult, credits: getCreditsResult, images: getImagesResult };
|
||||||
|
cb(returnResult);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else if (getJson.movie_results.length) {
|
else {
|
||||||
// If result is movie
|
// Return the error if imdb id cannot be found
|
||||||
var result = getJson.movie_results[0];
|
const returnResult = { result: 0, error: 0 };
|
||||||
var originalName = result.original_title;
|
cb(returnResult)
|
||||||
var name = result.title;
|
|
||||||
var year = result.release_date;
|
|
||||||
if (result.poster_path != null) {
|
|
||||||
var poster = 'https://image.tmdb.org/t/p/original/' + result.poster_path;
|
|
||||||
}
|
|
||||||
if (result.poster_path != null) {
|
|
||||||
var backdrop = 'https://image.tmdb.org/t/p/original/' + result.backdrop_path;
|
|
||||||
}
|
|
||||||
var country = result.original_language;
|
|
||||||
var rate = result.vote_average;
|
|
||||||
var overviewEN = result.overview;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
returnResult = { result: 1, error: 0, originalName, name, year, poster, backdrop, country, rate, overviewEN };
|
|
||||||
// If there is no error return the result
|
|
||||||
cb(returnResult);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
119
lib/module.js
Normal file
119
lib/module.js
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
const config = require('../config');
|
||||||
|
const request = require('request');
|
||||||
|
|
||||||
|
module.exports.getDetails = function (detailsId, movieOrTv, tmdbApiKey, cb) {
|
||||||
|
|
||||||
|
if (movieOrTv == 'movie' || movieOrTv == 'tv') {
|
||||||
|
|
||||||
|
const detailURL = config.theMovieDbURL + movieOrTv + '/' + detailsId + '?api_key=' + tmdbApiKey + '&language=en-US';
|
||||||
|
|
||||||
|
request(detailURL, (err, resultBody, body) => {
|
||||||
|
|
||||||
|
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 wrong watch parameter';
|
||||||
|
const result = null;
|
||||||
|
cb(error, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.getCredits = function (detailsId, movieOrTv, tmdbApiKey, cb) {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const error = null;
|
||||||
|
const result = getJson;
|
||||||
|
cb(error, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const error = 'tmdb get credits 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) => {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const error = 'tmdb get images wrong watch parameter';
|
||||||
|
const result = null;
|
||||||
|
cb(error, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user