add google search

This commit is contained in:
Wise Colt
2020-05-01 02:18:21 +03:00
parent fd58d43568
commit a6ba96aa1f
4 changed files with 112 additions and 54 deletions

View File

@@ -6,37 +6,6 @@ const config = require('../config');
// Modules
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 {
/**
@@ -140,7 +109,7 @@ class FlixInfo {
if (theMovieDbLanguage) {
// Sayfada imdb id varsa, tmdb üzerinden imdb id'ye göre arama yapılır
if (findFlixableImdbId) {
const imdb = await imdbIdReal(findFlixableImdbId)
const imdb = await modules.getRealImdbId(findFlixableImdbId)
imdbId = imdb.id
imdbRate = imdb.rate
tmdbURL = theMovieDbURL + 'find/' + imdbId + '?api_key=' + tmdbApiKey + '&language=' + theMovieDbLanguage + '&external_source=imdb_id';
@@ -149,7 +118,7 @@ class FlixInfo {
// Sayfada imdb id yoksa, tmdb üzerinden title ve year'a göre arama yapılır
tmdbURL = theMovieDbURL + 'search/' + type + '?api_key=' + tmdbApiKey + '&language=' + theMovieDbLanguage + '&query=' + netflixTitle + '&first_air_date_year=' + netflixYear;
}
request(encodeURI(tmdbURL), async (err, resultBody, body) => {
if (err) {
@@ -171,7 +140,6 @@ class FlixInfo {
if (imdbId) {
result = type == 'movie' ? getJson.movie_results : getJson.tv_results
} else {
result = getJson.results
}
@@ -179,17 +147,11 @@ class FlixInfo {
// if tmdb api result not empty
if (result.length) {
const thmdbId = result[0].id;
const tmdbId = result[0].id;
try {
// Get detail info
const getDetailResult = await modules.getTmdbDetails('details', thmdbId, 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)
// set tmdb info
const { google_search, details, credits, images, trailers } = await modules.setTmdbAllInfos(false, tmdbId, type, tmdbApiKey, theMovieDbLanguage)
// Result Object
result = {
@@ -198,7 +160,7 @@ class FlixInfo {
watch: type,
imdb: {
// 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
},
netflix: {
@@ -213,10 +175,11 @@ class FlixInfo {
cast: netflixCast
},
tmdb: {
details: getDetailResult,
credits: getCreditsResult,
images: getImagesResult,
trailers: getTrailersResult
google_search,
details,
credits,
images,
trailers
}
};
resolve(result);
@@ -225,6 +188,18 @@ class FlixInfo {
}
}
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
result = {
result: 1,
@@ -244,7 +219,7 @@ class FlixInfo {
genres: netflixGenres,
cast: netflixCast
},
tmdb: null
tmdb: tmdbInfo
};
resolve(result);
}