Promise based pixiv API client
Inspired by upbit/pixivpy: Pixiv API for Python.
$ npm install --save pixiv-app-api
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')
})()
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
}
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.
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>
userDetail(id: ID, params?: PixivParams): Promise<PixivUserDetail>.
Get a user's profile.
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
}
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
}
illustNew(params?: PixivParams): Promise<PixivIllustSearch>
Searches new illusts.
illustFollow(params?: PixivParams): Promise<PixivIllustSearch>
Searches new illusts from users you follow.
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
}
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
}
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.
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.
if (pixiv.hasNext()) {
pixiv.next().then()
}
pixiv.nextQuery(): Promise<string | undefined>
Return next params parameter.
Export your pixiv username and password before running Tests.
$ export USERNAME=your pixiv username...
$ export PASSWORD=your pixiv password...
$ npm test
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!
MIT © akameco