-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmovie.service.ts
More file actions
72 lines (67 loc) · 2 KB
/
movie.service.ts
File metadata and controls
72 lines (67 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { HTMLElement, parse } from 'node-html-parser';
import { fetchMovie } from '../fetchers';
import {
getColorRating,
getDescriptions,
getDirectors,
getGenres,
getGroup,
getId,
getOrigins,
getOtherTitles,
getPoster,
getRating,
getTags,
getTitle,
getType,
getYear
} from '../helpers/movie.helper';
import { CSFDFilmTypes } from '../interfaces/global';
import { CSFDMovie } from '../interfaces/movie.interface';
import { movieUrl } from '../vars';
export class MovieScraper {
private film: CSFDMovie;
public async movie(movie: string | number): Promise<CSFDMovie> {
const response = await fetchMovie(movie);
const movieHtml = parse(response);
const pageClasses = movieHtml.querySelector('.page-content').classNames;
const asideNode = movieHtml.querySelector('.box-rating-container');
const movieNode = movieHtml.querySelector('.main-movie-profile');
this.buildMovie(movie, movieNode, asideNode, pageClasses);
return this.film;
}
private buildMovie(
movie: string | number,
el: HTMLElement,
elAside: HTMLElement,
pageClasses: string[]
) {
this.film = {
id: getId(el),
title: getTitle(el),
year: getYear(el),
descriptions: getDescriptions(el),
genres: getGenres(el),
type: getType(el) as CSFDFilmTypes,
url: movieUrl(movie),
origins: getOrigins(el),
colorRating: getColorRating(pageClasses),
rating: getRating(el),
otherTitles: getOtherTitles(el),
poster: getPoster(el),
creators: {
directors: getDirectors(el),
writers: getGroup(el, 'Scénář'),
cinematography: getGroup(el, 'Kamera'),
music: getGroup(el, 'Hudba'),
actors: getGroup(el, 'Hrají'),
basedOn: getGroup(el, 'Předloha'),
producers: getGroup(el, 'Produkce'),
filmEditing: getGroup(el, 'Střih'),
costumeDesign: getGroup(el, 'Kostýmy'),
productionDesign: getGroup(el, 'Scénografie')
},
tags: getTags(elAside)
};
}
}