Created
February 16, 2019 18:04
-
-
Save lazygyu/cc0703c5ccca144d59cdd3b0523a401d to your computer and use it in GitHub Desktop.
mgsc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request-promise-native'); | |
const {createCanvas, loadImage} = require('canvas'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const wr_id = process.argv[2]; | |
if( !wr_id ) { | |
console.error('USAGE : node index [wr_id]'); | |
process.exit(1); | |
} | |
request('https://mangashow2.me/bbs/board.php?bo_table=msm_manga&wr_id=' + wr_id).then( (html)=>{ | |
let vcnt, images, chapter, seed, title; | |
const CX = 5, CY = 5; | |
function __v(){ | |
if(chapter < 554714){ | |
const e = 1e4 * Math.sin(seed++); | |
return Math.floor(1e5 * (e - Math.floor(e))); | |
} | |
seed++; | |
let t = 100 * Math.sin(10 * seed), n = 1e3 * Math.cos(13 * seed), a = 1e4 * Math.tan(14 * seed); | |
return t = Math.floor(100 * (t - Math.floor(t))), n = Math.floor(1e3 * (n - Math.floor(n))), a = Math.floor(1e4 * (a - Math.floor(a))), t + n + a; | |
} | |
const viewcntPat = /var view_cnt = ([0-9]+);/g; | |
const chapterPat = /var chapter = ([0-9]+);/g; | |
const imgListPat = /var img_list = (\[[^\]]+\]);/g; | |
const titlePat = /<title>(.+)<\/title>/g; | |
let tmp = viewcntPat.exec(html); | |
if(tmp){ | |
vcnt = tmp[1]; | |
console.log(`view_cnt : ${vcnt}`); | |
} | |
tmp = chapterPat.exec(html); | |
if(tmp){ | |
chapter = tmp[1]; | |
console.log(`chapter : ${chapter}`); | |
} | |
tmp = titlePat.exec(html); | |
if(tmp){ | |
title = tmp[1]; | |
console.log(`title : ${title}`); | |
} | |
tmp = imgListPat.exec(html); | |
if(tmp){ | |
images = JSON.parse(tmp[1]); | |
console.log('images'); | |
console.dir(images); | |
} | |
seed = vcnt / 10; | |
for(d = [], m = 0; m < 25; m++){ | |
d.push([m, __v()]); | |
} | |
d = d.sort( (e,t)=>{ | |
return (e[1] - t[1]) || (e[0] - t[0]); | |
}); | |
const outdir = path.resolve(__dirname, 'images', title); | |
if( !fs.existsSync( outdir ) ){ | |
fs.mkdirSync(outdir); | |
} | |
images.forEach( (url,i)=>{ | |
loadImage(url).then( img => { | |
const iw = img.width, ih = img.height; | |
const dw = Math.floor(iw / CX), dh = Math.floor(ih / CY); | |
const canv = createCanvas(iw, ih); | |
const ctx = canv.getContext('2d'); | |
const u = dw, g = dh, a=0; | |
for (let p in d) { | |
var h = p % CX, _ = Math.floor(p / CX), f = d[p][0] % CX, v = Math.floor(d[p][0] / CX), s = 1 == a ? -r / 2 : 0; | |
ctx.drawImage(img, h * u, _ * g, u, g, f * u + s, v * g, u, g); | |
} | |
const out = fs.createWriteStream(path.resolve(outdir, `${('0000'+i).substr(-4)}.png`)); | |
canv.createPNGStream().pipe(out); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "mangashowmecroller", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"canvas": "^2.3.1", | |
"request": "^2.88.0", | |
"request-promise-native": "^1.0.7" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment