From 383d10eda8b0c9ecfb9222c3c1eaa093f782cbf1 Mon Sep 17 00:00:00 2001 From: Seyden Date: Sun, 28 Jul 2024 03:46:50 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20TheNetsk?= =?UTF-8?q?y/community-extensions@fce8a4cf9dfb624aa694a701e287431b9655c136?= =?UTF-8?q?=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 0.8/AsuraScans/index.js | 43 ++++++++++++++++++++++++++++++---------- 0.8/AsuraScans/source.js | 43 ++++++++++++++++++++++++++++++---------- 0.8/versioning.json | 2 +- 3 files changed, 65 insertions(+), 23 deletions(-) diff --git a/0.8/AsuraScans/index.js b/0.8/AsuraScans/index.js index 8b6fd11..85034ab 100644 --- a/0.8/AsuraScans/index.js +++ b/0.8/AsuraScans/index.js @@ -3918,7 +3918,7 @@ const simpleUrl = require('simple-url'); const ASURASCANS_DOMAIN = 'https://asuracomic.net'; const ASURASCANS_API_DOMAIN = 'https://gg.asuracomic.net'; exports.AsuraScansInfo = { - version: '4.1.1', + version: '4.1.2', name: 'AsuraScans', description: 'Extension that pulls manga from AsuraScans', author: 'Seyden', @@ -4078,6 +4078,8 @@ class AsuraScans { enabled: false } }; + // Ugly workaround to fasten up migrations and updates, paperback doesnt support any other way for not double requesting + this.mangaDataRequests = {}; } async getSourceMenu() { return App.createDUISection({ @@ -4094,6 +4096,26 @@ class AsuraScans { const url = settingsUrl ? settingsUrl : this.baseUrl; return url.replace(/\/*$/, ''); } + async getMangaRequest(mangaId) { + let request = this.mangaDataRequests[mangaId]; + if (request && request.expires > Date.now()) { + return request.data; + } + for (const key in this.mangaDataRequests) { + let tempRequest = this.mangaDataRequests[key]; + if (tempRequest.expires < Date.now()) { + delete this.mangaDataRequests[key]; + } + } + this.mangaDataRequests[mangaId] = { + expires: Date.now() + 5000, + data: new Promise(async (resolve) => { + const result = await this.getMangaData(mangaId); + resolve(result); + }) + }; + return this.mangaDataRequests[mangaId].data; + } async getMangaSlug(mangaId) { return await this.stateManager.retrieve(`${mangaId}:slug`); } @@ -4111,11 +4133,11 @@ class AsuraScans { return await this.loadRequestData(url); } async getMangaDetails(mangaId) { - const data = await this.getMangaData(mangaId); + const data = await this.getMangaRequest(mangaId); return this.parser.parseMangaDetails(data, mangaId, this); } async getChapters(mangaId) { - const data = await this.getMangaData(mangaId); + const data = await this.getMangaRequest(mangaId); const chapters = await this.parser.parseChapterList(data, mangaId, this); if (!Array.isArray(chapters) || chapters.length == 0) { throw new Error(`Couldn't find any chapters for mangaId ${mangaId}, throwing an error to prevent loosing reading progress`); @@ -4138,8 +4160,8 @@ class AsuraScans { async getChapterDetails(mangaId, chapterId) { const chapterLink = await this.getChapterSlug(mangaId, chapterId); const url = await this.getBaseUrl(); - const $ = await this.loadCheerioData(`${url}/${chapterLink}/`); - return this.parser.parseChapterDetails($, mangaId, chapterId); + const data = await this.loadRequestData(`${url}/${chapterLink}/`); + return this.parser.parseChapterDetails(data, mangaId, chapterId); } async getSearchTags() { const data = await this.loadRequestData(`${ASURASCANS_API_DOMAIN}/api/series/filters`); @@ -4165,7 +4187,7 @@ class AsuraScans { const request = await this.constructSearchRequest(page, query); const response = await this.requestManager.schedule(request, 1); this.checkResponseErrors(response); - const $ = this.cheerio.load(response.data); + const $ = this.cheerio.load(response.data, { _useHtmlParser2: true }); const results = await this.parser.parseSearchResults($, this); const chapterTag = query?.includedTags.find((x) => x.id.startsWith('chapters')); const manga = []; @@ -4272,7 +4294,7 @@ class AsuraScans { return response.data; } async loadCheerioData(url, method = 'GET') { - return this.cheerio.load(await this.loadRequestData(url, method)); + return this.cheerio.load(await this.loadRequestData(url, method), { _useHtmlParser2: true }); } async getCloudflareBypassRequestAsync() { const url = await this.getBaseUrl(); @@ -4388,7 +4410,7 @@ class AsuraScansParser { if (obj == '') { throw new Error(`Failed to parse comic object for manga ${mangaId}`); // If null, throw error, else parse data to json. } - const $ = source.cheerio.load(data); + const $ = source.cheerio.load(data, { _useHtmlParser2: true }); const comicObj = JSON.parse(obj); const titles = []; titles.push(comicObj.comic.name.trim()); @@ -4481,8 +4503,7 @@ class AsuraScansParser { return App.createChapter(chapter); }); } - parseChapterDetails($, mangaId, chapterId) { - const data = $.html(); + parseChapterDetails(data, mangaId, chapterId) { const pages = new Set(); const matches = data.matchAll(/(https:\/\/gg\.asuracomic\.net\/storage\/comics\/[^"\\]+)/gi); for (const match of Array.from(matches)) { @@ -4532,7 +4553,7 @@ class AsuraScansParser { return results; } for (const manga of mangas.toArray()) { - const slug = manga.attribs['href'] ?? ''; + const slug = $(manga).attr('href') ?? ''; if (!slug) { throw new Error(`Unable to parse slug (${slug})!`); } diff --git a/0.8/AsuraScans/source.js b/0.8/AsuraScans/source.js index 8b6fd11..85034ab 100644 --- a/0.8/AsuraScans/source.js +++ b/0.8/AsuraScans/source.js @@ -3918,7 +3918,7 @@ const simpleUrl = require('simple-url'); const ASURASCANS_DOMAIN = 'https://asuracomic.net'; const ASURASCANS_API_DOMAIN = 'https://gg.asuracomic.net'; exports.AsuraScansInfo = { - version: '4.1.1', + version: '4.1.2', name: 'AsuraScans', description: 'Extension that pulls manga from AsuraScans', author: 'Seyden', @@ -4078,6 +4078,8 @@ class AsuraScans { enabled: false } }; + // Ugly workaround to fasten up migrations and updates, paperback doesnt support any other way for not double requesting + this.mangaDataRequests = {}; } async getSourceMenu() { return App.createDUISection({ @@ -4094,6 +4096,26 @@ class AsuraScans { const url = settingsUrl ? settingsUrl : this.baseUrl; return url.replace(/\/*$/, ''); } + async getMangaRequest(mangaId) { + let request = this.mangaDataRequests[mangaId]; + if (request && request.expires > Date.now()) { + return request.data; + } + for (const key in this.mangaDataRequests) { + let tempRequest = this.mangaDataRequests[key]; + if (tempRequest.expires < Date.now()) { + delete this.mangaDataRequests[key]; + } + } + this.mangaDataRequests[mangaId] = { + expires: Date.now() + 5000, + data: new Promise(async (resolve) => { + const result = await this.getMangaData(mangaId); + resolve(result); + }) + }; + return this.mangaDataRequests[mangaId].data; + } async getMangaSlug(mangaId) { return await this.stateManager.retrieve(`${mangaId}:slug`); } @@ -4111,11 +4133,11 @@ class AsuraScans { return await this.loadRequestData(url); } async getMangaDetails(mangaId) { - const data = await this.getMangaData(mangaId); + const data = await this.getMangaRequest(mangaId); return this.parser.parseMangaDetails(data, mangaId, this); } async getChapters(mangaId) { - const data = await this.getMangaData(mangaId); + const data = await this.getMangaRequest(mangaId); const chapters = await this.parser.parseChapterList(data, mangaId, this); if (!Array.isArray(chapters) || chapters.length == 0) { throw new Error(`Couldn't find any chapters for mangaId ${mangaId}, throwing an error to prevent loosing reading progress`); @@ -4138,8 +4160,8 @@ class AsuraScans { async getChapterDetails(mangaId, chapterId) { const chapterLink = await this.getChapterSlug(mangaId, chapterId); const url = await this.getBaseUrl(); - const $ = await this.loadCheerioData(`${url}/${chapterLink}/`); - return this.parser.parseChapterDetails($, mangaId, chapterId); + const data = await this.loadRequestData(`${url}/${chapterLink}/`); + return this.parser.parseChapterDetails(data, mangaId, chapterId); } async getSearchTags() { const data = await this.loadRequestData(`${ASURASCANS_API_DOMAIN}/api/series/filters`); @@ -4165,7 +4187,7 @@ class AsuraScans { const request = await this.constructSearchRequest(page, query); const response = await this.requestManager.schedule(request, 1); this.checkResponseErrors(response); - const $ = this.cheerio.load(response.data); + const $ = this.cheerio.load(response.data, { _useHtmlParser2: true }); const results = await this.parser.parseSearchResults($, this); const chapterTag = query?.includedTags.find((x) => x.id.startsWith('chapters')); const manga = []; @@ -4272,7 +4294,7 @@ class AsuraScans { return response.data; } async loadCheerioData(url, method = 'GET') { - return this.cheerio.load(await this.loadRequestData(url, method)); + return this.cheerio.load(await this.loadRequestData(url, method), { _useHtmlParser2: true }); } async getCloudflareBypassRequestAsync() { const url = await this.getBaseUrl(); @@ -4388,7 +4410,7 @@ class AsuraScansParser { if (obj == '') { throw new Error(`Failed to parse comic object for manga ${mangaId}`); // If null, throw error, else parse data to json. } - const $ = source.cheerio.load(data); + const $ = source.cheerio.load(data, { _useHtmlParser2: true }); const comicObj = JSON.parse(obj); const titles = []; titles.push(comicObj.comic.name.trim()); @@ -4481,8 +4503,7 @@ class AsuraScansParser { return App.createChapter(chapter); }); } - parseChapterDetails($, mangaId, chapterId) { - const data = $.html(); + parseChapterDetails(data, mangaId, chapterId) { const pages = new Set(); const matches = data.matchAll(/(https:\/\/gg\.asuracomic\.net\/storage\/comics\/[^"\\]+)/gi); for (const match of Array.from(matches)) { @@ -4532,7 +4553,7 @@ class AsuraScansParser { return results; } for (const manga of mangas.toArray()) { - const slug = manga.attribs['href'] ?? ''; + const slug = $(manga).attr('href') ?? ''; if (!slug) { throw new Error(`Unable to parse slug (${slug})!`); } diff --git a/0.8/versioning.json b/0.8/versioning.json index 5845207..5d8dc94 100644 --- a/0.8/versioning.json +++ b/0.8/versioning.json @@ -1 +1 @@ -{"buildTime":"2024-07-26T23:39:30.409Z","sources":[{"id":"AsuraScans","name":"AsuraScans","author":"Seyden","desc":"Extension that pulls manga from AsuraScans","website":"https://github.com/Seyden","contentRating":"MATURE","version":"4.1.1","icon":"icon.png","tags":[],"websiteBaseURL":"https://asuracomic.net","intents":53},{"id":"BatoTo","name":"BatoTo","author":"niclimcy","desc":"Extension that pulls manga from bato.to","website":"https://github.com/niclimcy","contentRating":"MATURE","version":"3.1.2","icon":"icon.png","tags":[{"text":"Multi Language","type":"default"}],"websiteBaseURL":"https://bato.to","intents":53},{"id":"Hentai2Read","name":"Hentai2Read","author":"EmZedH","desc":"Extension that pulls manga from hentai2read.com","website":"https://github.com/EmZedH","contentRating":"ADULT","version":"1.0.1","icon":"icon.png","tags":[{"text":"18+","type":"warning"}],"websiteBaseURL":"https://hentai2read.com","intents":5},{"id":"MangaDex","name":"MangaDex","author":"Nar1n & Netsky","desc":"Extension that pulls manga from MangaDex","website":"https://github.com/nar1n","contentRating":"EVERYONE","version":"3.0.5","icon":"icon.png","tags":[],"websiteBaseURL":"https://mangadex.org","intents":37},{"id":"MangaPlus","name":"MangaPlus","author":"Rinto-kun","desc":"Extension that pulls manga from Manga+ by Shueisha","website":"https://github.com/Rinto-kun","contentRating":"EVERYONE","version":"2.0.3","icon":"icon.png","tags":[],"websiteBaseURL":"https://mangaplus.shueisha.co.jp","intents":53},{"id":"NHentai","name":"nhentai","author":"NotMarek & Netsky","desc":"Extension which pulls content from nHentai.","website":"https://github.com/TheNetsky","contentRating":"ADULT","version":"4.0.7","icon":"icon.png","tags":[{"text":"18+","type":"warning"}],"websiteBaseURL":"https://nhentai.net","intents":53}],"builtWith":{"toolchain":"0.8.0-alpha.47","types":"0.8.0-alpha.47"}} \ No newline at end of file +{"buildTime":"2024-07-28T03:46:49.698Z","sources":[{"id":"AsuraScans","name":"AsuraScans","author":"Seyden","desc":"Extension that pulls manga from AsuraScans","website":"https://github.com/Seyden","contentRating":"MATURE","version":"4.1.2","icon":"icon.png","tags":[],"websiteBaseURL":"https://asuracomic.net","intents":53},{"id":"BatoTo","name":"BatoTo","author":"niclimcy","desc":"Extension that pulls manga from bato.to","website":"https://github.com/niclimcy","contentRating":"MATURE","version":"3.1.2","icon":"icon.png","tags":[{"text":"Multi Language","type":"default"}],"websiteBaseURL":"https://bato.to","intents":53},{"id":"Hentai2Read","name":"Hentai2Read","author":"EmZedH","desc":"Extension that pulls manga from hentai2read.com","website":"https://github.com/EmZedH","contentRating":"ADULT","version":"1.0.1","icon":"icon.png","tags":[{"text":"18+","type":"warning"}],"websiteBaseURL":"https://hentai2read.com","intents":5},{"id":"MangaDex","name":"MangaDex","author":"Nar1n & Netsky","desc":"Extension that pulls manga from MangaDex","website":"https://github.com/nar1n","contentRating":"EVERYONE","version":"3.0.5","icon":"icon.png","tags":[],"websiteBaseURL":"https://mangadex.org","intents":37},{"id":"MangaPlus","name":"MangaPlus","author":"Rinto-kun","desc":"Extension that pulls manga from Manga+ by Shueisha","website":"https://github.com/Rinto-kun","contentRating":"EVERYONE","version":"2.0.3","icon":"icon.png","tags":[],"websiteBaseURL":"https://mangaplus.shueisha.co.jp","intents":53},{"id":"NHentai","name":"nhentai","author":"NotMarek & Netsky","desc":"Extension which pulls content from nHentai.","website":"https://github.com/TheNetsky","contentRating":"ADULT","version":"4.0.7","icon":"icon.png","tags":[{"text":"18+","type":"warning"}],"websiteBaseURL":"https://nhentai.net","intents":53}],"builtWith":{"toolchain":"0.8.0-alpha.47","types":"0.8.0-alpha.47"}} \ No newline at end of file