diff --git a/src/web/mjs/connectors/YugenMangas.mjs b/src/web/mjs/connectors/YugenMangas.mjs index bf9ba6dfbe..eb6c4610e6 100644 --- a/src/web/mjs/connectors/YugenMangas.mjs +++ b/src/web/mjs/connectors/YugenMangas.mjs @@ -6,10 +6,10 @@ export default class YugenMangas extends Connector { super.id = 'yugenmangas'; super.label = 'YugenMangas'; this.tags = [ 'webtoon', 'novel', 'spanish' ]; - this.url = 'https://yugenmangas.com'; - this.apiURL = 'https://api.yugenmangas.com'; + this.url = 'https://yugenmangas.net'; + this.apiURL = 'https://api.yugenmangas.net'; this.queryChapters = 'ul.chapters-list-single a'; - this.novelContentQuery = 'div#reading-content'; + this.novelContentQuery = 'div#reader-container'; this.novelFormat = 'image/png'; this.novelWidth = '56em';// parseInt(1200 / window.devicePixelRatio) + 'px'; this.novelPadding = '1.5em'; @@ -25,21 +25,9 @@ export default class YugenMangas extends Connector { } async _getMangasFromPage(page) { - const uri = new URL('/series/querysearch', this.apiURL); - const body = { - 'order_by' : 'latest', - 'tags_ids': [], - 'order':'desc', - 'page':page - }; - let request = new Request(uri, { - method: 'POST', - body: JSON.stringify(body), - headers: { - 'content-type': 'application/json', - 'x-referer': this.url - } - }); + const uri = new URL(`/query?visibility=Public&series_type=All&order=desc&page=${page}&perPage=200`, this.apiURL); + const request = new Request(uri, this.requestOptions); + request.headers.set('x-referer', this.url); const data = await this.fetchJSON(request); return data.data.map(element => { return { @@ -52,76 +40,67 @@ export default class YugenMangas extends Connector { async _getChapters(manga) { const uri = new URL(manga.id, this.url); const request = new Request(uri, this.requestOptions); - const jsonObj = (await this.getNextData(request)).props.pageProps; - return jsonObj.series.chapters.map(element => { + const data = await this.fetchDOM(request, 'ul.grid a'); + return data.map(element => { return { - id: JSON.stringify({slug : element.chapter_slug, id : element.id}), - title: element.chapter_name.trim() + id: element.pathname, + title: element.querySelector('li.flex div.flex span').textContent.trim() }; }); } async _getPages(chapter) { - const chapid = JSON.parse(chapter.id); - const uri = new URL(chapter.manga.id +'/'+chapid.slug, this.url); - const request = new Request(uri, this.requestOptions); const darkmode = Engine.Settings.NovelColorProfile(); const script = ` - new Promise(async resolve => { - //fetch chapter content - const response = await fetch('${this.apiURL}/series/chapter/${chapid.id}'); - const obj = await response.json(); - //if its pictures, list pictures - if (obj.content.images) { - resolve( { - pictures : obj.content.images - }); - return; - } - else { - //else render the novel - document.body.style.width = '${this.novelWidth}'; - let novel = document.querySelector('${this.novelContentQuery}'); - novel.innerHTML = obj.content; - novel.style.padding = '${this.novelPadding}'; - [...novel.querySelectorAll(":not(:empty)")].forEach(ele => { - ele.style.backgroundColor = '${darkmode.background}' - ele.style.color = '${darkmode.text}' - }) - novel.style.backgroundColor = '${darkmode.background}' - novel.style.color = '${darkmode.text}' - let script = document.createElement('script'); - script.onerror = error => reject(error); - script.onload = async function() { - try{ - let canvas = await html2canvas(novel); - resolve({ - rendered : canvas.toDataURL('${this.novelFormat}') - }); - } - catch (error){ - reject(error) - } - } - script.src = 'https://html2canvas.hertzen.com/dist/html2canvas.min.js'; - document.body.appendChild(script); - } - }); + new Promise((resolve, reject) => { + + //check for images container + const imgcontainer = document.querySelector('div.container p.items-center'); + if (imgcontainer) { + let images = [...imgcontainer.querySelectorAll('img[data-src]')]; + images = images.map(image => image.dataset['src'] || image.src) + .filter(image => !image.match(/,/));//they put invalid characters in some pictures (not chapters one), gotta filter it + resolve(images); //return images + } else { //else render the text canvas + document.body.style.width = '${this.novelWidth}'; + let container = document.querySelector('div.container'); + container.style.maxWidth = '${this.novelWidth}'; + container.style.padding = '0'; + container.style.margin = '0'; + let novel = document.querySelector('${this.novelContentQuery}'); + novel.style.padding = '${this.novelPadding}'; + [...novel.querySelectorAll(":not(:empty)")].forEach(ele => { + ele.style.backgroundColor = '${darkmode.background}' + ele.style.color = '${darkmode.text}' + }) + novel.style.backgroundColor = '${darkmode.background}' + novel.style.color = '${darkmode.text}' + let script = document.createElement('script'); + script.onerror = error => reject(error); + script.onload = async function() { + try{ + let canvas = await html2canvas(novel); + resolve([canvas.toDataURL('${this.novelFormat}')]); + }catch (error){ + reject(error) + } + } + script.src = 'https://html2canvas.hertzen.com/dist/html2canvas.min.js'; + document.body.appendChild(script); + } + }); `; - const data = await Engine.Request.fetchUI(request, script, 30000, true); - return data.pictures ? data.pictures.map(picture => this.getAbsolutePath(picture, this.apiURL)) : [data.rendered]; + + const uri = new URL(chapter.id, this.url); + const request = new Request(uri, this.requestOptions); + return await Engine.Request.fetchUI(request, script, 30000, true); } async _getMangaFromURI(uri) { const request = new Request(new URL(uri), this.requestOptions); - const data = await this.fetchDOM(request, 'div.series-title h1'); + const data = await this.fetchDOM(request, 'meta[property="og:title"]'); const element = [...data].pop(); - const title = (element.content || element.textContent).trim(); + const title = (element.content || element.textContent).replace('- Yugen Manga', '').trim(); return new Manga(this, uri.pathname, title); } - - async getNextData(request) { - const [data] = await this.fetchDOM(request, '#__NEXT_DATA__'); - return JSON.parse(data.textContent); - } }