🐛 fix issue #4: Error caused by new order of the DOM

master
carlos-burelo 4 years ago
parent b4d37e517f
commit 5a2abf318e

@ -5,33 +5,29 @@ import { parse } from 'node-html-parser';
export async function getAnime(req, res) { export async function getAnime(req, res) {
try { try {
const url = 'https://monoschinos2.com/'; const url = 'https://monoschinos2.com/';
const noImage = 'https://monoschinos2.com/assets/img/no_image.png';
const defaulImage = 'https://image.freepik.com/free-vector/404-error-page-found_41910-364.jpg';
const { id } = req.params; const { id } = req.params;
const { data } = await axios.get(api.anime(id)); const { data } = await axios.get(api.anime(id));
const html = parse(data); const html = parse(data);
const urlMatch = /url\((.+)\)/gim; const date = html.querySelectorAll('.breadcrumb')[1].querySelector('.breadcrumb-item').text;
const image = attr(html, '.heroarea', 'style')
.match(urlMatch)[0]
.replace(/url\(|\)/g, '');
res.status(200).json({ res.status(200).json({
banner: image == noImage ? defaulImage : image || null, banner: attr(html, '.herobg img', 'src'),
image: attr(html, '.chapterpic img', 'src') || null, image: attr(html, '.chapterpic img', 'src'),
title: title:
html html
.querySelector('.chapterdetails h1') .querySelector('.chapterdetails h1')
.text.replace(/Sub Español/gi, '') .text.replace(/Sub Español/gi, '')
.trim() || null, .trim() || null,
sinopsis: html.querySelector('.chapterdetails p').text || null, titleAlt: html.querySelector('.alterno').text || null,
status: html.querySelector('.butns .btn1').text.trim() || null, sinopsis: html.querySelector('.textComplete').text.replace('Ver menos', '') || null,
date: parseInt(html.querySelector('.butns .btn2').text.trim()) || null, status: html.querySelector('#btninfo').text.trim() || null,
rating: html.querySelector('.chapterpic p').text || null, rating: html.querySelector('.chapterpic p').text || null,
genders: html.querySelectorAll('.breadcrumb .breadcrumb-item a').map((g) => g.text) || null, genders: html.querySelectorAll('.breadcrumb .breadcrumb-item a').map((g) => g.text) || null,
date: date || null,
episodes: episodes:
html.querySelectorAll('.row.jpage.row-cols-md-6 .col-item a').map((cap) => { html.querySelectorAll('.row.jpage.row-cols-md-6 .col-item a').map((cap) => {
const epId = cap.attributes['href'].replace(`${url}ver/`, ''); const epId = cap.attributes['href'].replace(`${url}ver/`, '');
return { return {
image: attr(cap, '.animeimghv', 'src'), image: attr(cap, '.animeimghv', 'data-src'),
no: parseInt(epId.split('-').pop()), no: parseInt(epId.split('-').pop()),
id: epId, id: epId,
}; };

Loading…
Cancel
Save