diff --git a/package.json b/package.json index 8b13ad9..e66ad16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "faparser", - "version": "1.1.0", + "version": "1.1.1", "description": "Parser for Filmaffinity site", "main": "src/faparser.js", "scripts": { @@ -30,7 +30,7 @@ }, "homepage": "https://github.com/aespinilla/faparser#readme", "dependencies": { - "bent": "^7.3.12", - "cheerio": "1.0.0-rc.2" + "cheerio": "1.0.0-rc.2", + "request": "^2.88.2" } } diff --git a/src/parser.js b/src/parser.js index 0d609cd..b97edc4 100644 --- a/src/parser.js +++ b/src/parser.js @@ -193,7 +193,7 @@ function parseFilm(data) { } function parseSearch(data) { - const pathname = url.parse(data.url).pathname; + const pathname = url.parse(data.response.request.uri.href).pathname; if (pathname.includes('film')) { const idTemp = pathname.substring(pathname.indexOf('film') + 'film'.length, pathname.indexOf('.')); data.response.lang = data.lang @@ -203,7 +203,7 @@ function parseSearch(data) { count: 1, result: [{ id: idTemp, - url: data.url, + url: data.response.request.uri.href, thumbnail: film.imageUrlMed.replace("mmed", "msmall"), year: film.year, title: film.title, diff --git a/src/requestfa.js b/src/requestfa.js index ca41d86..f84e38b 100644 --- a/src/requestfa.js +++ b/src/requestfa.js @@ -1,10 +1,10 @@ /** * Created by aespinilla on 20/6/17. */ -const bent = require('bent') +const request = require('request') module.exports = { - FArequest: requestServer + FArequest: rPromise } const BASE_URL = "https://www.filmaffinity.com" @@ -20,26 +20,28 @@ const searchTypes = { PRO_REVIEWS: "/pro-reviews.php?movie-id=", } -async function requestServer(data) { - const url = computedUrl(data) - const get = bent(url) - try { - let getResult = await get() - const body = await getResult.text() - return { - url: url, - type: data.type, - isFilm: data.isFilm, - lang: data.lang, - body: body - } - } catch (error) { - throw { - code: error.statusCode, - url: url, - error: error.message - } - } +function rPromise(data) { + return new Promise(function (resolve, reject) { + const url = computedUrl(data) + request(url, function (error, response, body) { + if (!error && response.statusCode == 200) { + resolve({ + url: url, + response: response, + type: data.type, + isFilm: data.isFilm, + lang: data.lang, + body: body + }) + } else { + reject({ + code: response.statusCode, + url: url, + error: response.error + }) + } + }) + }) } function computedUrl(data) {