npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nhentai-tools

v1.1.1

Published

A toolset to interact with the doujin site nhentai.net

Downloads

20

Readme

In my long, sad walks of the web, I've realized that most every package interacting with the doujin site nhentai.net is a simple scraper, despite an official (but entirely undocumented) api at nhentai.net/api.

This package was created to bring awareness to this api and to make it exceedingly easy to create simple projects interacting with nhentai.

Disclaimers

I am currently a student, so updates will be neither regular, nor high quality. This has been developed as a result of too many long nights, so code might just not work at all. If there's a problem, leave an issue describing what causes it and I'll try to fix it soon.

Secondly, nhentai has a scuffed website, and an even more scuffed api. It's not that they don't work, they just don't work quite right. Occasionally searching by recent will return { error: true }, on the second login in a short time a captcha will be required, but cannot be used, etc. I'm working to make these errors not affect users/developers, but there's always unexpected behavior. If you find a reproducable issue, create a pull request if you can find a way to fix it, or an issue if you can't.

Installation

npm install nhentai-tools
pnpm add nhentai-tools

Examples

  • Check if a doujin exists:
import nhentai from 'nhentai-tools';

nhentai.gallery.exists(383446)
    .then(exists => {
        // expected output: doujin 383446 exists.
        console.log(`doujin 383446 ${exists ? 'exists' : 'does not exist'}.`);
    })
  • Get a specific doujin:
import nhentai from 'nhentai-tools';

// get the doujin at https://nhentai.net/g/383300
nhentai.gallery.get(383300)
    .then(gallery => {
        // expected output: title: Kosho ni Umoreta Mesu no Hana | A Bitch Rose Shrouded in Books
        console.log(`title: ${gallery.title.pretty}`);
        // expected output: id: 383300
        console.log(`id: ${gallery.id}`);
    })
  • Get a random doujin:
import nhentai from 'nhentai-tools';

// get the doujin at https://nhentai.net/random
nhentai.gallery.random()
    .then(id => {
        // get the gallery data for the id
        return nhentai.gallery.get(id);
    })
    .then(randomGallery => {
        // expected output: {english: '...', japanese: '...', pretty: '...'}
        console.log(randomGallery.title);
        // expected output: id: ...
        console.log(randomGallery.id);
    })
  • Search for a query:
import nhentai from 'nhentai-tools';

// search for the tag kemonomimi, then get the second page sorted by popularity in the past month
nhentai.search.query('tag:kemonomimi', { page: 2, sort: 'popular-month' })
    .then(search => {
        // expected output: 416
        console.log(search.num_pages);

        // create galleries
        const galleries = search.result;
        // expected output: length: 25
        console.log(`length: ${galleries.length}`);
    })
  • Get ALL comments under a specific doujin (for some reason, nhentai's api just sends all of them at once):
import nhentai from 'nhentai-tools';

// get ALL comments under the doujin 177013 (1.58 mb of text lol)
nhentai.comments.get(177013)
    .then(comments => {
        // expected output: 4114
        console.log(comments.length)

        // be very careful when simply looping through comments
        // as the array can often be over 1000 entries long
        for (const comment of comments) {
            // destructure the comment object to extract comment.body and comment.poster.username
            const { poster: { username }, body } = comment
            const postDate = new Date(comment.post_date * 1000)

            console.log(`user '${username}' said '${body}' on ${postDate.toDateString()} at ${postDate.toTimeString()}.`)
        }
    })
  • Login as a user and interact with favorites (warning: requires google chrome for solving captchas):
import nhentai from 'nhentai-tools';

// login as user/pass
nhentai.user.login('user', 'pass')
    .then(() => {
        console.log('logged in!')
        // remove something cursed
        return nhentai.user.favorites.remove(177013)
    })
    .then(() => {
        console.log('removed the cursed gallery')
        // add something less cursed
        return nhentai.user.favorites.add(383300)
    })
    .then(() => {
        console.log('added something good')
    })
    // don't forget to log out after completing all actions
    // or do, all it does is makes your captcha easier
    .finally(() => nhentai.user.logout())

Dependencies

This project requires:

  • axios
    • A wonderful requests library.
    • Used for all web requests in this library.
  • chrome-launcher
    • A simple library which does exactly what it should.
    • Used to display captchas for logging in and adding comments.
  • chrome-remote-interface
    • A library to interact with chrome instances. Works as intended, just hard to find how to do anything.
    • Used to find a captcha key.

API

The default export exposes:

  • gallery: All methods relating to a gallery, like getting a random id, or getting data from an id.
  • comments: All methods relating to user comments, like submitting or deleting.
  • search: All methods relating to searching nhentai's database.
  • user: All methods relating to a single user.
  • favorites: All methods relating to adding or removing favorites.