Bangumi

bangumi~ Bangumi

new Bangumi(optionsopt)

Represents the Bangumi API client.
Source:
Parameters:
Name Type Attributes Description
options Object <optional>
Configuration options.
Name Type Attributes Description
app_id string <optional>
App ID used to identify the source (deprecated).
access_token string <optional>
Access token used to identify the user.
protocol string <optional>
HTTP protocol used for the API (e.g., 'http' or 'https').
user_agent string <optional>
Custom user agent. See https://github.com/bangumi/api/blob/master/docs-raw/user%20agent.md for more information.
Example
const Bangumi = require('bangumi');
const bgm = new Bangumi({
  access_token: "123456"
});

Methods

auth(params, callbackopt) → {Promise}

A POST method that login user with username and password, and returns auth string
Deprecated:
  • since version 1.0.0, newer version of api will use oauth.
Source:
Parameters:
Name Type Attributes Description
params object Parameters for the request
Name Type Description
username string Username or UID of the target user
password string Password for the target user
callback function <optional>
Optional callback function
Returns:
Type:
Promise
- Returns a promise if no callback is provided

createCollection(subject_id, paramsopt, callbackopt) → {Promise}

A POST method that updates user's status on specific subject by subject id
Source:
Parameters:
Name Type Attributes Description
subject_id number ID of the target subject
params object <optional>
Optional parameters for the request
Name Type Attributes Default Description
status string <optional>
wish Accepts [wish|collect|do|on_hold|dropped]
comment string <optional>
Comment on the target subject status update
tags string <optional>
Tags on the target subject status update, separated by comma
rating number <optional>
Star rating on the target subject, accepts [0~10]
privacy number <optional>
Privacy control of this action, accepts [0|1] (0.open, 1.private)
callback function <optional>
Optional callback function
Returns:
Type:
Promise
- Returns a promise if no callback is provided
Example
bgm.createCollection(211567, {status: 'do', rating: 10});

fetchCalendar(callbackopt) → {Promise|undefined}

A GET method that gets current weekly shows' seclude
Source:
Parameters:
Name Type Attributes Description
callback function <optional>
Optional callback function
Returns:
Type:
Promise | undefined
- Returns a promise if no callback is provided

fetchCollection(subject_id, paramsopt, callbackopt) → {Promise}

A GET method that get current user's collection details on specific subject by subject id
Source:
Parameters:
Name Type Attributes Description
subject_id number ID of the target subject
params object <optional>
Optional parameters for the request
Name Type Attributes Description
auth string <optional>
Authentication string used for validation of user identity, deprecated
callback function <optional>
Optional callback function
Returns:
Type:
Promise
- Returns a promise if no callback is provided
Example
bgm.fetchCollection(1);

fetchEps(subject_id, callbackopt) → {Promise}

A GET method that gets a list of episodes of a subject by subject id
Deprecated:
  • use fetchSubjectEps
Source:
Parameters:
Name Type Attributes Description
subject_id number ID of the target subject
callback function <optional>
Optional callback function
Returns:
Type:
Promise
- Returns a promise if no callback is provided

fetchProgress(username, paramsopt, callbackopt) → {Promise}

A GET method that get lists of episodes that user already watched, sorted by subject id
Source:
Parameters:
Name Type Attributes Description
username string | number Username or UID of the target user
params object <optional>
Optional parameters for the request
Name Type Attributes Description
subject_id number <optional>
The ID of the subject the user wants to fetch progress for
auth string <optional>
Authentication string used for validation of user identity, deprecated
callback function <optional>
Optional callback function
Returns:
Type:
Promise
- Returns a promise if no callback is provided
Example
bgm.fetchProgress(1, {subject_id:899}).then(console.log);

fetchSubject(subject_id, paramsopt, callbackopt) → {Promise.<Subject>}

A GET method that gets details of a subject by id
Source:
Parameters:
Name Type Attributes Description
subject_id number ID of the target subject
params Object <optional>
Optional parameters for the request
Name Type Attributes Description
responseGroup string <optional>
Accepts [small|medium|large]
callback function <optional>
Optional callback function
Returns:
Type:
Promise.<Subject>
- Returns a promise that resolves to the subject details

fetchSubjectEps(subject_id, callbackopt) → {Promise}

A GET method that gets a list of episodes of a subject by subject id
Source:
Parameters:
Name Type Attributes Description
subject_id number ID of the target subject
callback function <optional>
Optional callback function
Returns:
Type:
Promise
- Returns a promise if no callback is provided
Example
bgm.fetchSubjectEps(211567);

fetchUser(username, callbackopt) → {Promise|undefined}

A GET method that gets target user's profile
Source:
Parameters:
Name Type Attributes Description
username string | number Username or UID of the target user
callback function <optional>
Optional callback function
Returns:
Type:
Promise | undefined
- Returns a promise if no callback is provided

fetchUserCollection(username, params, callbackopt) → {Promise}

A GET method that gets details of user's collection by user id
Source:
Parameters:
Name Type Attributes Description
username string | number Username or UID of the target user
params object Parameters for the request
Name Type Attributes Description
cat string Type of the collections, accepts [watching|all_watching]
responseGroup string <optional>
Type of the collections, accepts [medium|small]
ids string <optional>
IDs of subjects the user wants to fetch, this is very poorly implemented at the moment
callback function <optional>
Optional callback function
Returns:
Type:
Promise
- Returns a promise if no callback is provided
Example
bgm.fetchUserCollection(1, {cat:'all_watching', responseGroup: 'small'}).then(console.log)

fetchUserCollections(username, subject_type, paramsopt, callbackopt) → {Promise}

A GET method that gets overview of user's collection by username and subject type
Source:
Parameters:
Name Type Attributes Description
username string | number Username or UID of the target user
subject_type string Type of subject
params object <optional>
Optional parameters for the request
Name Type Attributes Description
max_results number <optional>
Upper limit of the amount of subjects the client can fetch (max 25)
callback function <optional>
Optional callback function
Returns:
Type:
Promise
- Returns a promise if no callback is provided
Example
bgm.fetchUserCollections('sai', 'real', {max_results: 1}).then(console.log).catch(console.error)

fetchUserCollectionsStatus(username, paramsopt, callbackopt) → {Promise}

A GET method that gets overview of user's collection statics by username
Source:
Parameters:
Name Type Attributes Description
username string | number Username or UID of the target user
params object <optional>
Optional parameters for the request
callback function <optional>
Optional callback function
Returns:
Type:
Promise
- Returns a promise if no callback is provided
Example
bgm.fetchUserCollectionsStatus('sai').then(console.log).catch(console.error)

get(url, params, callbackopt) → {Promise|undefined}

A general GET request method for Bangumi API
Source:
Parameters:
Name Type Attributes Description
url string Base GET request path
params object Parameters used for GET query string
callback function <optional>
Optional callback function
Returns:
Type:
Promise | undefined
- Returns a promise if no callback is provided, otherwise undefined

post(url, params, callbackopt) → {Promise|undefined}

A general POST request method for Bangumi API
Source:
Parameters:
Name Type Attributes Description
url string Base POST request path
params object Parameters used for POST body
callback function <optional>
Optional callback function
Returns:
Type:
Promise | undefined
- Returns a promise if no callback is provided
A GET method that searches and returns a list of subjects by keywords
Source:
Parameters:
Name Type Attributes Description
keywords string Query string for search
params object <optional>
Optional parameters for the request
Name Type Attributes Description
responseGroup string <optional>
Accepts [small|medium|large]
type number <optional>
Accepts [1|2|3|4|6] (1.book 2.anime 3.music 4.game 5.live action)
start number <optional>
Result start index, used for paging
max_results number <optional>
The number of entries to return, max 25
callback function <optional>
Optional callback function
Returns:
Type:
Promise
- Returns a promise if no callback is provided
Example
bgm.search('天元突破');

setAccessToken(access_token)

Updates the access token in case it's refreshed.
Source:
Parameters:
Name Type Description
access_token string The new access token.
Example
bgm.setAccessToken('123456');

setPromiseProvider(provider)

Sets a custom promise provider. By default, the Node.js ES6 promise provider is used.
Source:
Parameters:
Name Type Description
provider function Custom promise provider.
Example
// Use Bluebird as the promise provider, so you can use features like .finally()
bgm.setPromiseProvider(require('bluebird'));

updateEpStatus(ep_id, status, paramsopt, callbackopt) → {Promise}

A POST method that updates user's status on specific episode by episode id
Source:
Parameters:
Name Type Attributes Description
ep_id number ID of the target episode
status string Accepts [watched|queue|drop|remove]
params object <optional>
Optional parameters for the request
Name Type Attributes Description
ep_id string <optional>
A list of episode IDs for batch processing, separated by comma
callback function <optional>
Optional callback function
Returns:
Type:
Promise
- Returns a promise if no callback is provided
Example
bgm.updateEpStatus(7036,'drop');

updateWatchedEps(subject_id, params, callbackopt) → {Promise}

A POST method that marks episode 1 to target number as watched
Source:
Parameters:
Name Type Attributes Description
subject_id number ID of the target subject
params object Parameters for the request
Name Type Attributes Description
watched_eps string The number of episodes the user currently has watched
watched_vols string <optional>
The number of volumes the user currently has watched
callback function <optional>
Optional callback function
Returns:
Type:
Promise
- Returns a promise if no callback is provided
Example
bgm.updateWatchedEps(18462, {watched_eps: 10, watched_vols: 2});