-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmovie.service.ts
More file actions
88 lines (83 loc) · 2.56 KB
/
movie.service.ts
File metadata and controls
88 lines (83 loc) · 2.56 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { HTMLElement, parse } from 'node-html-parser';
import { fetchPage } from '../fetchers';
import {
getBoxMovies,
getColorRating,
getDescriptions,
getDuration,
getGenres,
getGroup,
getOrigins,
getPoster,
getPremieres,
getRandomPhoto,
getRating,
getRatingCount,
getTags,
getTitle,
getTitlesOther,
getTrivia,
getType,
getVods,
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(movieId: number): Promise<CSFDMovie> {
const url = movieUrl(+movieId);
const response = await fetchPage(url);
const movieHtml = parse(response);
const pageClasses = movieHtml.querySelector('.page-content').classNames.split(' ');
const asideNode = movieHtml.querySelector('.aside-movie-profile');
const movieNode = movieHtml.querySelector('.main-movie-profile');
const jsonLd = movieHtml.querySelector('script[type="application/ld+json"]').innerText;
this.buildMovie(+movieId, movieNode, asideNode, pageClasses, jsonLd);
return this.film;
}
private buildMovie(
movieId: number,
el: HTMLElement,
asideEl: HTMLElement,
pageClasses: string[],
jsonLd: string
) {
this.film = {
id: movieId,
title: getTitle(el),
year: getYear(jsonLd),
duration: getDuration(jsonLd, el),
descriptions: getDescriptions(el),
genres: getGenres(el),
type: getType(el) as CSFDFilmTypes,
url: movieUrl(movieId),
origins: getOrigins(el),
colorRating: getColorRating(pageClasses),
rating: getRating(asideEl),
ratingCount: getRatingCount(asideEl),
titlesOther: getTitlesOther(el),
poster: getPoster(el),
photo: getRandomPhoto(el),
trivia: getTrivia(el),
creators: {
directors: getGroup(el, 'Režie'),
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')
},
vod: getVods(asideEl),
tags: getTags(asideEl),
premieres: getPremieres(asideEl),
related: getBoxMovies(asideEl, 'Související'),
similar: getBoxMovies(asideEl, 'Podobné')
};
}
}