|
@@ -27,15 +27,16 @@ class Webshot extends CallableInstance {
|
|
this.renderWebshot = (url, height, webshotDelay) => {
|
|
this.renderWebshot = (url, height, webshotDelay) => {
|
|
const writeOutPic = (pic) => writeOutTo(`${this.outDir}/${url.replace(/[:\/]/g, '_')}.png`, pic);
|
|
const writeOutPic = (pic) => writeOutTo(`${this.outDir}/${url.replace(/[:\/]/g, '_')}.png`, pic);
|
|
const promise = new Promise(resolve => {
|
|
const promise = new Promise(resolve => {
|
|
- const width = 600;
|
|
|
|
|
|
+ const width = 1080;
|
|
logger.info(`shooting ${width}*${height} webshot for ${url}`);
|
|
logger.info(`shooting ${width}*${height} webshot for ${url}`);
|
|
this.browser.newPage()
|
|
this.browser.newPage()
|
|
.then(page => {
|
|
.then(page => {
|
|
page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36')
|
|
page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36')
|
|
.then(() => page.setViewport({
|
|
.then(() => page.setViewport({
|
|
- width,
|
|
|
|
- height,
|
|
|
|
|
|
+ width: width / 2,
|
|
|
|
+ height: height / 2,
|
|
isMobile: true,
|
|
isMobile: true,
|
|
|
|
+ deviceScaleFactor: 2,
|
|
}))
|
|
}))
|
|
.then(() => page.setBypassCSP(true))
|
|
.then(() => page.setBypassCSP(true))
|
|
.then(() => page.goto(url, { waitUntil: 'load', timeout: 150000 }))
|
|
.then(() => page.goto(url, { waitUntil: 'load', timeout: 150000 }))
|
|
@@ -54,11 +55,17 @@ class Webshot extends CallableInstance {
|
|
}).on('parsed', function () {
|
|
}).on('parsed', function () {
|
|
// remove comment area
|
|
// remove comment area
|
|
let boundary = null;
|
|
let boundary = null;
|
|
- let x = 0;
|
|
|
|
|
|
+ let x = Math.floor(this.width / 180);
|
|
for (let y = 0; y < this.height; y++) {
|
|
for (let y = 0; y < this.height; y++) {
|
|
const idx = (this.width * y + x) << 2;
|
|
const idx = (this.width * y + x) << 2;
|
|
if (this.data[idx] !== 255) {
|
|
if (this.data[idx] !== 255) {
|
|
- boundary = y;
|
|
|
|
|
|
+ if (this.data[idx + this.width * 10] !== 255) {
|
|
|
|
+ // footer kicks in
|
|
|
|
+ boundary = null;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ boundary = y;
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -67,7 +74,7 @@ class Webshot extends CallableInstance {
|
|
this.data = this.data.slice(0, (this.width * boundary) << 2);
|
|
this.data = this.data.slice(0, (this.width * boundary) << 2);
|
|
this.height = boundary;
|
|
this.height = boundary;
|
|
boundary = null;
|
|
boundary = null;
|
|
- x = Math.floor(this.width / 2);
|
|
|
|
|
|
+ x = Math.floor(this.width / 30);
|
|
let flag = false;
|
|
let flag = false;
|
|
let cnt = 0;
|
|
let cnt = 0;
|
|
for (let y = this.height - 1; y >= 0; y--) {
|
|
for (let y = this.height - 1; y >= 0; y--) {
|
|
@@ -79,11 +86,11 @@ class Webshot extends CallableInstance {
|
|
else
|
|
else
|
|
continue;
|
|
continue;
|
|
// line above the "comment", "retweet", "like", "share" button row
|
|
// line above the "comment", "retweet", "like", "share" button row
|
|
- if (cnt === 6) {
|
|
|
|
|
|
+ if (cnt === 2) {
|
|
boundary = y + 1;
|
|
boundary = y + 1;
|
|
}
|
|
}
|
|
// if there are a "retweet" count and "like" count row, this will be the line above it
|
|
// if there are a "retweet" count and "like" count row, this will be the line above it
|
|
- if (cnt === 8) {
|
|
|
|
|
|
+ if (cnt === 4) {
|
|
const b = y + 1;
|
|
const b = y + 1;
|
|
if (this.height - b <= 200)
|
|
if (this.height - b <= 200)
|
|
boundary = b;
|
|
boundary = b;
|
|
@@ -95,20 +102,20 @@ class Webshot extends CallableInstance {
|
|
this.data = this.data.slice(0, (this.width * boundary) << 2);
|
|
this.data = this.data.slice(0, (this.width * boundary) << 2);
|
|
this.height = boundary;
|
|
this.height = boundary;
|
|
}
|
|
}
|
|
- writeOutPic(this.pack()).then(data => {
|
|
|
|
|
|
+ writeOutPic(this.pack()).then(path => {
|
|
logger.info(`finished webshot for ${url}`);
|
|
logger.info(`finished webshot for ${url}`);
|
|
- resolve({ data, boundary });
|
|
|
|
|
|
+ resolve({ path, boundary });
|
|
});
|
|
});
|
|
}
|
|
}
|
|
else if (height >= 8 * 1920) {
|
|
else if (height >= 8 * 1920) {
|
|
logger.warn('too large, consider as a bug, returning');
|
|
logger.warn('too large, consider as a bug, returning');
|
|
- writeOutPic(this.pack()).then(data => {
|
|
|
|
- resolve({ data, boundary: 0 });
|
|
|
|
|
|
+ writeOutPic(this.pack()).then(path => {
|
|
|
|
+ resolve({ path, boundary: 0 });
|
|
});
|
|
});
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
logger.info('unable to find boundary, try shooting a larger image');
|
|
logger.info('unable to find boundary, try shooting a larger image');
|
|
- resolve({ data: '', boundary });
|
|
|
|
|
|
+ resolve({ path: '', boundary });
|
|
}
|
|
}
|
|
}).parse(screenshot);
|
|
}).parse(screenshot);
|
|
})
|
|
})
|
|
@@ -119,7 +126,7 @@ class Webshot extends CallableInstance {
|
|
if (data.boundary === null)
|
|
if (data.boundary === null)
|
|
return this.renderWebshot(url, height + 1920, webshotDelay);
|
|
return this.renderWebshot(url, height + 1920, webshotDelay);
|
|
else
|
|
else
|
|
- return data.data;
|
|
|
|
|
|
+ return data.path;
|
|
});
|
|
});
|
|
};
|
|
};
|
|
this.fetchImage = (url, tag) => new Promise(resolve => {
|
|
this.fetchImage = (url, tag) => new Promise(resolve => {
|
|
@@ -151,19 +158,8 @@ class Webshot extends CallableInstance {
|
|
onready();
|
|
onready();
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- puppeteer.launch({
|
|
|
|
- args: [
|
|
|
|
- '--no-sandbox',
|
|
|
|
- '--disable-setuid-sandbox',
|
|
|
|
- '--disable-dev-shm-usage',
|
|
|
|
- '--disable-accelerated-2d-canvas',
|
|
|
|
- '--no-first-run',
|
|
|
|
- '--no-zygote',
|
|
|
|
- '--single-process',
|
|
|
|
- '--disable-gpu',
|
|
|
|
- '--lang=ja-JP,ja',
|
|
|
|
- ]
|
|
|
|
- })
|
|
|
|
|
|
+ // use local Chromium
|
|
|
|
+ puppeteer.connect({ browserURL: 'http://127.0.0.1:9222' })
|
|
.then(browser => this.browser = browser)
|
|
.then(browser => this.browser = browser)
|
|
.then(() => {
|
|
.then(() => {
|
|
logger.info('launched puppeteer browser');
|
|
logger.info('launched puppeteer browser');
|
|
@@ -209,18 +205,18 @@ class Webshot extends CallableInstance {
|
|
if (webshotFilePath)
|
|
if (webshotFilePath)
|
|
messageChain.push(mirai_1.MiraiMessage.Image('', '', baseName(webshotFilePath)));
|
|
messageChain.push(mirai_1.MiraiMessage.Image('', '', baseName(webshotFilePath)));
|
|
});
|
|
});
|
|
- // fetch extra images
|
|
|
|
}
|
|
}
|
|
- else if (1 - this.mode % 2) {
|
|
|
|
|
|
+ // fetch extra images
|
|
|
|
+ if (1 - this.mode % 2) {
|
|
if (originTwi.extended_entities) {
|
|
if (originTwi.extended_entities) {
|
|
originTwi.extended_entities.media.forEach(media => promise = promise.then(() => this.fetchImage(media.media_url_https + ':orig', `${twi.user.screen_name}-${twi.id_str}--`)
|
|
originTwi.extended_entities.media.forEach(media => promise = promise.then(() => this.fetchImage(media.media_url_https + ':orig', `${twi.user.screen_name}-${twi.id_str}--`)
|
|
.then(path => {
|
|
.then(path => {
|
|
messageChain.push(mirai_1.MiraiMessage.Image('', '', baseName(path)));
|
|
messageChain.push(mirai_1.MiraiMessage.Image('', '', baseName(path)));
|
|
})));
|
|
})));
|
|
}
|
|
}
|
|
- // append URLs, if any
|
|
|
|
}
|
|
}
|
|
- else if (this.mode === 0) {
|
|
|
|
|
|
+ // append URLs, if any
|
|
|
|
+ if (this.mode === 0) {
|
|
if (originTwi.entities && originTwi.entities.urls && originTwi.entities.urls.length) {
|
|
if (originTwi.entities && originTwi.entities.urls && originTwi.entities.urls.length) {
|
|
promise = promise.then(() => {
|
|
promise = promise.then(() => {
|
|
const urls = originTwi.entities.urls
|
|
const urls = originTwi.entities.urls
|