1.2.2 • Published 10 months ago

pixiv-api-wrapper v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

pixiv-api-wrapper

A type safe wrapper for Pixiv App API.

How to use

Authentication

It recommended you authenticate with Refresh Token as ID authentication can easily produce errors in from browser processes. To retrieve your Refresh Token you may try to authenticate through Options 2 or 3 or through another program.

Authentication Options:

  1. Authenticate with Refresh Token (Recommended)
const client = await PixivApi.create("<your refresh token>");
  1. Authenticating with ID (Not recommended) see 1
const browser = await puppeteer.launch({ headless: 'new' });
const client = await PixivApi.create({ userId, password }, browser);
  1. Complete authentication in an opened browser see 2
const client = await PixivApi.create({ userId, password });

Retrieve Authenticated User

const auth = client.Auth.getAuthentication();
const { accessToken, refreshToken, user } = auth;

API

const illustDetail = await client.Illust.detail("<artworkId>");

Util

Downloading illustrations

const illustDetail = await client.Illust.detail("<artworkId>");
const downloadResults = await Utils.downloadIllusts(illustDetail);
	for (const result of downloadResults) {
		if (result.status == 'fulfilled') {
			const { data, metadata: { fileName, fileExtension } } = result.value;
					// save to file or do something else
			fs.writeFileSync(`${fileName}.${fileExtension}`, data);
		} else {
			const { reason } = result;
      		// handle 'rejected'
		}
	}

Downloading gif

const ugoiraMetadata = await client.Ugoira.metadata("<artworkId>");
const { metadata: { fileName, fileExtension }, data } = await Utils.downloadUgoira(ugoiraMetadata);
fs.writeFileSync(`${fileName}.${fileExtension}`, data);

1: Puppeteer is optional, however it is required if you choose to authenticate by ID in a headless browser. Recommended to use 'puppeteer-chromium-resolver' if you find difficulty.

2: If no puppeteer browser is provided, you will be prompted to enter a code by having to manually complete the login in the opened browser [source]: 1. Open dev console (F12) and switch to network tab. 2. Enable persistent logging ("Preserve log"). 3. Type into the filter field: callback? 4. Proceed with Pixiv login. 5. After logging in you should see a blank page and request that looks like this: https://app-api.pixiv.net/web/v1/users/auth/pixiv/callback?state=...&code=.... Copy value of the code parameter into the prompt and hit the Enter key.

License

MIT licensed

1.2.0

10 months ago

1.1.1

11 months ago

1.0.2

11 months ago

1.1.0

11 months ago

1.0.0

11 months ago

1.2.2

10 months ago

1.2.1

10 months ago

1.0.0-a

11 months ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago