Skip to content

Commit b555813

Browse files
committed
Merge branch 'release/1.1.1'
2 parents eac720a + 3d177df commit b555813

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "faparser",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Parser for Filmaffinity site",
55
"main": "src/faparser.js",
66
"scripts": {
@@ -30,7 +30,7 @@
3030
},
3131
"homepage": "https://github.com/aespinilla/faparser#readme",
3232
"dependencies": {
33-
"bent": "^7.3.12",
34-
"cheerio": "1.0.0-rc.2"
33+
"cheerio": "1.0.0-rc.2",
34+
"request": "^2.88.2"
3535
}
3636
}

src/parser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function parseFilm(data) {
193193
}
194194

195195
function parseSearch(data) {
196-
const pathname = url.parse(data.url).pathname;
196+
const pathname = url.parse(data.response.request.uri.href).pathname;
197197
if (pathname.includes('film')) {
198198
const idTemp = pathname.substring(pathname.indexOf('film') + 'film'.length, pathname.indexOf('.'));
199199
data.response.lang = data.lang
@@ -203,7 +203,7 @@ function parseSearch(data) {
203203
count: 1,
204204
result: [{
205205
id: idTemp,
206-
url: data.url,
206+
url: data.response.request.uri.href,
207207
thumbnail: film.imageUrlMed.replace("mmed", "msmall"),
208208
year: film.year,
209209
title: film.title,

src/requestfa.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* Created by aespinilla on 20/6/17.
33
*/
4-
const bent = require('bent')
4+
const request = require('request')
55

66
module.exports = {
7-
FArequest: requestServer
7+
FArequest: rPromise
88
}
99

1010
const BASE_URL = "https://www.filmaffinity.com"
@@ -20,26 +20,28 @@ const searchTypes = {
2020
PRO_REVIEWS: "/pro-reviews.php?movie-id=",
2121
}
2222

23-
async function requestServer(data) {
24-
const url = computedUrl(data)
25-
const get = bent(url)
26-
try {
27-
let getResult = await get()
28-
const body = await getResult.text()
29-
return {
30-
url: url,
31-
type: data.type,
32-
isFilm: data.isFilm,
33-
lang: data.lang,
34-
body: body
35-
}
36-
} catch (error) {
37-
throw {
38-
code: error.statusCode,
39-
url: url,
40-
error: error.message
41-
}
42-
}
23+
function rPromise(data) {
24+
return new Promise(function (resolve, reject) {
25+
const url = computedUrl(data)
26+
request(url, function (error, response, body) {
27+
if (!error && response.statusCode == 200) {
28+
resolve({
29+
url: url,
30+
response: response,
31+
type: data.type,
32+
isFilm: data.isFilm,
33+
lang: data.lang,
34+
body: body
35+
})
36+
} else {
37+
reject({
38+
code: response.statusCode,
39+
url: url,
40+
error: response.error
41+
})
42+
}
43+
})
44+
})
4345
}
4446

4547
function computedUrl(data) {

0 commit comments

Comments
 (0)