Compare commits
No commits in common. "c8a91e54e2e341360f50fae23fb66d03686ff106" and "f2f4a012a3d942affeff83c4ee4122e5247fdeed" have entirely different histories.
c8a91e54e2
...
f2f4a012a3
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,5 +2,5 @@ credentials.json
|
|||||||
known_ids
|
known_ids
|
||||||
logindata
|
logindata
|
||||||
._*
|
._*
|
||||||
*.txt
|
output.txt
|
||||||
node_modules
|
node_modules
|
||||||
|
9
Bot.js
9
Bot.js
@ -18,12 +18,11 @@ export default class Bot {
|
|||||||
form.append("grant_type", "password");
|
form.append("grant_type", "password");
|
||||||
form.append("username", this.username);
|
form.append("username", this.username);
|
||||||
form.append("password", this.password);
|
form.append("password", this.password);
|
||||||
var res = await fetch(this.url + "/oauth/token", {
|
var data = await fetch(this.url + "/oauth/token", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: form
|
body: form
|
||||||
});
|
}).then(res => res.json());
|
||||||
if (!res.ok) throw new Error("HTTP "+ res.status);
|
this.loginData = data;
|
||||||
this.loginData = await res.json();
|
|
||||||
writeFileSync(`logindata/${this.username}.json`, JSON.stringify(this.loginData));
|
writeFileSync(`logindata/${this.username}.json`, JSON.stringify(this.loginData));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +46,6 @@ export default class Bot {
|
|||||||
"Authorization": `${this.loginData.token_type} ${this.loginData.access_token}`
|
"Authorization": `${this.loginData.token_type} ${this.loginData.access_token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!res.ok) throw new Error("HTTP "+ res.status);
|
|
||||||
var json = await res.json();
|
var json = await res.json();
|
||||||
console.log("posted", res.status, json.uri || json);
|
console.log("posted", res.status, json.uri || json);
|
||||||
return json;
|
return json;
|
||||||
@ -63,7 +61,6 @@ export default class Bot {
|
|||||||
"Authorization": `${this.loginData.token_type} ${this.loginData.access_token}`
|
"Authorization": `${this.loginData.token_type} ${this.loginData.access_token}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!res.ok) throw new Error("HTTP "+ res.status);
|
|
||||||
var json = await res.json();
|
var json = await res.json();
|
||||||
console.log("uploaded file", res.status, json.url);
|
console.log("uploaded file", res.status, json.url);
|
||||||
return json;
|
return json;
|
||||||
|
25
index.js
25
index.js
@ -1,12 +1,9 @@
|
|||||||
import {unescape} from 'html-escaper';
|
import {unescape} from 'html-escaper';
|
||||||
import fetchRetry from "fetch-retry";
|
|
||||||
import { appendFileSync } from "fs";
|
|
||||||
import credentials from "./credentials.json" assert { type: 'json' };
|
import credentials from "./credentials.json" assert { type: 'json' };
|
||||||
import Bot from "./Bot.js";
|
import Bot from "./Bot.js";
|
||||||
import { getPostDataById, getNewPixivPosts } from "./pixiv.js";
|
import { getPostDataById, getNewPixivPosts } from "./pixiv.js";
|
||||||
|
|
||||||
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
|
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
|
||||||
global.fetch = fetchRetry(global.fetch);
|
|
||||||
|
|
||||||
var mikubot = new Bot({
|
var mikubot = new Bot({
|
||||||
url: "https://mikuobsession.net",
|
url: "https://mikuobsession.net",
|
||||||
@ -29,15 +26,17 @@ await mikubot_nsfw.login();
|
|||||||
|
|
||||||
var newPosts = await getNewPixivPosts("初音ミク");
|
var newPosts = await getNewPixivPosts("初音ミク");
|
||||||
|
|
||||||
for (let post of newPosts) {
|
posts: for (let post of newPosts) {
|
||||||
let bot = post.xRestrict ? mikubot_nsfw : mikubot;
|
let bot = post.xRestrict ? mikubot_nsfw : mikubot;
|
||||||
let url = `https://www.pixiv.net/en/artworks/${post.id}`;
|
let url = `https://www.pixiv.net/en/artworks/${post.id}`;
|
||||||
|
let attempts = 0, error;
|
||||||
|
do {
|
||||||
|
attempts++;
|
||||||
|
if (attempts > 1) console.log("attempt", attempts);
|
||||||
try {
|
try {
|
||||||
let {images, illust} = await getPostDataById(post.id);
|
let {images, illust} = await getPostDataById(post.id);
|
||||||
let date = new Date(illust.createDate);
|
let date = new Date(illust.createDate).toLocaleString("en-US", {timeZone: "JST", month: "long", day: "numeric", year: "numeric"});
|
||||||
let dateString = date.toLocaleDateString("en-US", {timeZone: "JST", month: "long", day: "numeric", year: "numeric"});
|
let status = `<b>${illust.title}</b> / ${illust.userName} / ${date}<br>${unescape(illust.description)}<br>${illust.aiType == 2 ? `#AIgenerated ` : ''}${post.tags.map(tag => `#${tag}`).join(" ")}<br>${url}<br>https://www.pixiv.net/en/users/${illust.userId}`;
|
||||||
let timeString = date.toLocaleTimeString("en-US", {timeZone: "JST", hour12: true, hour: "numeric", "minute": "numeric"}) + " JST";
|
|
||||||
let status = `<b>${illust.title}</b> / ${illust.userName} / ${dateString} ${timeString}<br>${unescape(illust.description)}<br>${illust.aiType == 2 ? `#AIgenerated ` : ''}${post.tags.map(tag => `#${tag}`).join(" ")}<br>${url}<br>https://www.pixiv.net/en/users/${illust.userId}`;
|
|
||||||
if (images.length > 4) {
|
if (images.length > 4) {
|
||||||
status += `<br>⚠ There are ${images.length} images.`;
|
status += `<br>⚠ There are ${images.length} images.`;
|
||||||
}
|
}
|
||||||
@ -48,12 +47,14 @@ for (let post of newPosts) {
|
|||||||
sensitive: Boolean(post.xRestrict),
|
sensitive: Boolean(post.xRestrict),
|
||||||
visibility: "public"
|
visibility: "public"
|
||||||
});
|
});
|
||||||
appendFileSync(`known_ids/初音ミク.txt`, "\n" + post.id);
|
continue posts;
|
||||||
} catch(error) {
|
} catch(e) {
|
||||||
console.error(error.stack);
|
console.error(e.stack);
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
} while (attempts < 3)
|
||||||
await bot.post({
|
await bot.post({
|
||||||
status: `${url}\n#error\n${error.stack}`,
|
status: `${url}\n#error\n${error.stack}`,
|
||||||
visibility: "public"
|
visibility: "public"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
11
package-lock.json
generated
11
package-lock.json
generated
@ -5,15 +5,9 @@
|
|||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fetch-retry": "^6.0.0",
|
|
||||||
"html-escaper": "^3.0.3"
|
"html-escaper": "^3.0.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/fetch-retry": {
|
|
||||||
"version": "6.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/fetch-retry/-/fetch-retry-6.0.0.tgz",
|
|
||||||
"integrity": "sha512-BUFj1aMubgib37I3v4q78fYo63Po7t4HUPTpQ6/QE6yK6cIQrP+W43FYToeTEyg5m2Y7eFUtijUuAv/PDlWuag=="
|
|
||||||
},
|
|
||||||
"node_modules/html-escaper": {
|
"node_modules/html-escaper": {
|
||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz",
|
||||||
@ -21,11 +15,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fetch-retry": {
|
|
||||||
"version": "6.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/fetch-retry/-/fetch-retry-6.0.0.tgz",
|
|
||||||
"integrity": "sha512-BUFj1aMubgib37I3v4q78fYo63Po7t4HUPTpQ6/QE6yK6cIQrP+W43FYToeTEyg5m2Y7eFUtijUuAv/PDlWuag=="
|
|
||||||
},
|
|
||||||
"html-escaper": {
|
"html-escaper": {
|
||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz",
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fetch-retry": "^6.0.0",
|
|
||||||
"html-escaper": "^3.0.3"
|
"html-escaper": "^3.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
pixiv.js
8
pixiv.js
@ -21,7 +21,8 @@ export async function getNewPixivPosts(tag = "初音ミク") {
|
|||||||
}
|
}
|
||||||
}).then(res => res.json());
|
}).then(res => res.json());
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
throw new Error(JSON.stringify(data));
|
console.error(data);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let post of data.body.illustManga.data) {
|
for (let post of data.body.illustManga.data) {
|
||||||
@ -35,8 +36,7 @@ export async function getNewPixivPosts(tag = "初音ミク") {
|
|||||||
await sleep(1);
|
await sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newPosts.reverse();
|
return {
|
||||||
/*return {
|
|
||||||
[Symbol.iterator]() {
|
[Symbol.iterator]() {
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
@ -47,7 +47,7 @@ export async function getNewPixivPosts(tag = "初音ミク") {
|
|||||||
}
|
}
|
||||||
return {value, done: !Boolean(value)}
|
return {value, done: !Boolean(value)}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sleep(seconds) {
|
async function sleep(seconds) {
|
||||||
|
Loading…
Reference in New Issue
Block a user