tenpi / pixiv.ts Goto Github PK
View Code? Open in Web Editor NEWWrapper for the Pixiv API with typings
License: MIT License
Wrapper for the Pixiv API with typings
License: MIT License
Can I log in with cookies (PHPSESSID) that I could get from pixiv page?
I tried using Pixiv.refreshLogin()
with my cookies as the parameter and it doesn't work.
Can we improve this method to support login with cookies too?
Search Illusts only shows the first page and 30 results
所有与r18相关的都试了一遍
I'm not very sure if I am using it wrongly, here's my code snippet:
const pixiv = await Pixiv.default.refreshLogin(refreshToken);
const word = 'ロリ';
let illusts = await pixiv.search.illusts({ word: word, r18: false, type:'illust', bookmarks: '1000' });
if (pixiv.search.nextURL) illusts = [...illusts, ...await pixiv.util.multiCall({ next_url: pixiv.search.nextURL, illusts }, 2)];
I noticed that no matter what number I use for limit (which is 2 in the code above), it always ends up returning Error: Request failed with status code 400
. If no limit is provided, it will end up returning Error: Request failed with status code 403
.
Also, using await Pixiv.refreshLogin(refreshToken)
like the example in the readme.md will not work. An error will pop up saying TypeError: Pixiv.refreshLogin is not a function
. It took me quite a while to figure out that I have to use Pixiv.default.refreshLogin
instead.
I am reopening this issue because the previous one was closed but the issue is still there.
Here is what i came up with to 'solve' the issue
const img_dir = "./downloaded";
await client.util.downloadIllust(url, img_dir, "original");
// should be downloaded by now
let exit = false;
let prev_hash = "";
let images: string[] = [];
while(true) {
let images_stats = fs.readdirSync(img_dir);
let curr_hash = "";
images = [];
for (const image_stats of images_stats) {
const file = img_dir + "/" + image_stats;
images.push(file);
curr_hash += await getFileHash(file);
}
if(exit) {
break;
}
if (prev_hash != curr_hash || !curr_hash.length) {
debug(`hash mismatch, waiting... (${prev_hash} || ${curr_hash})`);
}
exit = prev_hash == curr_hash && curr_hash.length > 0;
prev_hash = curr_hash;
await sleep(1000);
}
// by this point the images are downloaded, but the solution is mega-crap
here is the output
hash mismatch, waiting... (c397c6d991c6ddc033cc089b33a412355 || af1349b9f5f9a1a6a0404dea36dcc9499)
hash mismatch, waiting... (af1349b9f5f9a1a6a0404dea36dcc9497 || efb763f51eb0780232d81f86cdc86135c)
hash mismatch, waiting... (a2344fc328fe26a3ff5f241c10ba91071 || 9183ef0552ac039c012bec3885eb85d79)
hash mismatch, waiting... (2b90f3912a26806e03a96f0a107870f16 || 015537fcb4eee269792ed88ad1d7bdb84)
hash mismatch, waiting... (b90f3912a26806e03a96f0a107870f167 || 12a26806e03a96f0a107870f167258f9a)
as you can see, the hash changes which means that the files are still downloading, please don't close this issue blaming me, this is clearly a problem in the library
Tried to login but I get an error:
Relevant code:
import Pixiv from 'pixiv.ts';
import { env } from './environment';
let client: Pixiv;
export async function usePixivClient() {
if (!client) {
client = await Pixiv.login(env.pixiv.username, env.pixiv.password);
}
async function getUserIllustrations(params: Parameters<typeof client['user']['illusts']>[0]) {
return await client.user.illusts(params);
}
return {
getUserIllustrations,
};
}
I literally just took your example with the hashes and it doesn't work.
await client.util.downloadIllust(url, "./downloads", "original");
const files = fs.readdirSync(path.join(__dirname, "../downloads")).map((p) => {
return path.join(__dirname, "../downloads", p)
})
const hash = crypto.createHash("md5").update(fs.readFileSync(files[0])).digest("hex")
console.log(hash);
for(let i = 1; i < 5; i++) {
setTimeout(() => {
const hash2 = crypto.createHash("md5").update(fs.readFileSync(files[0])).digest("hex")
console.log(hash2)
console.log(hash === hash2)
}, i * 1000)
}
the output is as follows
2a96de86c25cd98a85c89debfed3fe4e
7cbe45c3c4fdf5cf4c3cd0ae78ee1a1b -- after a second
false
aad8d30495ccc35463511dc27bd0e52d -- after 2 seconds
false
f56fb56448ec3df54eb0986a81ce0554 -- after 3 seconds
false
4528e847c998aa0617f56412ca11a624 -- after 4 seconds
false
25cd98a8aaaad7f56412e4e2a96de86c -- after 5 seconds
false
please dont close the damn issue, let's discuss this, I just don't see where this is my problem
here is the post I tried it on: https://www.pixiv.net/en/artworks/98079929
It contains 3 images by the way
Basically I want to download images to a folder and after they are downloaded, convert and move them to another folder.
This does not work and crashed with [Error: VipsJpeg: Premature end of input file]
because files didn't finish downloading yet
const illust = await client.illust.get(url);
const img_dir = "./downloaded";
await sendToChannel(channel, `📥 Downloading from pixiv`);
await client.util.downloadIllust(illust, img_dir, "original");
let images = walk(img_dir);
for (const image of images) {
const new_file_name = getFileName(image);
const new_file_path = await getFilePath(new_file_name, channel);
if(new_file_path) {
await processAndSaveImage(fs.createReadStream(image));
fs.unlinkSync(image);
}
However, if i add sleep(5000);
before walk(img_dir);
it works, which means that await client.util.downloadIllust(illust, img_dir, "original");
does not actually wait untill all images are saved
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.