From 095d46681fd32e9cf2011f574a5a7df01e27af84 Mon Sep 17 00:00:00 2001 From: Rajarshee Chatterjee Date: Sun, 12 Sep 2021 08:46:06 +0530 Subject: [PATCH] fix(source): TuNovelaLigera --- src/sources/es/tunovelaligera.js | 93 ++++++++++++++------------------ src/sources/sources.json | 2 +- 2 files changed, 42 insertions(+), 53 deletions(-) diff --git a/src/sources/es/tunovelaligera.js b/src/sources/es/tunovelaligera.js index f805d81c..282bdddc 100644 --- a/src/sources/es/tunovelaligera.js +++ b/src/sources/es/tunovelaligera.js @@ -1,10 +1,14 @@ import cheerio from "react-native-cheerio"; +import { defaultCoverUri, Status } from "../helpers/constants"; + +const sourceId = 23; +const sourceName = "TuNovelaLigera"; const baseUrl = "https://tunovelaligera.com/"; const popularNovels = async (page) => { - let totalPages = 1; - let url = baseUrl + "mejores-novelas-originales/"; + let totalPages = 62; + let url = baseUrl + "novelas/page/" + page + "/?m_orderby=rating"; const result = await fetch(url); const body = await result.text(); @@ -13,7 +17,7 @@ const popularNovels = async (page) => { let novels = []; - $(".page-item-detail").each(function (result) { + $(".page-item-detail").each(function () { const novelName = $(this).find(".h5 > a").text(); const novelCover = $(this).find("img").attr("src"); @@ -21,7 +25,7 @@ const popularNovels = async (page) => { novelUrl += "/"; const novel = { - sourceId: 23, + sourceId, novelName, novelCover, novelUrl, @@ -41,63 +45,48 @@ const parseNovelAndChapters = async (novelUrl) => { $ = cheerio.load(body); - let novel = {}; - - novel.sourceId = 23; - - novel.sourceName = "Tunovelaligera"; - - novel.url = url; + let novel = { sourceId, sourceName, url }; novel.novelUrl = novelUrl; - novel.novelName = $("h1.titulo-novela") - .text() - .replace(/[\t\n]/g, "") - .trim(); + $(".manga-title-badges").remove(); - novel.novelCover = $(".summary_image > a > img").attr("src"); + novel.novelName = $(".post-title > h1").text().trim(); - $(".post-content_item").each(function (result) { - detailName = $(this) - .find(".summary-heading > h5") - .text() - .replace(/[\t\n]/g, "") - .trim(); - detail = $(this) - .find(".summary-content") - .text() - .replace(/[\t\n]/g, "") - .trim(); + novelCover = $(".summary_image > a > img"); - novel[detailName] = detail; + novel.novelCover = + novelCover.attr("data-src") || + novelCover.attr("src") || + defaultCoverUri; + + $(".post-content_item").each(function () { + const detailName = $(this).find(".summary-heading > h5").text().trim(); + const detail = $(this).find(".summary-content").text().trim(); + + switch (detailName) { + case "Generos": + novel.genre = detail.replace(/, /g, ","); + break; + case "Autores": + novel.author = detail; + break; + case "Estado": + novel.status = + detail.includes("OnGoing") || detail.includes("Updating") + ? Status.ONGOING + : Status.COMPLETED; + break; + } }); - novel.genre = novel.Generos.replace(/, /g, ","); - novel.author = novel.Autores; - novel.status = novel.Estado; - novel.status = null; - - novel.artist = novel["Artista(s)"]; - - delete novel.Genre; - delete novel["Artista(s)"]; - delete novel.Autores; - delete novel.Estado; - - let novelSummary = ""; - - $(".summary__content") - .find("p") - .each(function () { - novelSummary += $(this).html(); - }); - - novel.summary = novelSummary; + novel.summary = $("div.summary__content > p").text().trim(); let novelChapters = []; - const novelId = $(".wp-manga-action-button").attr("data-post"); + const novelId = + $(".rating-post-id").attr("value") || + $("#manga-chapters-holder").attr("data-id"); let formData = new FormData(); formData.append("action", "manga_get_chapters"); @@ -151,7 +140,7 @@ const parseChapter = async (novelUrl, chapterUrl) => { novelUrl = novelUrl + "/"; const chapter = { - sourceId: 23, + sourceId, novelUrl, chapterUrl, chapterName, @@ -179,7 +168,7 @@ const searchNovels = async (searchTerm) => { novelUrl = novelUrl.replace(`${baseUrl}novelas/`, ""); const novel = { - sourceId: 23, + sourceId, novelName, novelCover, novelUrl, diff --git a/src/sources/sources.json b/src/sources/sources.json index 63e03ace..c9fbff11 100644 --- a/src/sources/sources.json +++ b/src/sources/sources.json @@ -156,7 +156,7 @@ { "sourceId": 23, "url": "https://tunovelaligera.com/", - "sourceName": "Tunovelaligera", + "sourceName": "TuNovelaLigera", "icon": "https://github.com/LNReader/lnreader-sources/blob/main/src/es/tunovelaligera/icon.png?raw=true", "lang": "Spanish" },