UNPKG

afacinemas

Version:

> A web scraper library for [AFA Cinemas](http://www.afacinemas.com.br/)

138 lines 5.12 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SessionsScraper = void 0; const afa_scraper_1 = require("./afa-scraper"); class SessionsScraper extends afa_scraper_1.AfaScraper { constructor(theaterId, sessionsDate) { super(); this.theaterId = theaterId; this.sessionsDate = sessionsDate; this.url = `${this.baseUrl}acess_painel.php?idc=${this.theaterId}&dt=${this.sessionsDate}`; console.debug(this.url); } extract() { return __awaiter(this, void 0, void 0, function* () { yield this.loadContent(); const movies = []; const sections = this.$('section.colfilmes'); sections.each((_index, element) => { const $element = this.$(element); const id = this.getMovieId($element); const title = this.getMovieTitle($element); const posterUrl = this.getMoviePosterUrl($element); const classification = this.getMovieClassification($element); const duration = this.getMovieDuration($element); const description = this.getMovieDescription($element); const genre = this.getMovieGenre($element); const sessions = this.getMovieSessions($element); movies.push({ id, title, posterUrl, classification, duration, description, genre, sessions, }); }); return movies; }); } getMovieId(item) { const id = this.$(item).find('button.bsessao').attr('property'); return Number(id); } getMovieTitle(item) { const title = this.$(item).find('h1').text().trim().slice(0, -7); return title; } getMoviePosterUrl(item) { const src = this.$(item).find('img').attr('src'); return `${this.baseUrl}${src}`; } getMovieClassification(item) { let classification = this.$(item).find('img.classificao').attr('src'); classification = classification.split('.').slice(0, -1).join('.'); classification = classification.split('/').slice(-1)[0]; if (classification.match(/^\d+$/)) { classification = `${classification} ANOS`; } return classification.toUpperCase(); } getMovieDuration(item) { const duration = this.$(item) .find('p') .first() .text() .split(' - ')[0] .trim(); return duration; } getMovieGenre(item) { const genre = this.$(item).find('p').first().text().split(' - ')[1].trim(); return genre; } getMovieDescription(item) { const genre = this.$(item).find('p').last().text().trim(); return genre; } getMovieSessions(item) { const sessions = []; const buttons = this.$(item).find('div.sessoesfilme button'); buttons.each((_index, element) => { const $element = this.$(element); const room = this.getRoom($element); const time = this.getTime($element); const audio = this.getAudio($element); const image = this.getImage($element); sessions.push({ room, time, audio, image }); }); return sessions; } getRoom(item) { const [room, roomNumber] = this.$(item) .text() .replace(/\s+/g, ' ') .trim() .split(' '); return `${room} ${roomNumber}`; } getTime(item) { const [, , time = ''] = this.$(item) .text() .replace(/\s+/g, ' ') .trim() .split(' '); return time; } getAudio(item) { const [, , , , attrs] = this.$(item) .text() .replace(/\s+/g, ' ') .trim() .split(' '); const [audio] = attrs.split('/'); return audio; } getImage(item) { const [, , , , attrs] = this.$(item) .text() .replace(/\s+/g, ' ') .trim() .split(' '); const [, image] = attrs.split('/'); return image; } } exports.SessionsScraper = SessionsScraper; //# sourceMappingURL=sessions-scraper.js.map