UNPKG

bedetheque-scraper

Version:

NodeJS script to scrap the entire database of dbgest.com / bedetheque.com (approx. 260.000+ albums)

39 lines (38 loc) 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var utils_1 = require("./utils"); var Serie = /** @class */ (function () { function Serie($) { this.serieId = parseInt($('.idbel').text(), 10); this.serieTitle = $('h1 a').text(); var match = $('.serie-info').text().match(/Tomes? :([0-9]+)/); this.numberOfAlbums = match ? parseInt(match[1], 10) : 0; this.recommendationsId = this.getRecommendationsId($); } Serie.prototype.addAlbumsInfo = function (albums) { var _a; this.albumsId = albums.map(function (album) { return album.albumId; }); _a = this.getVoteAverage(albums), this.voteAverage = _a[0], this.voteCount = _a[1]; this.serieCover = albums[0] && albums[0].imageCover; }; Serie.prototype.getVoteAverage = function (albums) { var voteAverage = 0; var voteCount = 0; albums.forEach(function (album) { voteAverage += album.voteAverage * album.voteCount; voteCount += album.voteCount; }); if (voteCount === 0) { return [0, 0]; } return [Math.floor(voteAverage / voteCount * 10) / 10, voteCount]; }; Serie.prototype.getRecommendationsId = function ($) { return $('.alire li a') .map(function (i, elem) { return $(elem).attr('href'); }) .get() .map(function (url) { return utils_1.Utils.urlToSerieID(url); }); }; return Serie; }()); exports.Serie = Serie;