search with location on flixinfo

This commit is contained in:
Wise Colt
2020-04-26 13:25:41 +03:00
parent 08c834e54f
commit 5c22d7da50
2 changed files with 50 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
var config = { var config = {
// Filexible URL // Filexible URL
filexibleURL: 'https://tr.flixable.com/title/', filexibleTrURL: 'https://tr.flixable.com/title/',
filexibleGlobalURL: 'https://flixable.com/title/',
// Tmdb URL // Tmdb URL
theMovieDbURL: 'https://api.themoviedb.org/3/', theMovieDbURL: 'https://api.themoviedb.org/3/',
// Tmdb image URL // Tmdb image URL

View File

@@ -16,13 +16,16 @@ class FlixInfo {
/** /**
* Get movie/show info * Get movie/show info
* @param {number} netflixId * @param {number} netflixId Aranan netflix içeriğine ait id bilgisi girilir
* @param {string} theMovieDbLanguage The Movie DB Api de hangi dilde arama yapılacağı girilir (e.g. tr-TR)
* @param {string} netflixLocation flixinfo üzerinde hangi lokasyonda sorgulama yapılacağı girilir (e.g. tr -> tr.flixinfo.com)
* @description Netflix içeriğinde id bilgisine ve netflix lokasyonuna göre arama yapmayı sağlar
* @return {JSON} * @return {JSON}
*/ */
get(netflixId, language) { get(netflixId, theMovieDbLanguage, netflixLocation) {
// Imdb id page // Imdb id page
const flixableURL = config.filexibleURL + netflixId; const flixableURL = netflixLocation == 'tr' ? (config.filexibleTrURL + netflixId) : (config.filexibleGlobalURL + netflixId);
// The Movie DB api page // The Movie DB api page
const theMovieDbURL = config.theMovieDbURL; const theMovieDbURL = config.theMovieDbURL;
@@ -57,22 +60,39 @@ class FlixInfo {
if (netflixButton != null) { if (netflixButton != null) {
const findTitle = ($($('[property="og:title"]')).attr('content'));
const splitString = findTitle.split("-"); const findImdb = ($($('[class="mb-2 rating-container"]')).attr());
const title = splitString[0].split("(")[0].trim(); const type = netflixLocation == 'tr' ? (body.search("Sezon") > 0 ? 'tv' : 'movie') : (body.search("Season") > 0 ? 'tv' : 'movie');
const year = splitString[0].split("(")[1].split(")")[0].trim(); console.log(type);
const type = body.search("Sezon") > 0 ? 'tv' : 'movie';
const netflixOverview = ($($('[name="description"]')).attr('content')); const netflixOverview = ($($('[name="description"]')).attr('content'));
const netflixPoster = ($($('[class="img lazyload poster"]')).attr('data-src')); const netflixPoster = ($($('[class="img lazyload poster"]')).attr('data-src'));
let tmdbURL
if (theMovieDbLanguage) {
if (language) { // Sayfada imdb id varsa, tmdb üzerinden imdb id'ye göre arama yapılır
// create (find) tmdb api url if (findImdb) {
const tmdbURL = theMovieDbURL + 'search/' + type + '?api_key=' + tmdbApiKey + '&language=' + language + '&query=' + title + '&first_air_date_year=' + year; const imdbId = ($($('[class="imdbRatingPlugin"]')).attr('data-title'));
tmdbURL = theMovieDbURL + 'find/' + imdbId + '?api_key=' + tmdbApiKey + '&language=' + theMovieDbLanguage + '&external_source=imdb_id';
}
// Sayfada imdb id yoksa, tmdb üzerinden title ve year'a göre arama yapılır
else {
const findTitle = ($($('[property="og:title"]')).attr('content'));
const splitString = findTitle.split("- Netflix");
const title = splitString[0].split("(")[0].trim();
const year = splitString[0].split("(")[1].split(")")[0].trim();
// create (find) tmdb api url
tmdbURL = theMovieDbURL + 'search/' + type + '?api_key=' + tmdbApiKey + '&language=' + theMovieDbLanguage + '&query=' + title + '&first_air_date_year=' + year;
}
console.log(tmdbURL);
request(encodeURI(tmdbURL), (err, resultBody, body) => { request(encodeURI(tmdbURL), (err, resultBody, body) => {
// Api find all result (for get tmdb id) // Api find all result (for get tmdb id)
const getJson = JSON.parse(resultBody.body); const getJson = JSON.parse(resultBody.body);
if (getJson.status_code > 1) { if (getJson.status_code > 1) {
@@ -89,13 +109,23 @@ class FlixInfo {
} }
else { else {
// if tmdb api result not empty let result;
if (getJson.results.length) {
const thmdbId = getJson.results[0].id; if(findImdb){
result = type == 'movie' ? getJson.movie_results : getJson.tv_results
console.log(result);
}else{
result = getJson.results
}
// if tmdb api result not empty
if (result.length) {
const thmdbId = result[0].id;
// Get detail info // Get detail info
modules.getDetails(thmdbId, type, tmdbApiKey, language, (err, getDetailResult) => { modules.getDetails(thmdbId, type, tmdbApiKey, theMovieDbLanguage, (err, getDetailResult) => {
if (err) { if (err) {
returnResult = { error: 1, errorMsg: err }; returnResult = { error: 1, errorMsg: err };
@@ -136,14 +166,14 @@ class FlixInfo {
} }
else { else {
// Return the empty result if tmdb return empty // Return the empty result if tmdb return empty
const returnResult = { result: 0, error: 0, msg: 'tmdb api return is empty' }; const returnResult = { result: 0, error: 1, msg: 'tmdb api return is empty' };
reject(returnResult) reject(returnResult)
} }
} }
} }
}); });
} else { } else {
returnResult = { error: 1, errorMsg: 'anguage parameters not found.' }; returnResult = { error: 1, errorMsg: 'language parameters not found.' };
reject(returnResult) reject(returnResult)
} }
} }