Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to ES6 modules #9

Open
wants to merge 59 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
5d1b938
Split requests.
aespinilla Aug 17, 2022
6597c32
Add index.js
aespinilla Aug 17, 2022
1eb30ae
Handle error on request
aespinilla Aug 17, 2022
dc0fc36
Little refactor on parser
aespinilla Aug 18, 2022
f30356b
Fix search
aespinilla Aug 18, 2022
a585b4e
Format index
aespinilla Aug 18, 2022
5a677a0
Refactor parser.
aespinilla Aug 18, 2022
820fb81
Add utils
aespinilla Aug 18, 2022
078bafc
Fix switch
aespinilla Aug 18, 2022
f39ca74
Fix search.
aespinilla Aug 18, 2022
72f5760
Remove dead code
aespinilla Aug 18, 2022
edd58cc
Split parser into functions
aespinilla Aug 18, 2022
ef841da
Split parser
aespinilla Aug 18, 2022
e543b42
Split in more functions
aespinilla Aug 18, 2022
8568a7d
Clear parser.
aespinilla Aug 18, 2022
4fbb222
Add special search parser
aespinilla Aug 19, 2022
29a537a
Add new controller
aespinilla Aug 19, 2022
a7fb09a
Add search controller.
aespinilla Aug 19, 2022
1670614
Add parsers
aespinilla Aug 19, 2022
c9296e1
Add search parser.
aespinilla Aug 19, 2022
e3536b6
Add trailers controller.
aespinilla Aug 19, 2022
56eb3a9
Add images controller
aespinilla Aug 19, 2022
0b96339
Add pro reviews controller.
aespinilla Aug 19, 2022
a91430e
Add search controller
aespinilla Aug 19, 2022
16fd5b7
Fix crashs.
aespinilla Aug 19, 2022
5a6004d
Fix minor bugs
aespinilla Aug 19, 2022
52adfc7
Add config json
aespinilla Aug 21, 2022
635d752
Add urlbuilders.
aespinilla Aug 21, 2022
0ff8be3
Clear requestfa.
aespinilla Aug 21, 2022
7f5b9ab
Use new urlbuilders on controllers.
aespinilla Aug 21, 2022
2b4fb33
Add searcontrollers url builders.
aespinilla Aug 21, 2022
7597ddd
Fix bug on build urls.
aespinilla Aug 21, 2022
e30922b
Clear
aespinilla Aug 21, 2022
b3a78f5
Fix productions.
aespinilla Aug 24, 2022
a64f6f4
Update .gitignore
aespinilla Jan 23, 2023
9c631af
- Refactor project to es6 module.
aespinilla Jan 23, 2023
13cb7e2
Refactor urlBuilder
aespinilla Jan 23, 2023
4b6a0e8
Migrate parser
aespinilla Jan 23, 2023
277f244
Migrate controller
aespinilla Jan 23, 2023
a6926d6
Migrate index
aespinilla Jan 23, 2023
e2d54aa
Update tests
aespinilla Jan 24, 2023
4ea321a
Add first github action
aespinilla Jan 24, 2023
c479999
Fix steps
aespinilla Jan 24, 2023
f932826
Set only on pull request
aespinilla Jan 24, 2023
82f3d82
Set Config as module.
aespinilla Jan 24, 2023
fd96910
Add trailers url builder test
aespinilla Jan 24, 2023
9ec3826
Add topic url builder test
aespinilla Jan 24, 2023
25e960e
Add images url builder test
aespinilla Jan 24, 2023
1c0be3a
Add semicolon
aespinilla Jan 24, 2023
eafcc89
Add genre url builder test
aespinilla Jan 24, 2023
4ea3aaf
Try set es6 module tests
aespinilla Jan 25, 2023
c95dca0
Add search url builder tests
aespinilla Jan 25, 2023
0429cb6
Add film controller tests.
aespinilla Jan 25, 2023
980cff3
Add utils module and tests.
aespinilla Jan 25, 2023
1d768d8
Set beforeEach
aespinilla Jan 25, 2023
2e0faac
Add imagesController test
aespinilla Jan 25, 2023
5a04b7b
Add trailersControler test
aespinilla Jan 25, 2023
5082f60
Add proReviewController test
aespinilla Jan 25, 2023
5d81d63
Add e2e faParser test
aespinilla Jan 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"env": {
"test": {
"plugins": [
"@babel/plugin-transform-modules-commonjs"
]
}
}
}
22 changes: 22 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Node.js CI

on:
pull_request:
branches:
- master
- develop
- 'release/**'

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '19.x'
- run: npm install
- run: npm test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ node_modules/
*.DS_Store
.idea
helper.js
package-lock.json
package-lock.json
.vscode
coverage
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { search, film, types } from './src/index.js';
41 changes: 29 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@
"name": "faparser",
"version": "1.1.1",
"description": "Parser for Filmaffinity site",
"main": "src/faparser.js",
"scripts": {
"test": "\"\""
"main": "index.js",
"author": "Alberto Espinilla",
"license": "MIT",
"bugs": {
"url": "https://github.com/aespinilla/faparser/issues"
},
"homepage": "https://github.com/aespinilla/faparser#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/aespinilla/faparser.git"
"url": "https://github.com/aespinilla/faparser.git"
},
"type": "module",
"scripts": {
"test": "jest"
},
"jest": {
"collectCoverage": true,
"moduleFileExtensions": [
"js",
"jsx",
"json",
"ts",
"tsx"
]
},
"keywords": [
"filmaffinity",
Expand All @@ -23,14 +40,14 @@
"series",
"film"
],
"author": "Alberto Espinilla",
"license": "MIT",
"bugs": {
"url": "https://github.com/aespinilla/faparser/issues"
},
"homepage": "https://github.com/aespinilla/faparser#readme",
"dependencies": {
"cheerio": "1.0.0-rc.2",
"node-fetch": "^2.0"
"cheerio": "1.0.0-rc.2"
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/plugin-transform-modules-commonjs": "^7.20.11",
"@babel/preset-env": "^7.20.2",
"jest": "^28.1.3",
"supertest": "^6.2.4"
}
}
11 changes: 11 additions & 0 deletions src/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const Config = {
"BASE_URL": "https://www.filmaffinity.com",
"paths": {
"GENRE": "/moviegenre.php?genre=",
"TOPIC": "/movietopic.php?topic=",
"IMAGES": "/filmimages.php?movie_id=",
"TRAILERS": "/evideos.php?movie_id=",
"PRO_REVIEWS": "/pro-reviews.php?movie-id=",
"SEARCH": "/search.php?stype="
}
};
11 changes: 11 additions & 0 deletions src/controller/filmController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { request } from "../request/request.js";
import { filmUrlBuilder as urlBuilder } from "../urlBuilder/index.js";
import { filmParser as parse } from "../parser/index.js";

export const fetchFilm = async (data) => {
const url = urlBuilder(data);
const result = await request(url);
result.lang = data.lang;
const film = parse(result);
return { id: `${data.id}`, ...film }
}
11 changes: 11 additions & 0 deletions src/controller/imagesController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { request } from "../request/request.js";
import { imagesUrlBuilder as urlBuilder } from "../urlBuilder/index.js";
import { imagesParser as parse } from "../parser/index.js";

export const fetchImages = async (data) => {
data.type = 'IMAGES'
const url = urlBuilder(data);
const response = await request(url);
const result = parse(response);
return result;
}
5 changes: 5 additions & 0 deletions src/controller/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { fetchFilm as filmController } from './filmController.js';
export { fetchImages as imagesController } from './imagesController.js';
export { fetchProReviews as proReviewsController } from './proReviewsController.js';
export { search as searchController } from './searchController.js';
export { fetchTrailers as trailersController } from './trailersController.js';
11 changes: 11 additions & 0 deletions src/controller/proReviewsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { request } from "../request/request.js";
import { proReviewsUrlBuilder as urlBuilder } from "../urlBuilder/index.js";
import { proReviewsParser as parse } from "../parser/index.js";

export const fetchProReviews = async (data) => {
data.type = 'PRO_REVIEWS';
const url = urlBuilder(data);
const response = await request(url);
const result = parse(response);
return result;
}
81 changes: 81 additions & 0 deletions src/controller/searchController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import url from 'url';
import { request } from "../request/request.js";
import { searchUrlBuilder, genreUrlBuilder, topicUrlBuilder } from "../urlBuilder/index.js";
import { filmParser, specialSearch, searchParser } from "../parser/index.js";

export const search = async (data) => {
if (data.type === 'TOPIC') {
const result = await getTopics(data);
result.lang = data.lang;
return buildOutput(result, false);
}

if (data.type === 'GENRE') {
const result = await getGenres(data);
result.lang = data.lang;
return buildOutput(result, false);
}

const url = searchUrlBuilder(data);
const response = await request(url);
response.lang = data.lang;

if (isFilm(response.response.url)) {
const id = getId(response.response.url);
const film = filmParser(response);
const result = mapFilm(id, film);
return buildOutput([result], false);
}

const result = searchParser(response);
return buildOutput(result.result, result.hasMore);
}

const isFilm = (responseUrl) => {
const pathname = url.parse(responseUrl).pathname;
return pathname.includes('film');
}

const getId = (responseUrl) => {
const pathname = url.parse(responseUrl).pathname;
return pathname.substring(pathname.indexOf('film') + 'film'.length, pathname.indexOf('.'));
}

const getTopics = async (data) => {
const url = topicUrlBuilder(data);
return await getSpecialSearch(url);
}

const getGenres = async (data) => {
const url = genreUrlBuilder(data);
return await getSpecialSearch(url);
}

const getSpecialSearch = async (url) => {
const response = await request(url);
const result = specialSearch(response);
return result;
}

const mapFilm = (id, film) => {
return {
id: id,
url: film.url,
thumbnail: film.coverImages.imageUrlMed.replace("mmed", "msmall"),
year: film.year,
title: film.titles.title,
directors: film.directors,
cast: film.cast,
country: film.country,
rating: film.rating,
votes: film.votes
}
}

const buildOutput = (result, hasMore) => {
return {
more: hasMore || false,
count: result.length,
result: result
}
}
11 changes: 11 additions & 0 deletions src/controller/trailersController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { request } from "../request/request.js";
import { trailersUrlBuilder as urlBuilder } from "../urlBuilder/index.js";
import { trailersParser as parse } from "../parser/index.js";

export const fetchTrailers = async (data) => {
data.type = 'TRAILERS';
const url = urlBuilder(data);
const response = await request(url);
const result = parse(response);
return result;
}
73 changes: 0 additions & 73 deletions src/faparser.js

This file was deleted.

Loading