Skip to content

Commit d96c698

Browse files
committed
Merge branch 'release/1.0.5'
2 parents 4767573 + 07efc01 commit d96c698

File tree

5 files changed

+220
-244
lines changed

5 files changed

+220
-244
lines changed

.gitlab-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ stages:
66

77
before_script:
88
- export GITHUB_TOKEN="$GITHUB_TOKEN"
9-
- npm install -g github-release-cli
109

1110
deploy:npm:
1211
stage: deploy
@@ -25,4 +24,5 @@ release:github:
2524
only:
2625
- tags
2726
script:
27+
- npm install -g github-release-cli
2828
- github-release upload --owner="$GITHUB_USER" --repo=faparser --tag="$CI_COMMIT_TAG" --name="$CI_COMMIT_TAG" --body="Release $CI_COMMIT_TAG"

faparser.js

+57-48
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var parser = require('./parser')
2-
var requestfa = require('./requestfa')
3-
var Promise = require('promise')
1+
const parser = require('./parser')
2+
const requestfa = require('./requestfa')
3+
const Promise = require('promise')
44

55
module.exports = {
66
film: film,
@@ -13,33 +13,34 @@ module.exports = {
1313
CAST: 'CAST'
1414
}
1515

16-
function search(data){
17-
return new Promise(function(resolve, reject){
18-
var now = new Date()
16+
function search(data) {
17+
return new Promise(function (resolve, reject) {
18+
const now = new Date()
1919
data.isFilm = false
20-
requestfa.FArequest(data).then(function(res){
20+
requestfa.FArequest(data).then(function (res) {
2121
res.lang = data.lang
2222
res.type = data.type
23-
var result = parser.parseSearch(res)
24-
var diff = new Date().getTime() - now.getTime()
25-
console.log('Process time: '+diff+'ms succesfully for data: '+JSON.stringify(data)+' with result count: '+result.result.length)
23+
const result = parser.parseSearch(res)
24+
log(now, data, result.result)
2625
return resolve(result)
27-
}).catch(function(error){
28-
console.log(error)
29-
var diff = new Date().getTime() - now.getTime()
30-
console.log('Process time: '+diff+'ms for data: '+JSON.stringify(data)+' with error: '+error)
31-
return reject(error)
26+
}).catch(function (error) {
27+
console.error('[' + new Date() + '] faparser: ' + JSON.stringify(error))
28+
log(now, data, {error: error})
29+
return reject({
30+
code: error.code,
31+
error: error.error
32+
})
3233
})
3334
})
3435
}
3536

36-
function preview(data){
37-
return new Promise(function(resolve, reject){
38-
var now = new Date()
37+
function preview(data) {
38+
return new Promise(function (resolve, reject) {
39+
const now = new Date()
3940
data.isFilm = true
40-
requestfa.FArequest(data).then(function(result){
41-
var film = parser.parseFilm(result)
42-
var filmResult = {
41+
requestfa.FArequest(data).then(function (result) {
42+
const film = parser.parseFilm(result)
43+
const filmResult = {
4344
id: data.id,
4445
url: film.url,
4546
thumbnail: film.imageUrlMed.replace("mmed", "msmall"),
@@ -48,62 +49,70 @@ function preview(data){
4849
directors: film.directors,
4950
cast: film.cast,
5051
country: film.country,
51-
rating: data.lang == 'es' && film.rating?film.rating.replace('.',','):film.rating,
52+
rating: film.rating ? film.rating.replace(',', '.') : 0,
5253
votes: film.votes
5354
}
54-
var diff = new Date().getTime() - now.getTime()
55-
console.log('Process time: '+diff+'ms succesfully for preview data: '+JSON.stringify(data)+' with film title: '+film.title)
55+
log(now, data, film)
5656
return resolve(filmResult)
57-
}).catch(function(e){
58-
return reject(e)
57+
}).catch(function (error) {
58+
console.error('[' + new Date() + '] faparser: ' + JSON.stringify(error))
59+
log(now, data, {error: error})
60+
return reject({
61+
code: error.code,
62+
error: error.error
63+
})
5964
})
6065
})
6166
}
6267

63-
function film(data){
68+
function film(data) {
6469
return new Promise(function (resolve, reject) {
65-
var now = new Date()
70+
const now = new Date()
6671
data.isFilm = true
67-
filmTaskPromise(data).then(function(film){
68-
var diff = new Date().getTime() - now.getTime()
69-
console.log('Process time: '+diff+'ms succesfully for data: '+JSON.stringify(data)+' with film title: '+film.title)
72+
filmTaskPromise(data).then(function (film) {
73+
log(now, data, film)
7074
return resolve(film)
71-
}).catch(function(error){
72-
console.log(error)
73-
var diff = new Date().getTime() - now.getTime()
74-
console.log('Process time: '+diff+'ms for data: '+JSON.stringify(data)+' with error: '+error)
75-
return reject(error)
75+
}).catch(function (error) {
76+
console.error('[' + new Date() + '] faparser: ' + JSON.stringify(error))
77+
log(now, data, {error: error})
78+
return reject({
79+
code: error.code,
80+
error: error.error
81+
})
7682
})
7783
})
7884
}
7985

80-
function filmTaskPromise(data){
81-
return new Promise(function(resolve, reject){
82-
var f = data
83-
var t = clone(data)
86+
function filmTaskPromise(data) {
87+
return new Promise(function (resolve, reject) {
88+
const f = data
89+
const t = clone(data)
8490
t.isFilm = false
8591
t.type = 'TRAILERS'
86-
var i = clone(data)
92+
const i = clone(data)
8793
i.isFilm = false
8894
i.type = 'IMAGES'
89-
var r = clone(data)
95+
const r = clone(data)
9096
r.isFilm = false
9197
r.type = 'PRO_REVIEWS'
9298

9399
Promise.all([requestfa.FArequest(f), requestfa.FArequest(i), requestfa.FArequest(t), requestfa.FArequest(r)])
94-
.then(function(result){
95-
var film = parser.parseFilm(result[0])
100+
.then(function (result) {
101+
const film = parser.parseFilm(result[0])
96102
film.id = data.id
97103
film.images = parser.parseImages(result[1])
98104
film.trailers = parser.parseTrailers(result[2])
99105
film.proReviews = parser.parseProReviews(result[3])
100106
return resolve(film)
101-
}).catch(function(error){
102-
return reject(error)
103-
})
107+
}).catch(reject)
104108
})
105109
}
106110

107-
function clone(o){
111+
function clone(o) {
108112
return JSON.parse(JSON.stringify(o))
113+
}
114+
115+
function log(now, data, response) {
116+
const diff = new Date().getTime() - now.getTime()
117+
console.info('[' + new Date() + '] faparser: ' + 'Process time: ' + diff + 'ms for request data: ' + JSON.stringify(data) + ' with response: ' + JSON.stringify(response))
109118
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "faparser",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Parser for Filmaffinity site",
55
"main": "faparser.js",
66
"scripts": {

0 commit comments

Comments
 (0)