add google search
This commit is contained in:
@@ -3,7 +3,7 @@ const getflix = new GetFlix('d9d6007d1bcf12043db5a085ae3e5bbb');
|
|||||||
|
|
||||||
getInfo = async () => {
|
getInfo = async () => {
|
||||||
try {
|
try {
|
||||||
const info = await getflix.getNetflixInfo(81082225, 'en-EN', 'en');
|
const info = await getflix.getNetflixInfo(81151514, 'en-EN', 'tr');
|
||||||
console.log(info);
|
console.log(info);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|||||||
71
lib/index.js
71
lib/index.js
@@ -6,37 +6,6 @@ const config = require('../config');
|
|||||||
// Modules
|
// Modules
|
||||||
const modules = require('./module');
|
const modules = require('./module');
|
||||||
|
|
||||||
process.setMaxListeners(0)
|
|
||||||
|
|
||||||
// imdb.com adresine bağlanarak imdb id'sinin geçerliliğini sorgulamayı sağlayan method
|
|
||||||
const imdbIdReal = async (flixableFindImdbId) => {
|
|
||||||
|
|
||||||
const imdbIdURL = "https://www.imdb.com/title/" + flixableFindImdbId
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
request(imdbIdURL, (error, response, body) => {
|
|
||||||
if (error) {
|
|
||||||
reject('imdb id alinirken hata olustu')
|
|
||||||
} else {
|
|
||||||
const $ = cheerio.load(body, {
|
|
||||||
normalizeWhitespace: true,
|
|
||||||
xmlMode: true
|
|
||||||
});
|
|
||||||
const imdbId = ($($('[property="pageId"]')).attr('content'));
|
|
||||||
const imdbRate = /<span itemprop="ratingValue">(.*?)<\/span>/img.exec(body)[1]
|
|
||||||
if (imdbId == undefined) {
|
|
||||||
reject('imdb id bulunamadi')
|
|
||||||
} else {
|
|
||||||
resolve({
|
|
||||||
id: imdbId,
|
|
||||||
rate: imdbRate
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
class FlixInfo {
|
class FlixInfo {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,7 +109,7 @@ class FlixInfo {
|
|||||||
if (theMovieDbLanguage) {
|
if (theMovieDbLanguage) {
|
||||||
// Sayfada imdb id varsa, tmdb üzerinden imdb id'ye göre arama yapılır
|
// Sayfada imdb id varsa, tmdb üzerinden imdb id'ye göre arama yapılır
|
||||||
if (findFlixableImdbId) {
|
if (findFlixableImdbId) {
|
||||||
const imdb = await imdbIdReal(findFlixableImdbId)
|
const imdb = await modules.getRealImdbId(findFlixableImdbId)
|
||||||
imdbId = imdb.id
|
imdbId = imdb.id
|
||||||
imdbRate = imdb.rate
|
imdbRate = imdb.rate
|
||||||
tmdbURL = theMovieDbURL + 'find/' + imdbId + '?api_key=' + tmdbApiKey + '&language=' + theMovieDbLanguage + '&external_source=imdb_id';
|
tmdbURL = theMovieDbURL + 'find/' + imdbId + '?api_key=' + tmdbApiKey + '&language=' + theMovieDbLanguage + '&external_source=imdb_id';
|
||||||
@@ -171,7 +140,6 @@ class FlixInfo {
|
|||||||
|
|
||||||
if (imdbId) {
|
if (imdbId) {
|
||||||
result = type == 'movie' ? getJson.movie_results : getJson.tv_results
|
result = type == 'movie' ? getJson.movie_results : getJson.tv_results
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = getJson.results
|
result = getJson.results
|
||||||
}
|
}
|
||||||
@@ -179,17 +147,11 @@ class FlixInfo {
|
|||||||
// if tmdb api result not empty
|
// if tmdb api result not empty
|
||||||
if (result.length) {
|
if (result.length) {
|
||||||
|
|
||||||
const thmdbId = result[0].id;
|
const tmdbId = result[0].id;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get detail info
|
// set tmdb info
|
||||||
const getDetailResult = await modules.getTmdbDetails('details', thmdbId, type, tmdbApiKey, theMovieDbLanguage)
|
const { google_search, details, credits, images, trailers } = await modules.setTmdbAllInfos(false, tmdbId, type, tmdbApiKey, theMovieDbLanguage)
|
||||||
// Get credits info
|
|
||||||
const getCreditsResult = await modules.getTmdbDetails('credits', thmdbId, type, tmdbApiKey)
|
|
||||||
// Get images info
|
|
||||||
const getImagesResult = await modules.getTmdbDetails('images', thmdbId, type, tmdbApiKey)
|
|
||||||
// Get trailers
|
|
||||||
const getTrailersResult = await modules.getTmdbDetails('trailers', thmdbId, type, tmdbApiKey)
|
|
||||||
|
|
||||||
// Result Object
|
// Result Object
|
||||||
result = {
|
result = {
|
||||||
@@ -198,7 +160,7 @@ class FlixInfo {
|
|||||||
watch: type,
|
watch: type,
|
||||||
imdb: {
|
imdb: {
|
||||||
// imdb üzerinden id alınamadıysa tmdb üzerinden alınmaya çalışılır. tmdb'de de yoksa null döner
|
// imdb üzerinden id alınamadıysa tmdb üzerinden alınmaya çalışılır. tmdb'de de yoksa null döner
|
||||||
id: (imdbId != null ? imdbId : (getDetailResult.imdb_id != undefined ? getDetailResult.imdb_id : null)),
|
id: (imdbId != null ? imdbId : (details.imdb_id != undefined ? details.imdb_id : null)),
|
||||||
rate: imdbRate
|
rate: imdbRate
|
||||||
},
|
},
|
||||||
netflix: {
|
netflix: {
|
||||||
@@ -213,10 +175,11 @@ class FlixInfo {
|
|||||||
cast: netflixCast
|
cast: netflixCast
|
||||||
},
|
},
|
||||||
tmdb: {
|
tmdb: {
|
||||||
details: getDetailResult,
|
google_search,
|
||||||
credits: getCreditsResult,
|
details,
|
||||||
images: getImagesResult,
|
credits,
|
||||||
trailers: getTrailersResult
|
images,
|
||||||
|
trailers
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
resolve(result);
|
resolve(result);
|
||||||
@@ -225,6 +188,18 @@ class FlixInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
let tmdbInfo = null
|
||||||
|
// Imdb id verisi yoksa (title ve year bilgisine göre arama yapılmışsa) ve Oyuncu bilgisi varsa google ile arama yap
|
||||||
|
// Oyuncu bilgisi yoksa arama yapılmaz ve tmdb null olarak döner
|
||||||
|
if (!findFlixableImdbId && netflixCast != []) {
|
||||||
|
try {
|
||||||
|
// google arama sonucu veri döndüyse tmdb infoyu doldur
|
||||||
|
tmdbInfo = await modules.searchGoogleForTmdbId(type, netflixTitle, netflixYear, netflixCast, theMovieDbLanguage, tmdbApiKey)
|
||||||
|
} catch (error) {
|
||||||
|
// console.log('Google Search Warning: ' + error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Tmdb verisi yoksa sadece netflix verisi döndür
|
// Tmdb verisi yoksa sadece netflix verisi döndür
|
||||||
result = {
|
result = {
|
||||||
result: 1,
|
result: 1,
|
||||||
@@ -244,7 +219,7 @@ class FlixInfo {
|
|||||||
genres: netflixGenres,
|
genres: netflixGenres,
|
||||||
cast: netflixCast
|
cast: netflixCast
|
||||||
},
|
},
|
||||||
tmdb: null
|
tmdb: tmdbInfo
|
||||||
};
|
};
|
||||||
resolve(result);
|
resolve(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,40 @@
|
|||||||
const config = require('../config');
|
// Dependencies
|
||||||
|
const cheerio = require('cheerio');
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
|
// Configs
|
||||||
|
const config = require('../config');
|
||||||
|
|
||||||
module.exports.getTmdbDetails = function (getParamaters, thmdbId, type, tmdbApiKey, language) {
|
// imdb.com adresine bağlanarak imdb id'sinin geçerliliğini sorgulamayı sağlayan method
|
||||||
|
const getRealImdbId = (flixableFindImdbId) => {
|
||||||
|
|
||||||
|
const imdbIdURL = "https://www.imdb.com/title/" + flixableFindImdbId
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
request(imdbIdURL, (error, response, body) => {
|
||||||
|
if (error) {
|
||||||
|
reject('imdb id alinirken hata olustu')
|
||||||
|
} else {
|
||||||
|
const $ = cheerio.load(body, {
|
||||||
|
normalizeWhitespace: true,
|
||||||
|
xmlMode: true
|
||||||
|
});
|
||||||
|
const imdbId = ($($('[property="pageId"]')).attr('content'));
|
||||||
|
const imdbRate = /<span itemprop="ratingValue">(.*?)<\/span>/img.exec(body)[1]
|
||||||
|
if (imdbId == undefined) {
|
||||||
|
reject('imdb id bulunamadi')
|
||||||
|
} else {
|
||||||
|
resolve({
|
||||||
|
id: imdbId,
|
||||||
|
rate: imdbRate
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// The Movie DB Api'ye istek atar
|
||||||
|
const getTmdbDetails = (getParamaters, thmdbId, type, tmdbApiKey, language) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
if (type == 'movie' || type == 'tv') {
|
if (type == 'movie' || type == 'tv') {
|
||||||
@@ -52,3 +85,53 @@ module.exports.getTmdbDetails = function (getParamaters, thmdbId, type, tmdbApiK
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setTmdbAllInfos = async (googleSearch, tmdbId, type, tmdbApiKey, theMovieDbLanguage) => {
|
||||||
|
// Get detail info
|
||||||
|
const details = await getTmdbDetails('details', tmdbId, type, tmdbApiKey, theMovieDbLanguage)
|
||||||
|
// Get credits info
|
||||||
|
const credits = await getTmdbDetails('credits', tmdbId, type, tmdbApiKey)
|
||||||
|
// Get images info
|
||||||
|
const images = await getTmdbDetails('images', tmdbId, type, tmdbApiKey)
|
||||||
|
// Get trailers
|
||||||
|
const trailers = await getTmdbDetails('trailers', tmdbId, type, tmdbApiKey)
|
||||||
|
|
||||||
|
return { google_search: googleSearch, details, credits, images, trailers }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tmdb Api'de title ve year bilgilerine göre yapılan aramada sonuç bulunamazsa, netflixTitle, netflixYear, netflixCast
|
||||||
|
// bilgileri ile google'da arama yapar. Bu arama sonucunda tmdb id bilgisine ulaşır.
|
||||||
|
const searchGoogleForTmdbId = (type, netflixTitle, netflixYear, netflixCast, theMovieDbLanguage, tmdbApiKey) => {
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
const searchUrl = "https://www.google.com/search?q=" + netflixTitle + " " + netflixYear + " " + netflixCast[0] + " " + "themoviedb.org&ie=UTF-8"
|
||||||
|
|
||||||
|
request(encodeURI(searchUrl), async (error, response, body) => {
|
||||||
|
|
||||||
|
if (body) {
|
||||||
|
const $ = cheerio.load(body, {
|
||||||
|
normalizeWhitespace: true,
|
||||||
|
xmlMode: true
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
const tmdbIdFind = (/\/url\?q\=https\:\/\/www.themoviedb.org\/(.*?)&/img.exec(body)[1]).split("/")[1]
|
||||||
|
const tmdbId = /\d+/g.exec(tmdbIdFind)[0]
|
||||||
|
|
||||||
|
// tmdb info ayarlandı
|
||||||
|
resolve(await setTmdbAllInfos(true, tmdbId, type, tmdbApiKey, theMovieDbLanguage))
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
reject('themoviedb id not found')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// google arama sonucu hatalıysa
|
||||||
|
reject('themoviedb id not found')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { getTmdbDetails, getRealImdbId, setTmdbAllInfos, searchGoogleForTmdbId }
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "flixinfo",
|
"name": "flixinfo",
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"description": "Get movie detail with netflix id",
|
"description": "Get movie detail with netflix id",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
|
|||||||
Reference in New Issue
Block a user