pixiv-app-api
Promise based pixiv API client
Inspired by upbit/pixivpy: Pixiv API for Python.
Features
- Promise based
- Converts the output json keys to camelCase
- Converts the parameters to snakeCase
- Supports API without login
Install
$ npm install --save pixiv-app-api
Usage
import PixivAppApi from 'pixiv-app-api' //const PixivAppApi = require("pixiv-app-api")
import pixivImg from 'pixiv-img' //const pixivImg = require("pixiv-img")
const pixiv = new PixivAppApi(process.env.NAME, process.env.PASSWORD, {
camelcaseKeys: true,
})
;(async () => {
await pixiv.login()
const json = await pixiv.searchIllust('่ฆใใ10000usersๅ
ฅใ')
await pixivImg(json.illusts[0].imageUrls.large)
console.log('finish')
})()
Typescript
All functions will return either a camelCaseType or a snake_case_type depending on the value of camelcaseKeys
.
For example:
//const pixiv = new PixivAppApi(process.env.NAME, process.env.PASSWORD, {camelcaseKeys: true})
interface PixivClient = {
accessToken: string
expiresIn: number
tokenType: string
scope: string
refreshToken: string
user: PixivClientUser
deviceToken: string
}
//const pixiv = new PixivAppApi(process.env.NAME, process.env.PASSWORD, {camelcaseKeys: false})
interface Pixiv_Client = {
access_token: string
expires_in: number
token_type: string
scope: string
refresh_token: string
user: Pixiv_Client_User
device_token: string
}
API
constructor(username?: string, password?: string, options? {camelcaseKeys?: boolean})
Creates a new PixivAppApi object. camelcaseKeys
defaults to true
if it is omitted.
login(username?: string, password?: string): Promise<PixivClient>
Logs into the API.
{
"accessToken": "abcdefgabcdefgabcdefgabcdefg",
"expiresIn": 3600,
"tokenType": "bearer",
"scope": "unlimited",
"refreshToken": "abcdefgabcdefgabcdefgabcdefg",
"user": {
"profileImageUrls": {
"px16x16": "https://i.pximg.net/user-profile/img/2016/12/07/18/45/34/11842543_d51209fed2b2566336b1296e07f49b81_16.png",
"px50x50": "https://i.pximg.net/user-profile/img/2016/12/07/18/45/34/11842543_d51209fed2b2566336b1296e07f49b81_50.png",
"px170x170": "https://i.pximg.net/user-profile/img/2016/12/07/18/45/34/11842543_d51209fed2b2566336b1296e07f49b81_170.png"
},
"id": "19785907",
"name": "akameco",
"account": "akameco",
"mailAddress": "abcdefgabcdefgabcdefgabcdefg",
"isPremium": true,
"xRestrict": 2,
"isMailAuthorized": true
}
}
authInfo(): PixivClient
Gets your authInfo.
interface PixivClient {
accessToken: string
expiresIn: number
tokenType: string
scope: string
refreshToken: string
user: PixivClientUser
deviceToken: string
}
makeIterable(resp: Object): AsyncIterable<Object>
const json = await pixiv.searchIllust('่ฆใใ10000usersๅ
ฅใ')
let ar = []
for await (const r of pixiv.makeIterable(json)) {
ar = ar.concat(r.illusts)
await sleep(1000) // if the request rate is too high, pixiv might ban you
}
console.log(ar.length)
userDetail(id: ID, params?: PixivParams): Promise<PixivUserDetail>.
Get a user's profile.
export interface PixivUserDetail {
user: PixivUser
profile: {
webpage: string
gender: string
birth: string
birthDay: string
birthYear: number
region: string
addressId: number
countryCode: string
job: string
jobId: number
totalFollowUsers: number
totalMypixivUsers: number
totalIllusts: number
totalManga: number
totalNovels: number
totalIllustBookmarksPublic: number
totalIllustSeries: number
backgroundImageUrl: string
twitterAccount: string
twitterUrl: string
pawooUrl: string
isPremium: boolean
isUsingCustomProfileImage: boolean
}
profilePublicity: {
gender: string
region: string
birthDay: string
birthYear: string
job: string
pawoo: boolean
}
workspace: {
pc: string
monitor: string
tool: string
scanner: string
tablet: string
mouse: string
printer: string
desktop: string
music: string
desk: string
chair: string
comment: string
workspaceImageUrl: string | null
}
}
The type PixivParams is defined as follows:
export interface PixivParams {
userId?: number
type?: string
filter?: string
restrict?: 'public' | 'private'
illustId?: number
contentType?: string
includeTotalComments?: boolean
includeRankingLabel?: boolean
includeRankingIllusts?: boolean
includeRankingNovels?: boolean
mode?:
| 'day'
| 'week'
| 'month'
| 'day_male'
| 'day_female'
| 'week_original'
| 'week_rookie'
| 'day_r18'
| 'day_male_r18'
| 'day_female_r18'
| 'week_r18'
| 'week_r18g'
| 'day_manga'
| 'week_manga'
| 'month_manga'
| 'week_rookie_manga'
| 'day_r18_manga'
| 'week_r18_manga'
| 'week_r18g_manga'
word?: string
searchTarget?:
| 'partial_match_for_tags'
| 'exact_match_for_tags'
| 'title_and_caption'
sort?: 'date_desc' | 'date_asc' | 'popular_desc'
startDate?: string
endDate?: string
offset?: number
}
userIllusts(id: ID, params?: PixivParams): Promise<PixivIllustSearch>
Retrieves all of a users illusts.
export interface PixivIllustSearch {
illusts: PixivIllust[]
nextUrl: string | null
searchSpanLimit?: number
}
{
"illusts": [
{
"id": 64124918,
"title": "Noise Pollution Vol.3",
"type": "illust",
"imageUrls": {
"squareMedium": "https://i.pximg.net/c/360x360_70/img-master/img/2017/07/30/12/20/55/64124918_p0_square1200.jpg",
"medium": "https://i.pximg.net/c/540x540_70/img-master/img/2017/07/30/12/20/55/64124918_p0_master1200.jpg",
"large": "https://i.pximg.net/c/600x1200_90/img-master/img/2017/07/30/12/20/55/64124918_p0_master1200.jpg"
},
"caption": "ๅคใณใๆฐๅใฎโก<br /><br />ๆฑใฌ54b-CREAYUS<br />Noise Pollution Vol.3ใซใฏไผๅ ด้ๅฎA5ใตใคใบใฎใฏใชใขใใกใคใซใใคใใพใใ๏ผๅใซใคใ๏ผๆ๏ผๅ
็๏ผใใชใใชใๆฌก็ฌฌ็ตไบใงใใ<br /><br />ใจใใฎใใชไบ็ด(ใใซใซใฉใผๅ
จๅนด้ฝข)<br /><a href=\"http://www.toranoana.jp/mailorder/article/04/0030/54/88/040030548805.html?rec=circle\" target=\"_blank\">http://www.toranoana.jp/mailorder/article/04/0030/54/88/040030548805.html?rec=circle</a>",
"restrict": 0,
"user": {
"id": 471355,
"name": "ๅตๆ",
"account": "creayus",
"profileImageUrls": {
"medium": "https://i3.pixiv.net/user-profile/img/2014/02/02/00/05/39/7393018_f1ce44676a8c0d902cc49aad2828e510_170.jpg"
},
"isFollowed": true
},
"tags": [
{
"name": "C.C."
},
{
"name": "ใซใซใผใทใฅ"
},
{
"name": "ใซใซC"
},
{
"name": "ใณใผใใฎใขใน"
},
{
"name": "ใณใผใใฎใขใน1000usersๅ
ฅใ"
},
{
"name": "ใซใซใผใทใฅใปใฉใณใใซใผใธ"
}
],
"tools": ["Photoshop", "SAI"],
"createDate": "2017-07-30T12:20:55+09:00",
"pageCount": 5,
"width": 900,
"height": 633,
"sanityLevel": 4,
"metaSinglePage": {},
"metaPages": [
{
"imageUrls": {
"squareMedium": "https://i.pximg.net/c/360x360_70/img-master/img/2017/07/30/12/20/55/64124918_p0_square1200.jpg",
"medium": "https://i.pximg.net/c/540x540_70/img-master/img/2017/07/30/12/20/55/64124918_p0_master1200.jpg",
"large": "https://i.pximg.net/c/600x1200_90/img-master/img/2017/07/30/12/20/55/64124918_p0_master1200.jpg",
"original": "https://i.pximg.net/img-original/img/2017/07/30/12/20/55/64124918_p0.png"
}
},
{
"imageUrls": {
"squareMedium": "https://i.pximg.net/c/360x360_70/img-master/img/2017/07/30/12/20/55/64124918_p1_square1200.jpg",
"medium": "https://i.pximg.net/c/540x540_70/img-master/img/2017/07/30/12/20/55/64124918_p1_master1200.jpg",
"large": "https://i.pximg.net/c/600x1200_90/img-master/img/2017/07/30/12/20/55/64124918_p1_master1200.jpg",
"original": "https://i.pximg.net/img-original/img/2017/07/30/12/20/55/64124918_p1.png"
}
},
{
"imageUrls": {
"squareMedium": "https://i.pximg.net/c/360x360_70/img-master/img/2017/07/30/12/20/55/64124918_p2_square1200.jpg",
"medium": "https://i.pximg.net/c/540x540_70/img-master/img/2017/07/30/12/20/55/64124918_p2_master1200.jpg",
"large": "https://i.pximg.net/c/600x1200_90/img-master/img/2017/07/30/12/20/55/64124918_p2_master1200.jpg",
"original": "https://i.pximg.net/img-original/img/2017/07/30/12/20/55/64124918_p2.png"
}
},
{
"imageUrls": {
"squareMedium": "https://i.pximg.net/c/360x360_70/img-master/img/2017/07/30/12/20/55/64124918_p3_square1200.jpg",
"medium": "https://i.pximg.net/c/540x540_70/img-master/img/2017/07/30/12/20/55/64124918_p3_master1200.jpg",
"large": "https://i.pximg.net/c/600x1200_90/img-master/img/2017/07/30/12/20/55/64124918_p3_master1200.jpg",
"original": "https://i.pximg.net/img-original/img/2017/07/30/12/20/55/64124918_p3.png"
}
},
{
"imageUrls": {
"squareMedium": "https://i.pximg.net/c/360x360_70/img-master/img/2017/07/30/12/20/55/64124918_p4_square1200.jpg",
"medium": "https://i.pximg.net/c/540x540_70/img-master/img/2017/07/30/12/20/55/64124918_p4_master1200.jpg",
"large": "https://i.pximg.net/c/600x1200_90/img-master/img/2017/07/30/12/20/55/64124918_p4_master1200.jpg",
"original": "https://i.pximg.net/img-original/img/2017/07/30/12/20/55/64124918_p4.png"
}
}
],
"totalView": 45180,
"totalBookmarks": 2358,
"isBookmarked": false,
"visible": true,
"isMuted": false,
"totalComments": 33
}
],
"nextUrl": "https://app-api.pixiv.net/v1/user/illusts?user_id=471355&type=illust&filter=for_ios&offset=40"
}
userFollowAdd(id: ID, data?: Object): Promise<unknown>
Follows a user.
userFollowDelete(id: ID, data?: Object): Promise<unknown>
Unfollows a user.
userBookmarksIllust(id: ID, params?: PixivParams): Promise<PixivIllustSearch>
Gets a user's bookmarked illusts.
userFollowing(id: ID, params?: PixivParams): Promise<PixivUserSearch>
Gets the users that a user is following.
export interface PixivUserSearch {
userPreviews: {
user: PixivUser
illusts: PixivIllust[]
novels: PixivNovel[]
isMuted: boolean
}[]
nextUrl: string | null
}
userFollower(id: ID, params?: PixivParams): Promise<PixivUserSearch>
Gets the users who follow a user.
userMypixiv(id: ID, params?: PixivParams): Promise<PixivUserSearch>
Gets your friends on Mypixiv.
userList(id: ID, params?: PixivParams): Promise<unknown>
Gets a user list.
illustDetail(id: ID, params?: PixivParams): Promise<PixivIllustDetail>
Returns detailed info for a pixiv illust.
export interface PixivIllustDetail {
illust: PixivIllust
}
export interface PixivIllust {
id: number
title: string
interface: string
imageUrls: {
squareMedium: string
medium: string
large?: string
}
caption: string
restrict: number
user: PixivUser
tags: PixivTag[]
tools: string[]
createDate: string
pageCount: number
width: number
height: number
sanityLevel: number
metaSinglePage: {
originalImageUrl?: string
}
metaPages: PixivMetaPage[]
totalView: number
totalBookmarks: number
isBookmarked: boolean
visible: boolean
isMuted: boolean
totalComments: number
}
{
"illust": {
"id": 57907953,
"title": "ใญใณใฐใใขใฌใ ใใ",
"type": "illust",
"imageUrls": {
"squareMedium": "https://i.pximg.net/c/360x360_70/img-master/img/2016/07/15/00/08/24/57907953_p0_square1200.jpg",
"medium": "https://i.pximg.net/c/540x540_70/img-master/img/2016/07/15/00/08/24/57907953_p0_master1200.jpg",
"large": "https://i.pximg.net/c/600x1200_90/img-master/img/2016/07/15/00/08/24/57907953_p0_master1200.jpg"
},
"caption": "ใใคใชใผ32โ5 ใใใใจใใใใใพใ๏ผ",
"restrict": 0,
"user": {
"id": 3424578,
"name": "ใใผใใต@ไธๆฅ็ฎๆฑใซ26b",
"account": "burittohiroba",
"profileImageUrls": {
"medium": "https://i2.pixiv.net/user-profile/img/2017/02/07/16/03/00/12115481_03cc0ec0f2580ac4a12a3682929b485a_170.jpg"
},
"isFollowed": false
},
"tags": [
{
"name": "Re:ใผใญใใๅงใใ็ฐไธ็็ๆดป"
},
{
"name": "ใฌใ "
},
{
"name": "ใชใผใญ"
},
{
"name": "ใฌใ (ใชใผใญ)"
},
{
"name": "ใใใญใปใฌใ "
},
{
"name": "ใชใผใญ10000usersๅ
ฅใ"
},
{
"name": "ในใใฌใ "
},
{
"name": "ใกใคใ"
},
{
"name": "ใญใณใฐๅ"
}
],
"tools": [],
"createDate": "2016-07-15T00:08:24+09:00",
"pageCount": 1,
"width": 1000,
"height": 1412,
"sanityLevel": 2,
"metaSinglePage": {
"originalImageUrl": "https://i.pximg.net/img-original/img/2016/07/15/00/08/24/57907953_p0.jpg"
},
"metaPages": [],
"totalView": 191059,
"totalBookmarks": 28918,
"isBookmarked": false,
"visible": true,
"isMuted": false,
"totalComments": 181
}
}
illustNew(params?: PixivParams): Promise<PixivIllustSearch>
Searches new illusts.
illustFollow(params?: PixivParams): Promise<PixivIllustSearch>
Searches new illusts from users you follow.
{
"illusts": [
{
"id": 64419500,
"title": "ใPFRDใChapter.6",
"type": "illust",
"imageUrls": {
"squareMedium": "https://i.pximg.net/c/360x360_70/img-master/img/2017/08/15/00/16/32/64419500_p0_square1200.jpg",
"medium": "https://i.pximg.net/c/540x540_70/img-master/img/2017/08/15/00/16/32/64419500_p0_master1200.jpg",
"large": "https://i.pximg.net/c/600x1200_90/img-master/img/2017/08/15/00/16/32/64419500_p0_master1200.jpg"
},
"caption": "ๆณๅฐๅกๅฒ.็ผๆๅฏๆๅธฆ <br />ๆกๅจ้ฟๅฐๅกๅจ้ขๅ็ๆฐไธชๅคๆดป่
ๆฏไธชไธชไฝ้ฝๅธฆ็ไผค๏ผไปๆ่ตท็ๆถๅฟๆฅ็ไนไผผไนๆฏซๆ ็ซ ๆณ๏ผไฝๅคฉ็็็ด่งไพ็ถๅฆๅ่ญฆ้่ฌๆฅไฟ็ๆฒๆ็้ฟๅฐๅกๅจ็ๅฟใ<br />โๆ่ฟๆฏๅจ...ๅฎณๆไน๏ผโๆๅๅฐๆกๅ็ๅณๆๅพฎๅพฎ้ขคๆ๏ผ้ฟๅฐๅกๅจ่ชๅฒ็่ฝป็ฌโๅต..ๆ่ฟไปฅไธบๆๅทฒ็ปๅฟไบๅฎณๆๆฏไปไนไบๅขโใ<br /><br />ๆฅๅง๏ผไธ็ฎกใไฝ ไปฌใๆฏไปไน๏ผๅ ๅ ๆญฃๆญฃ็ไธๅณ่่ดๅง๏ผ",
"restrict": 0,
"user": {
"id": 22124330,
"name": "่ถ
ๅถใฎ็็ๅก",
"account": "swd3e22",
"profileImageUrls": {
"medium": "https://i4.pixiv.net/user-profile/img/2017/01/10/13/28/42/11988991_bae951a38d31d217fa1eceedc0aafdbe_170.jpg"
},
"isFollowed": true
},
"tags": [
{
"name": "ๅฅณใฎๅญ"
},
{
"name": "่ฝๆธ"
},
{
"name": "ใชใชใธใใซ"
},
{
"name": "ใฐใฉใณใกใคใซ"
},
{
"name": "pixivใใกใณใฟใธใขRD"
},
{
"name": "ไธๆ็ใฎๅพฉๆดป"
},
{
"name": "ๅพฉๆดป่
่จไผๆฆใ้ใ"
}
],
"tools": [],
"createDate": "2017-08-15T00:16:32+09:00",
"pageCount": 1,
"width": 2126,
"height": 1150,
"sanityLevel": 4,
"metaSinglePage": {
"originalImageUrl": "https://i.pximg.net/img-original/img/2017/08/15/00/16/32/64419500_p0.jpg"
},
"metaPages": [],
"totalView": 228,
"totalBookmarks": 63,
"isBookmarked": false,
"visible": true,
"isMuted": false
}
],
"nextUrl": "https://app-api.pixiv.net/v2/illust/follow?restrict=public&offset=30"
}
illustComments(id: ID, params?: PixivParams): Promise<PixivCommentSearch>
Returns the comments on an illust.
export interface PixivCommentSearch {
totalComments: number
comments: PixivComment[]
nextUrl: string | null
}
illustRelated(id: ID, params?: PixivParams): Promise<PixivIllustSearch>
Searches for illusts related to the one provided.
illustRecommended(params?: PixivParams): Promise<PixivIllustSearch>
Returns recommended illusts.
illustRecommendedNologin(params?: PixivParams): Promise<PixivIllustSearch>
Returns recommended illusts (logged out).
illustRanking(params?: PixivParams): Promise<PixivIllustSearch>
Returns top daily illusts by default.
trendingTagsIllust(params?: PixivParams): Promise<PixivTrendTags>
Returns an array of trending tags.
export interface PixivTrendTags {
trend_tags: PixivTag[]
}
searchIllust(word: Word, params?: PixivParams): Promise<PixivIllustSearch>
Searches for illusts with the provided query.
searchNovel(word: Word, params?: PixivParams): Promise<PixivNovelSearch>
Searches for novels with the provided query.
export interface PixivNovelSearch {
novels: PixivNovel[]
nextUrl: string | null
privacyPolicy?: {}
searchSpanLimit?: number
}
searchUser(word: Word, params?: PixivParams): Promise<PixivUserSearch>
Searches for users with the provided query.
searchAutoComplete(word: Word): Promise<PixivAutoComplete>
Returns an array of auto-completed words from the input.
export interface PixivAutoComplete {
searchAutoCompleteKeywords: string[]
}
illustBookmarkDetail(id: ID, params?: PixivParams): Promise<PixivBookmarkDetail>
Returns detailed info on a bookmark.
export interface PixivBookmarkDetail {
isBookmarked: boolean
tags: PixivTag[]
restrict: string
}
{
"bookmarkDetail": {
"isBookmarked": false,
"tags": [
{
"name": "Re:ใผใญใใๅงใใ็ฐไธ็็ๆดป",
"isRegistered": false
},
{
"name": "ใฌใ ",
"isRegistered": false
},
{
"name": "ใชใผใญ",
"isRegistered": false
},
{
"name": "ใฌใ (ใชใผใญ)",
"isRegistered": false
},
{
"name": "ใใใญใปใฌใ ",
"isRegistered": false
},
{
"name": "ใชใผใญ10000usersๅ
ฅใ",
"isRegistered": false
},
{
"name": "ในใใฌใ ",
"isRegistered": false
},
{
"name": "ใกใคใ",
"isRegistered": false
},
{
"name": "ใญใณใฐๅ",
"isRegistered": false
}
],
"restrict": "public"
}
}
illustBookmarkAdd(id: ID, data?: Object): Promise<unknown>
Adds a new bookmark.
illustBookmarkDelete(id: ID, data?: Object): Promise<unknown>
Deletes a bookmark.
userBookmarkTagsIllust(params?: PixivParams): Promise<PixivBookmarkSearch>
Searches your bookmark tags.
export interface PixivBookmarkSearch {
bookmarkTags: PixivTag[]
nextUrl: string | null
}
{
"bookmarkTags": [],
"nextUrl": null
}
novelRecommended(params?: PixivParams): Promise<PixivNovelSearch>
Searches recommended novels.
mangaNew(params?: PixivParams): Promise<unknown>
Searches new manga.
mangaRecommended(params?: PixivParams): Promise<PixivMangaSearch>
Searches recommended manga.
export interface PixivMangaSearch {
illusts: PixivManga[]
rankingIllusts: PixivManga[] | []
privacyPolicy: {}
nextUrl: string | null
}
novelRecommendedNologin(params?: PixivParams): Promise<PixivNovelSearch>
Searches recommended novels (logged out).
novelNew(params?: PixivParams): Promise<PixivNovelSearch>
Searches new novels.
ugoiraMetaData(id: number, params?: PixivParams): Promise<UgoiraMetaData>
Retrieves the zip url and frames for a Pixiv Ugoira.
export interface UgoiraMetaData {
ugoiraMetadata: {
zipUrls: {
medium: string
}
frames: {
file: string
delay: number
}[]
}
}
fetch(target: string, opts?: PixivFetchOptions): Promise<any>
Fetches a route in the Pixiv API and returns the result.
See Sniffer for iOS 6.x Common API ยท upbit/pixivpy Wiki
pixiv.next(): Promise<any>
Return next request result.
usage
pixiv
.searchIllust(word)
.then(() => pixiv.next())
.then(() => pixiv.next())
.then((json) => {
console.log(json)
})
pixiv.hasNext(): boolean
Return true
if pixiv.next()
is able to run.
usage
if (pixiv.hasNext()) {
pixiv.next().then()
}
pixiv.nextQuery(): Promise<string | undefined>
Return next params parameter.
Tests
Export your pixiv username and password before running Tests.
$ export USERNAME=your pixiv username...
$ export PASSWORD=your pixiv password...
$ npm test
Related
- PixivDeck - pixiv client for Desktop like TweetDeck
- pixiv-img - save the image of pixiv
- pixiv-dl - pixiv image downloader
- pixiv-dl-preview - electron pixiv downloader
Contributors
Thanks goes to these wonderful people (emoji key):
akameco |
Austin Huang |
Cake |
Ade Firman Fauzi |
yeti2018 |
maple |
Tenpi |
yanagiragi |
NigridsVa |
Anton Grigoryev |
ใใ |
This project follows the all-contributors specification. Contributions of any kind welcome!
License
MIT ยฉ akameco