🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

pixiv-api-wrapper

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pixiv-api-wrapper

A type safe wrapper for Pixiv App API

latest
Source
npmnpm
Version
1.2.2
Version published
Weekly downloads
4
100%
Maintainers
1
Weekly downloads
 
Created
Source

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]1.

Authentication Options:

  • Authenticate with Refresh Token (Recommended)
const client = await PixivApi.create("<your refresh token>");
  • Authenticating with ID (Not recommended) see [1]
const browser = await puppeteer.launch({ headless: 'new' });
const client = await PixivApi.create({ userId, password }, browser);
  • 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.
  • Enable persistent logging ("Preserve log").
  • Type into the filter field: callback?
  • Proceed with Pixiv login.
  • 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

Footnotes

FAQs

Package last updated on 03 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts