From 5a2abf318ed25a0c11fc004a5e39c9d287a98e38 Mon Sep 17 00:00:00 2001 From: carlos-burelo Date: Tue, 8 Feb 2022 23:53:12 -0600 Subject: [PATCH] :bug: fix issue #4: Error caused by new order of the DOM --- src/controllers/anime.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/controllers/anime.js b/src/controllers/anime.js index ce0e49c..a423de7 100644 --- a/src/controllers/anime.js +++ b/src/controllers/anime.js @@ -5,33 +5,29 @@ import { parse } from 'node-html-parser'; export async function getAnime(req, res) { try { 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 { data } = await axios.get(api.anime(id)); const html = parse(data); - const urlMatch = /url\((.+)\)/gim; - const image = attr(html, '.heroarea', 'style') - .match(urlMatch)[0] - .replace(/url\(|\)/g, ''); + const date = html.querySelectorAll('.breadcrumb')[1].querySelector('.breadcrumb-item').text; res.status(200).json({ - banner: image == noImage ? defaulImage : image || null, - image: attr(html, '.chapterpic img', 'src') || null, + banner: attr(html, '.herobg img', 'src'), + image: attr(html, '.chapterpic img', 'src'), title: html .querySelector('.chapterdetails h1') .text.replace(/Sub EspaƱol/gi, '') .trim() || null, - sinopsis: html.querySelector('.chapterdetails p').text || null, - status: html.querySelector('.butns .btn1').text.trim() || null, - date: parseInt(html.querySelector('.butns .btn2').text.trim()) || null, + titleAlt: html.querySelector('.alterno').text || null, + sinopsis: html.querySelector('.textComplete').text.replace('Ver menos', '') || null, + status: html.querySelector('#btninfo').text.trim() || null, rating: html.querySelector('.chapterpic p').text || null, genders: html.querySelectorAll('.breadcrumb .breadcrumb-item a').map((g) => g.text) || null, + date: date || null, episodes: html.querySelectorAll('.row.jpage.row-cols-md-6 .col-item a').map((cap) => { const epId = cap.attributes['href'].replace(`${url}ver/`, ''); return { - image: attr(cap, '.animeimghv', 'src'), + image: attr(cap, '.animeimghv', 'data-src'), no: parseInt(epId.split('-').pop()), id: epId, };