Skip to content

Commit

Permalink
Merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
aespinilla committed Sep 9, 2021
2 parents eac720a + 3d177df commit b555813
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "faparser",
"version": "1.1.0",
"version": "1.1.1",
"description": "Parser for Filmaffinity site",
"main": "src/faparser.js",
"scripts": {
Expand Down Expand Up @@ -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"
}
}
4 changes: 2 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
46 changes: 24 additions & 22 deletions src/requestfa.js
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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) {
Expand Down

0 comments on commit b555813

Please sign in to comment.