Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Ynjn ; no more Speedbind #6031

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions src/web/mjs/connectors/Ynjn.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Manga from '../engine/Manga.mjs';
import SpeedBinb from './templates/SpeedBinb.mjs';
import Connector from '../engine/Connector.mjs';

export default class YnJn extends SpeedBinb {
export default class YnJn extends Connector {

constructor() {
super();
Expand Down Expand Up @@ -36,7 +36,7 @@ export default class YnJn extends SpeedBinb {
const json = await this.fetchJSON(request);
json.data.episodes.forEach(episode => {
chapters.push({
id: `/viewer/${manga.id}/${episode.id}?cid=${episode.id}`,
id: episode.id,
title: episode.name,
});
});
Expand All @@ -45,4 +45,59 @@ export default class YnJn extends SpeedBinb {
return chapters;
}

async _getPages(chapter) {
let pages = [];
const uri = new URL('/viewer', this.apiUrl);
uri.searchParams.set('title_id', chapter.manga.id);
uri.searchParams.set('episode_id', chapter.id);
const request = new Request(uri, this.requestOptions);
const json = await this.fetchJSON(request);

pages = json.data.pages
.filter(page=> page.manga_page)
.map(page => this.createConnectorURI(page.manga_page.page_image_url ));
return pages;
}

async _handleConnectorURI(payload) {
const uri = new URL(payload, this.url);
const request = new Request(uri, this.requestOptions);
const response = await fetch(request);

let data = await response.blob();
data = await this._descrambleImage(data);
return this._blobToBuffer(data);
}

async _descrambleImage(data) {
let bitmap = await createImageBitmap(data);
return new Promise(resolve => {

let canvas = document.createElement('canvas');
canvas.width = bitmap.width;
canvas.height = bitmap.height;
const ctx = canvas.getContext('2d');
const imageWidth = bitmap.width;
const imageHeight = bitmap.height;
const blockWidth = Math.floor(imageWidth / 4);
const blockHeight = Math.floor(imageHeight / 4);
ctx.clearRect(0, 0, imageWidth, imageHeight);
ctx.drawImage(bitmap, 0, 0, imageWidth, imageHeight);
let y = undefined;

for ( let blockIndex = 0; blockIndex < 16; blockIndex++) {
const A = Math.floor(blockIndex / 4) * blockHeight;
const P = blockIndex % 4 * blockWidth;
const s = Math.floor(blockIndex / 4);
const C = (y = blockIndex % 4 * 4 + s) % 4 * blockWidth;
const k = Math.floor(y / 4) * blockHeight;
ctx.drawImage(bitmap, P, A, blockWidth, blockHeight, C, k, blockWidth, blockHeight );
}

canvas.toBlob(data => {
resolve(data);
}, Engine.Settings.recompressionFormat.value, parseFloat(Engine.Settings.recompressionQuality.value)/100);
} );
}

}