Compare commits
No commits in common. "9d8653e0ac24d6b31c4b23ad0db8f7841b578b27" and "b7642eea4dc620194b4361ee1ca24520b80d4f91" have entirely different histories.
9d8653e0ac
...
b7642eea4d
44
index.js
44
index.js
@ -14,29 +14,13 @@ try {
|
||||
}
|
||||
|
||||
async function get(url) {
|
||||
var res;
|
||||
await (async function tryRequest() {
|
||||
console.log("get", url);
|
||||
try {
|
||||
res = await fetch(url, {
|
||||
headers: {
|
||||
Cookie,
|
||||
Referer: "https://www.pixiv.net/"
|
||||
}
|
||||
});
|
||||
} catch(error) {
|
||||
console.error(error.stack);
|
||||
await sleep(1);
|
||||
await tryRequest();
|
||||
return;
|
||||
console.log("get", url);
|
||||
var res = await fetch(url, {
|
||||
headers: {
|
||||
Cookie,
|
||||
Referer: "https://www.pixiv.net/"
|
||||
}
|
||||
if (res.status == 429) {
|
||||
console.warn(res.status, res.statusText);
|
||||
await sleep(10);
|
||||
await tryRequest();
|
||||
}
|
||||
})();
|
||||
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`${res.url} ${res.status} ${res.statusText} ${await res.text()}`);
|
||||
}
|
||||
@ -53,14 +37,9 @@ async function archiveArtwork(id, index) {
|
||||
for (let i = 0; i < illust.pageCount; i++) {
|
||||
let url = illust.urls.original.replace('p0', 'p'+i);
|
||||
let filename = url.split('/').pop();
|
||||
try {
|
||||
let res = await get(url);
|
||||
let buffer = Buffer.from(await res.arrayBuffer());
|
||||
fs.writeFileSync(`collection/${prefix}_${filename}`, buffer, {flag: "wx"});
|
||||
} catch(error) {
|
||||
console.error(error.stack);
|
||||
fs.writeFileSync(`collection/${prefix}_${filename}_error.txt`, error.stack, {flag: "wx"});
|
||||
}
|
||||
let writeStream = fs.createWriteStream(`collection/${prefix}_${filename}`, {flags: "wx"});
|
||||
let res = await get(url);
|
||||
Readable.fromWeb(res.body).pipe(writeStream);
|
||||
}
|
||||
} catch (error) {
|
||||
fs.writeFileSync(`collection/${prefix}_${id}_error.txt`, error.stack, {flag: "wx"});
|
||||
@ -92,11 +71,6 @@ async function archiveArtwork(id, index) {
|
||||
lastartwork.id = id;
|
||||
lastartwork.index++;
|
||||
fs.writeFileSync("lastartwork.json", JSON.stringify(lastartwork));
|
||||
await sleep(1);
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
async function sleep(seconds) {
|
||||
await new Promise(resolve => setTimeout(resolve, seconds * 1000));
|
||||
}
|
Loading…
Reference in New Issue
Block a user