anidb-udp-client
    Preparing search index...

    anidb-udp-client

    anidb-udp-client · anidb-udp-client GitHub license Tests Coverage

    anidb-udp-client is a library for Node.js that facilitates the use of Anidb's UDP API. It handles the UDP connection, encoding/decoding requests and responses, rate limiting and caching (can be disabled) and provides typescript type definitions for all methods. If you plan to use the library for your project I strongly suggest to add your project to: https://anidb.net/software/add and use your own name for clientid

    https://tsukeero.github.io/anidb-udp-client/

    Requires Node.js 22 or newer.

    NPM: npm install anidb-udp-client

    Yarn: yarn add anidb-udp-client

    import { AnidbUDPClient } from 'anidb-udp-client'

    const anidb_client = new AnidbUDPClient('my-anime-client')

    await anidb_client.connect('anidb_username', 'anidb_password')

    const anime = await anidb_client.anime(117, [ 'english_name', 'rating' ])

    console.log(`${anime.english_name}: rating ${anime.rating}`)

    await anidb_client.disconnect()

    The state field of file(), file_by_hash() and file_by_episode() is a raw bitfield. Decode it with decodeFileState():

    import { decodeFileState } from 'anidb-udp-client'

    const file = await anidb_client.file_by_hash(ed2k, size, [ 'state' ])
    const { crc_ok, version, censored, uncensored } = decodeFileState(file.state)

    If neither censored nor uncensored is set, AniDB has no censorship information for the file.

    import { AnidbUDPClient, SimplePersistentCache} from 'anidb-udp-client'

    const cache = new SimplePersistentCache({save_path: '/tmp/'})
    const anidb_client = new AnidbUDPClient('my-anime-client', { cache } )
    const anidb_client = new AnidbUDPClient('my-anime-client', { cache: false } )
    

    NOTE: when using custom cache make sure TTL for every anidb-udp-client related key is set to a reasonable amount. Long living cache can become stale.

    import { createClient } from 'redis';
    import { AnidbUDPClient } from 'anidb-udp-client'


    class RedisCache {
    #redisClient
    constructor(){
    this.#redisClient = createClient();
    }
    async connect() {
    await this.#redisClient.connect();
    }

    async get(key) {
    const result = await this.#redisClient.get(key)
    return JSON.parse(result)
    }
    async set(key, value) {
    //can use key.startsWith() to set TTL for different result types: 'ANIME:', 'FILE:', ...
    await this.#redisClient.set(key, JSON.stringify(value), {EX: 2592000 })
    }
    }


    const cache = new RedisCache()
    await cache.connect()

    const anidb_client = new AnidbUDPClient('my-anime-client', { cache } )
    • Node.js 22 or newer is required.
    • file(), file_by_hash() and file_by_episode(): the other_name field is now other_name_list and returns string[] (same as anime()).
    npm ci
    npm run verify # lint, typecheck, tests
    npm run build

    The git hooks (lint-staged, commitlint) need Node.js 22.22.1 or newer. Commit messages follow Conventional Commits; releases are created by release-please.