add google search
This commit is contained in:
@@ -1,7 +1,40 @@
|
||||
const config = require('../config');
|
||||
// Dependencies
|
||||
const cheerio = require('cheerio');
|
||||
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) => {
|
||||
|
||||
if (type == 'movie' || type == 'tv') {
|
||||
@@ -51,4 +84,54 @@ module.exports.getTmdbDetails = function (getParamaters, thmdbId, type, tmdbApiK
|
||||
reject('tmdb get detail wrong watch parameter');
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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 }
|
||||
Reference in New Issue
Block a user