From 0b86806fcf95c28c3b9b206640d731c17348ca0a Mon Sep 17 00:00:00 2001 From: Justin COLLON <48163201+error7404@users.noreply.github.com> Date: Wed, 24 Jul 2024 17:17:39 +0200 Subject: [PATCH] fix MTL Novel (#1085) * MTL Novel: - fix chapters not loading - fix geners & author & status not working - renamed MTL Novel for languages * MTL Novel version update --- scripts/multisrc/mtlnovel/sources.json | 6 ++-- scripts/multisrc/mtlnovel/template.ts | 48 ++++++++++++++++++++------ 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/scripts/multisrc/mtlnovel/sources.json b/scripts/multisrc/mtlnovel/sources.json index 4f4d4eb..8c367f5 100644 --- a/scripts/multisrc/mtlnovel/sources.json +++ b/scripts/multisrc/mtlnovel/sources.json @@ -10,7 +10,7 @@ { "id": "mtlnovel-fr", "sourceSite": "https://fr.mtlnovel.com/", - "sourceName": "MTL Novel", + "sourceName": "MTL Novel (FR)", "options": { "lang": "French" } @@ -18,7 +18,7 @@ { "id": "mtlnovel-es", "sourceSite": "https://es.mtlnovel.com/", - "sourceName": "MTL Novel", + "sourceName": "MTL Novel (ES)", "options": { "lang": "Spanish" } @@ -26,7 +26,7 @@ { "id": "mtlnovel-id", "sourceSite": "https://id.mtlnovel.com/", - "sourceName": "MTL Novel", + "sourceName": "MTL Novel (ID)", "options": { "lang": "Indonesian" } diff --git a/scripts/multisrc/mtlnovel/template.ts b/scripts/multisrc/mtlnovel/template.ts index 89c80d6..f2bc2a4 100644 --- a/scripts/multisrc/mtlnovel/template.ts +++ b/scripts/multisrc/mtlnovel/template.ts @@ -22,6 +22,7 @@ class MTLNovelPlugin implements Plugin.PluginBase { name: string; icon: string; site: string; + mainUrl: string; version: string; options?: MTLNovelOptions; filters?: Filters; @@ -31,7 +32,8 @@ class MTLNovelPlugin implements Plugin.PluginBase { this.name = metadata.sourceName; this.icon = 'multisrc/mtlnovel/mtlnovel/icon.png'; this.site = metadata.sourceSite; - this.version = '1.1.0'; + this.mainUrl = 'https://www.mtlnovel.com/'; + this.version = '1.1.1'; this.options = metadata.options ?? ({} as MTLNovelOptions); this.filters = metadata.filters satisfies Filters; } @@ -77,9 +79,8 @@ class MTLNovelPlugin implements Plugin.PluginBase { if ( !novelCover || novelCover == 'https://www.mtlnovel.net/no-image.jpg.webp' - ) { + ) novelCover = defaultCover; - } const novelUrl = loadedCheerio(el).find('a.list-title').attr('href'); if (!novelUrl) return; @@ -87,7 +88,7 @@ class MTLNovelPlugin implements Plugin.PluginBase { const novel = { name: novelName, cover: novelCover, - path: novelUrl.replace(this.site, ''), + path: novelUrl.replace(this.mainUrl, '').replace(this.site, ''), }; novels.push(novel); @@ -108,15 +109,38 @@ class MTLNovelPlugin implements Plugin.PluginBase { const novel: Plugin.SourceNovel = { path: novelPath, - name: loadedCheerio('h1.entry-title').text() || 'Untitled', - cover: loadedCheerio('.nov-head > amp-img').attr('src'), + name: loadedCheerio('h1.entry-title').text().trim() || 'Untitled', + cover: loadedCheerio('.nov-head > amp-img').attr('src') || defaultCover, summary: loadedCheerio('div.desc > h2').next().text().trim(), - author: loadedCheerio('#author').text(), - status: loadedCheerio('#status').text(), - genres: loadedCheerio('#genre').text().replace(/\s+/g, ''), chapters: [], }; + loadedCheerio('.info tr').each((i, el) => { + const infoName = loadedCheerio(el).find('td').eq(0).text().trim(); + const infoValue = loadedCheerio(el).find('td').eq(2).text().trim(); + switch (infoName) { + case 'Genre': + case 'Tags': + case 'Mots Clés': + case 'Género': + case 'Label': + if (novel.genres) novel.genres += ', ' + infoValue; + else novel.genres = infoValue; + break; + case 'Author': + case 'Auteur': + case 'Autor(a)': + novel.author = infoValue; + break; + case 'Status': + case 'Statut': + case 'Estado': + if (infoValue == 'Hiatus') novel.status = NovelStatus.OnHiatus; + else novel.status = infoValue; + break; + } + }); + const chapterListUrl = this.site + novelPath + 'chapter-list/'; const getChapters = async () => { @@ -136,7 +160,7 @@ class MTLNovelPlugin implements Plugin.PluginBase { const chapterUrl = loadedCheerio(el).attr('href'); if (!chapterUrl) return; chapter.push({ - path: chapterUrl.replace(this.site, ''), + path: chapterUrl.replace(this.mainUrl, '').replace(this.site, ''), name: chapterName, releaseTime: releaseDate, }); @@ -181,7 +205,9 @@ class MTLNovelPlugin implements Plugin.PluginBase { result.items[0].results.map((item: SearchEntry) => { const novelName = item.title.replace(/<\/?strong>/g, ''); const novelCover = item.thumbnail; - const novelUrl = item.permalink.replace(this.site, ''); + const novelUrl = item.permalink + .replace(this.mainUrl, '') + .replace(this.site, ''); const novel = { name: novelName, cover: novelCover, path: novelUrl };