flixable upgrade
This commit is contained in:
36
lib/index.js
36
lib/index.js
@@ -6,7 +6,6 @@ const config = require('../config');
|
||||
// Modules
|
||||
const modules = require('./module');
|
||||
|
||||
|
||||
class FlixInfo {
|
||||
|
||||
constructor(opt = '') {
|
||||
@@ -57,11 +56,20 @@ class FlixInfo {
|
||||
|
||||
|
||||
if (netflixButton != null) {
|
||||
|
||||
const imdbId = ($($('[class="imdbRatingPlugin"]')).attr('data-title'));
|
||||
const findTitle = ($($('[property="og:title"]')).attr('content'));
|
||||
const splitString = findTitle.split("-");
|
||||
const title = splitString[0].split("(")[0].trim();
|
||||
const year = splitString[0].split("(")[1].split(")")[0].trim();
|
||||
const type = body.search("Sezon") > 0 ? 'tv' : 'movie';
|
||||
const netflixOverview = ($($('[name="description"]')).attr('content'));
|
||||
const netflixPoster = ($($('[class="img lazyload poster"]')).attr('data-src'));
|
||||
|
||||
|
||||
if (imdbId && language) {
|
||||
// create (find) tmdb api url
|
||||
const tmdbURL = theMovieDbURL + 'find/' + imdbId + '?api_key=' + tmdbApiKey + '&language=' + language + '&external_source=imdb_id';
|
||||
const tmdbURL = theMovieDbURL + 'search/' + type + '?api_key=' + tmdbApiKey + '&language=' + language + '&query=' + title + '&first_air_date_year=' + year;
|
||||
|
||||
request(tmdbURL, (err, resultBody, body) => {
|
||||
// Api find all result (for get tmdb id)
|
||||
@@ -82,18 +90,12 @@ class FlixInfo {
|
||||
else {
|
||||
|
||||
// if tmdb api result not empty
|
||||
if (getJson.tv_results.length || getJson.movie_results.length) {
|
||||
if (getJson.results.length) {
|
||||
|
||||
const thmdbId = getJson.results[0].id;
|
||||
|
||||
if (getJson.movie_results.length) {
|
||||
var watchParameter = 'movie';
|
||||
var thmdbId = getJson.movie_results[0].id;
|
||||
}
|
||||
else if (getJson.tv_results.length) {
|
||||
var watchParameter = 'tv';
|
||||
var thmdbId = getJson.tv_results[0].id;
|
||||
}
|
||||
// Get detail info
|
||||
modules.getDetails(thmdbId, watchParameter, tmdbApiKey, language, (err, getDetailResult) => {
|
||||
modules.getDetails(thmdbId, type, tmdbApiKey, language, (err, getDetailResult) => {
|
||||
|
||||
if (err) {
|
||||
returnResult = { error: 1, errorMsg: err };
|
||||
@@ -101,25 +103,27 @@ class FlixInfo {
|
||||
}
|
||||
else {
|
||||
// Get credits info
|
||||
modules.getCredits(thmdbId, watchParameter, tmdbApiKey, (err, getCreditsResult) => {
|
||||
modules.getCredits(thmdbId, type, tmdbApiKey, (err, getCreditsResult) => {
|
||||
if (err) {
|
||||
returnResult = { error: 1, errorMsg: err };
|
||||
reject(returnResult);
|
||||
}
|
||||
else {
|
||||
// Get images info
|
||||
modules.getImages(thmdbId, watchParameter, tmdbApiKey, (err, getImagesResult) => {
|
||||
modules.getImages(thmdbId, type, tmdbApiKey, (err, getImagesResult) => {
|
||||
if (err) {
|
||||
returnResult = { error: 1, errorMsg: err };
|
||||
reject(returnResult);
|
||||
}
|
||||
else {
|
||||
modules.getTrailers(thmdbId, watchParameter, tmdbApiKey, (err, getTrailersResult) => {
|
||||
modules.getTrailers(thmdbId, type, 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 };
|
||||
getDetailResult.netflixOverview = netflixOverview;
|
||||
getDetailResult.netflixPoster = netflixPoster;
|
||||
returnResult = { result: 1, error: 0, watch: type, details: getDetailResult, credits: getCreditsResult, images: getImagesResult, trailers: getTrailersResult };
|
||||
resolve(returnResult);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user