Git Product home page Git Product logo

anilist-node's Introduction

Anilist-Node

Total Downloads (NPM Link) Monthly Downloads (NPM Link) Support Server

A simple, lightweight Node.js wrapper for the AniList API.

Using Anilist-node

To install: npm install anilist-node

You may need a token for some features (ie checking favourites). A token only needs to be generated once in order to use. To start, head to Anilist's Developer Page and click "Create New Client". Note the client id and place this URL into your client redirect https://anilist.co/api/v2/oauth/pin. This URL will allow you to get your token when authorizing. Then, copy paste this URL https://anilist.co/api/v2/oauth/authorize?client_id={clientID}&response_type=token, replacing the {clientID} with your client ID. It will ask you to log in and then provide you with the token to use.

NOTE: Please store your token securely and privately! This gives access to your AniList account. It is your responsibility to maintain your token.

Example

General lookup search (no login):

const anilist = require('anilist-node');
const Anilist = new anilist();

Anilist.media.anime(21708).then(data => {
    console.log(data);
});

Lookup search (login):

const settings = require('./settings.json'); //Or wherever your store your token.
const anilist = require('anilist-node');
const Anilist = new anilist(settings.token /* This being your token */);

Anilist.media.anime(21708).then(data => {
    console.log(data);
});

For a more in-depth guide on getting started, check out our Getting Started guide on our site or on the static HTML site under the docs directory.

Documentation

Documentation is provided in two locations. A static HTML site is available with the package under the docs directory. Or users can view the same site online here: katsurin.com/docs/anilist-node.

Contributing

Please refer to the Contributing Guide for more information.

License and Contact

AniList-Node is licensed under the MIT License.

For issues and bugs, please use the issue tracker on the GitHub repository. For other needs, either contact me by email [email protected] or in my Discord server in the #anilist-node channel.

anilist-node's People

Contributors

aurelicbutter avatar axelterizaki avatar bdashore3 avatar exhabition avatar jacob9423 avatar rd-xx avatar salixor avatar totto16 avatar typlox avatar varoop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

anilist-node's Issues

AniList responses don't always include "Page" property which causes some requests to fail

For example, trying to fetch someone's anime lists

const lists = await Anilist.lists.anime(USERNAME);
(node:10625) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'activities' of undefined
    at Utilities.send (/.../node_modules/anilist-node/lib/fetcher.js:127:28)

https://github.com/Butterstroke/AniList-Node/blob/master/lib/fetcher.js#L127-L129


An easy fix would be to check if the Page property is defined before trying to access the deeper properties

if (json.data.Page && json.data.Page.activities) { ... }

Anilist.Lists Keeps Appearing in Documentation

Description

When generating the JSDoc documentation, instead of AniList.Lists as the HTML file name, it uses Anilist.Lists.

Release 1.9.1 shipped with this mistake but running the docs script after release generated the correct file name.

Steps to Reproduce

  1. Run the NPM docs script
  2. Open the newly generated documentation
  3. Click on Lists class in the navigation bar
  4. Fail to load Lists page

Environment
Node.js Version: 12.22.6
AniList-Node Version: 1.9.1

Screenshots

Additional context

Searching Staff by ID Returns Nothing

Tested package version: 1.2.2
Tested Node version: Node 12
Affected areas: Staff function

Staff function returns null if you search for a staff member by their ID and not by their name.

Advice for not going over the X-RateLimit-Limit

As documented here there is rate limiting in place. While it is fairly generous currently at 90 rpm, I'm not sure if there's any way to use this from the node wrapper.

Would it be possible to either:

  1. Expose the useful headers from the library:
Retry-After: 30
X-RateLimit-Limit: 90
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1502035959
  1. Automatically handle it inside the library, by holding off on sending/resolving the promise response until the call has been made without exceeding the rate limit.

Would this be in scope for the library or do you have any advice for not exceeding the rate limit? Thanks!

[Possible Issue] Accessing a falsy value in lib/fetcher

Description
In lib/fetcher I found a possible issue. Read the following code.

https://github.com/Butterstroke/AniList-Node/blob/68c8006331ac304fbc11eddb4e64f4b4bccf08dd/lib/fetcher.js#L129-L137

The first statement returns errors if there are any, this means that if there are no errors it will continue to the next statement.
We now know that json.errors is a falsy value because otherwise it would have already returned.

However, in the second statement, if (json.date === null), we are accessing json.errors anyway.

TL;DR: Accesing json.errors after we now it's a falsy value

Environment
AniList-Node Version: 1.8.1

Additional context
Code in: lib/fetcher, lines 129 - 137

Allow Users to Grab the 26th+ Entry in a Query

Users are currently restricted by the first page of the related entries to many of the methods right now. The first page has 25 entries, as per AniList's limit, but it is possible to query for more entries. Users should have an optional parameter in methods to get the next 25+ entries if they wish.

For example:

One Piece has 53 related entries right now but with media.anime() it is only possible to get 25 of those entries.

Because of the way the query is setup,

relations { nodes { id title { english native romaji userPreferred } type } }

will only ever return 25 entries.

While a change like this,

relations (page: x) { nodes { id title { english native romaji userPreferred } type } }

would allow users to query for other entries that would not be listed on other pages.

Each entry that grabs related entries (ie: characters & media) is a connection so those changes should work fine for the GraphQL queries.

Edit: Updated with more explanation and example.

Bad Request

Description
I'm trying to make a discord bot with AniList API. However, when i'm trying to execute command of find e.g. user (this problem are occured on anime and manga too) it's returns a Bad Request HTTP error

Environment
Node.js Version: 20.9.0
AniList-Node Version: 1.14.0

Screenshots
image
image

Update Anime Mutation

Allow users to have a method to update their anime lists. Something to note is that anime queries don't allow names and must use their AniList IDs. Searching by names is also not as accurate as using an ID. So users should only be able to update if they have the ID of the anime in question.

Update Manga Mutation

Allow users to have a method to update their manga lists. Something to note is that manga queries don't allow names and must use their AniList IDs. Searching by names is also not as accurate as using an ID. So users should only be able to update if they have the ID of the manga in question.

Search Function Returning Empty Page

Tested package version: 1.2.2
Tested Node version: Node 8 & Node 12
Affected areas: All searching capabilities

When using the search function, AniList currently returns an empty page.

Can't use args[...] in place of the Anilist ID

Description
Use of arguments is currently not possible with default code.

Steps to Reproduce

  1. Load the module into your project
  2. Attempt to use the example code like this
const anilist = require('anilist-node');
const Anilist = new anilist();

Anilist.media.anime(**args[0]**).then(data => {
    console.log(data);
});
  1. Receive the "Term provided is not a number!" error

Environment
Node.js Version: 14.15.4
AniList-Node Version: 1.7.0

Screenshots

Additional context
Commented out line 25 in this file
https://github.com/Butterstroke/AniList-Node/blob/master/lib/media.js
Arguments were able to pass through, and the correct data was grabbed.

While the addition of this line helps make sure the correct string is passed, it checks the code before the actual argument and kills the process. Might want to add some exception for args[...]

Asynchronous/Synchronous for edgeRemove and formatMedia

https://github.com/Butterstroke/AniList-Node/blob/68c8006331ac304fbc11eddb4e64f4b4bccf08dd/lib/fetcher.js#L71-L73
https://github.com/Butterstroke/AniList-Node/blob/68c8006331ac304fbc11eddb4e64f4b4bccf08dd/lib/fetcher.js#L28-L50

Is there any point in using await on edgeRemove? It doesn't return a promise. If the awaiting of those functions is removed, function formatMedia for example doesn't have to be executed asynchronous anymore.

Unless there is a thought behind this, in that case I would like to know the explanation ๐Ÿ˜„

Originally posted by @Exhabition in #28 (comment)

Hmm... I believe the thought was to ensure the object was edited before it was returned. I'm trying to think if edgeRemove was always synchronous or not but I can't say for sure since it's been around forever. Might be worth a look to see if synchronous is just as good for it.

Originally posted by @Butterstroke in #28 (comment)

Activity of users

Does this have like a command to view your friends Activity. Like what that person watched/read today.

Typescript error: this expression is not constructable

Description

When using moduleResolution: node16 or nodenext in tsconfig.json, building with a call to the module causes the following error :

$ tsc
services/animeList.ts:12:21 - error TS2351: This expression is not constructable.
  Type 'typeof import("C:/xxx/karaokemugen-server/node_modules/anilist-node/lib/types/index")' has no construct signatures.

12 const anilist = new Anilist();
                       ~~~~~~~

Steps to Reproduce

  1. Create a new typescript project with moduleResolution: node16
  2. Try to spawn a new instance of Anilist in your code as described in the README.

Environment
Node.js Version: 18.12.1 (tyepscript version 5.0.2)
AniList-Node Version: 1.13.1

Thanks for looking into this! This would help a lot with a project I'm trying to keep up-to-date.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.