# pixiv-api-wrapper

> A type safe wrapper for Pixiv App API

Latest version **1.2.2** (published 2023-07-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install pixiv-api-wrapper
pnpm add pixiv-api-wrapper
yarn add pixiv-api-wrapper
bun add pixiv-api-wrapper
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2023-07-03 |
| First published | 2023-06-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 127.4 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Author | zhus-k |
| Maintainers | zhus-k |

## Links

- npm: https://www.npmjs.com/package/pixiv-api-wrapper
- Repository: https://github.com/zhus-k/pixiv-api-wrapper
- Homepage: https://github.com/zhus-k/pixiv-api-wrapper#readme
- Issues: https://github.com/zhus-k/pixiv-api-wrapper/issues
- npm.io page: https://npm.io/package/pixiv-api-wrapper

## Dependencies (4)

- [jimp](https://npm.io/package/jimp.md) ^0.22.8
- [adm-zip](https://npm.io/package/adm-zip.md) ^0.5.10
- [gif-encoder](https://npm.io/package/gif-encoder.md) ^0.7.2
- [puppeteer-core](https://npm.io/package/puppeteer-core.md) ^20.7.2

## Recent versions

- 1.2.2 (latest) — 2023-07-03
- 1.1.1 — 2023-06-17

## README

# **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][^f1].

#### **Authentication Options**:

1. Authenticate with Refresh Token (Recommended)
```typescript 
const client = await PixivApi.create("<your refresh token>");
```

2. Authenticating with ID (Not recommended) *see* [1]
```typescript 
const browser = await puppeteer.launch({ headless: 'new' });
const client = await PixivApi.create({ userId, password }, browser);
```

3. Complete authentication in an opened browser *see* [2]
```typescript 
const client = await PixivApi.create({ userId, password });
```

#### **Retrieve Authenticated User**
```typescript 
const auth = client.Auth.getAuthentication();
const { accessToken, refreshToken, user } = auth;
```

### **API**

```typescript 
const illustDetail = await client.Illust.detail("<artworkId>");
```

### **Util**

#### Downloading illustrations

```typescript 
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

```typescript 
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'](https://www.npmjs.com/package/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]][^f1]:
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.

[^f1]: https://gist.github.com/ZipFile/c9ebedb224406f4f11845ab700124362

## **License**

[MIT licensed](LICENSE)

---
_Source: https://npm.io/package/pixiv-api-wrapper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
