diff --git a/config/index.js b/config/index.js index 0be01be..8c22aef 100644 --- a/config/index.js +++ b/config/index.js @@ -1,6 +1,7 @@ var config = { // Filexible URL - filexibleURL: 'https://tr.flixable.com/title/', + filexibleTrURL: 'https://tr.flixable.com/title/', + filexibleGlobalURL: 'https://flixable.com/title/', // Tmdb URL theMovieDbURL: 'https://api.themoviedb.org/3/', // Tmdb image URL diff --git a/lib/index.js b/lib/index.js index 293adfe..06c85f3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -16,13 +16,16 @@ class FlixInfo { /** * 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} */ - get(netflixId, language) { + get(netflixId, theMovieDbLanguage, netflixLocation) { // Imdb id page - const flixableURL = config.filexibleURL + netflixId; + const flixableURL = netflixLocation == 'tr' ? (config.filexibleTrURL + netflixId) : (config.filexibleGlobalURL + netflixId); // The Movie DB api page const theMovieDbURL = config.theMovieDbURL; @@ -57,22 +60,39 @@ class FlixInfo { if (netflixButton != null) { - 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 findImdb = ($($('[class="mb-2 rating-container"]')).attr()); + const type = netflixLocation == 'tr' ? (body.search("Sezon") > 0 ? 'tv' : 'movie') : (body.search("Season") > 0 ? 'tv' : 'movie'); + console.log(type); + const netflixOverview = ($($('[name="description"]')).attr('content')); const netflixPoster = ($($('[class="img lazyload poster"]')).attr('data-src')); + let tmdbURL + if (theMovieDbLanguage) { - if (language) { - // create (find) tmdb api url - const tmdbURL = theMovieDbURL + 'search/' + type + '?api_key=' + tmdbApiKey + '&language=' + language + '&query=' + title + '&first_air_date_year=' + year; + // Sayfada imdb id varsa, tmdb üzerinden imdb id'ye göre arama yapılır + if (findImdb) { + 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) => { // Api find all result (for get tmdb id) - + const getJson = JSON.parse(resultBody.body); if (getJson.status_code > 1) { @@ -89,13 +109,23 @@ class FlixInfo { } else { - // if tmdb api result not empty - if (getJson.results.length) { + let result; - 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 - modules.getDetails(thmdbId, type, tmdbApiKey, language, (err, getDetailResult) => { + modules.getDetails(thmdbId, type, tmdbApiKey, theMovieDbLanguage, (err, getDetailResult) => { if (err) { returnResult = { error: 1, errorMsg: err }; @@ -136,14 +166,14 @@ class FlixInfo { } else { // 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) } } } }); } else { - returnResult = { error: 1, errorMsg: 'anguage parameters not found.' }; + returnResult = { error: 1, errorMsg: 'language parameters not found.' }; reject(returnResult) } }