nhentai-tools
Version:
A toolset to interact with the doujin site nhentai.net
48 lines • 7.66 kB
JSON
{
"name": "nhentai-tools",
"version": "1.1.1",
"description": "A toolset to interact with the doujin site nhentai.net",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib/**/*"
],
"keywords": [
"doujin",
"doujinshi",
"hentai",
"nhentai",
"nhentai.net",
"api",
"rest-api",
"nhentai-tools"
],
"author": "truedegen",
"license": "ISC",
"devDependencies": {
"@types/chrome-remote-interface": "^0.31.4",
"@types/jest": "^27.0.3",
"@types/node": "^17.0.6",
"@typescript-eslint/eslint-plugin": "^5.6.0",
"@typescript-eslint/parser": "^5.6.0",
"copy": "^0.3.2",
"eslint": "^8.4.1",
"jest": "^27.4.4",
"ts-jest": "^27.1.1",
"typescript": "^4.5.3"
},
"dependencies": {
"axios": "^0.24.0",
"puppeteer": "^13.0.1"
},
"scripts": {
"lint": "eslint src/",
"type": "tsc --noEmit",
"type:watch": "tsc --noEmit --watch",
"test": "jest --config jestconfig.json",
"test:watch": "jest --config jestconfig.json --watchAll",
"build": "pnpm lint && pnpm test && pnpm build:dev",
"build:dev": "rimraf lib/* && tsc && pnpm copy src/**/*.d.ts lib"
},
"readme": "<div align=\"center\">\r\n <h1>nhentai tools</h1>\r\n <i>a degenerate's work</i></br></br>\r\n <a href=\"disclaimers\">Disclaimers</a>\r\n ·\r\n <a href=\"#installation\">Installation</a>\r\n ·\r\n <a href=\"#api\">API</a>\r\n ·\r\n <a href=\"#examples\">Examples</a>\r\n ·\r\n <a href=\"#dependencies\">Dependencies</a>\r\n</div>\r\n</br>\r\n\r\nIn my long, sad walks of the web, I've realized that most every package interacting with the doujin site [nhentai.net](https://nhentai.net) is a simple scraper, despite an <i>official</i> (but entirely undocumented) api at [nhentai.net/api](https://nhentai.net/api).\r\n\r\nThis package was created to bring awareness to this api and to make it exceedingly easy to create simple projects interacting with [nhentai](https://nhentai.net).\r\n\r\n## Disclaimers\r\nI 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.\r\n\r\nSecondly, 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.\r\n\r\n## Installation\r\n- With [npm](https://www.npmjs.com):\r\n```sh\r\nnpm install nhentai-tools\r\n```\r\n- With [pnpm](https://pnpm.io):\r\n```sh\r\npnpm add nhentai-tools\r\n```\r\n\r\n## Examples\r\n- Check if a doujin exists:\r\n```js\r\nimport nhentai from 'nhentai-tools';\r\n\r\nnhentai.gallery.exists(383446)\r\n .then(exists => {\r\n // expected output: doujin 383446 exists.\r\n console.log(`doujin 383446 ${exists ? 'exists' : 'does not exist'}.`);\r\n })\r\n```\r\n- Get a specific doujin:\r\n```js\r\nimport nhentai from 'nhentai-tools';\r\n\r\n// get the doujin at https://nhentai.net/g/383300\r\nnhentai.gallery.get(383300)\r\n .then(gallery => {\r\n // expected output: title: Kosho ni Umoreta Mesu no Hana | A Bitch Rose Shrouded in Books\r\n console.log(`title: ${gallery.title.pretty}`);\r\n // expected output: id: 383300\r\n console.log(`id: ${gallery.id}`);\r\n })\r\n```\r\n- Get a random doujin:\r\n```js\r\nimport nhentai from 'nhentai-tools';\r\n\r\n// get the doujin at https://nhentai.net/random\r\nnhentai.gallery.random()\r\n .then(id => {\r\n // get the gallery data for the id\r\n return nhentai.gallery.get(id);\r\n })\r\n .then(randomGallery => {\r\n // expected output: {english: '...', japanese: '...', pretty: '...'}\r\n console.log(randomGallery.title);\r\n // expected output: id: ...\r\n console.log(randomGallery.id);\r\n })\r\n```\r\n- Search for a query:\r\n```js\r\nimport nhentai from 'nhentai-tools';\r\n\r\n// search for the tag kemonomimi, then get the second page sorted by popularity in the past month\r\nnhentai.search.query('tag:kemonomimi', { page: 2, sort: 'popular-month' })\r\n .then(search => {\r\n // expected output: 416\r\n console.log(search.num_pages);\r\n\r\n // create galleries\r\n const galleries = search.result;\r\n // expected output: length: 25\r\n console.log(`length: ${galleries.length}`);\r\n })\r\n```\r\n- Get ALL comments under a specific doujin (for some reason, nhentai's api just sends all of them at once):\r\n```js\r\nimport nhentai from 'nhentai-tools';\r\n\r\n// get ALL comments under the doujin 177013 (1.58 mb of text lol)\r\nnhentai.comments.get(177013)\r\n .then(comments => {\r\n // expected output: 4114\r\n console.log(comments.length)\r\n\r\n // be very careful when simply looping through comments\r\n // as the array can often be over 1000 entries long\r\n for (const comment of comments) {\r\n // destructure the comment object to extract comment.body and comment.poster.username\r\n const { poster: { username }, body } = comment\r\n const postDate = new Date(comment.post_date * 1000)\r\n\r\n console.log(`user '${username}' said '${body}' on ${postDate.toDateString()} at ${postDate.toTimeString()}.`)\r\n }\r\n })\r\n```\r\n- Login as a user and interact with favorites (**warning:** requires google chrome for solving captchas):\r\n```js\r\nimport nhentai from 'nhentai-tools';\r\n\r\n// login as user/pass\r\nnhentai.user.login('user', 'pass')\r\n .then(() => {\r\n console.log('logged in!')\r\n // remove something cursed\r\n return nhentai.user.favorites.remove(177013)\r\n })\r\n .then(() => {\r\n console.log('removed the cursed gallery')\r\n // add something less cursed\r\n return nhentai.user.favorites.add(383300)\r\n })\r\n .then(() => {\r\n console.log('added something good')\r\n })\r\n // don't forget to log out after completing all actions\r\n // or do, all it does is makes your captcha easier\r\n .finally(() => nhentai.user.logout())\r\n```\r\n\r\n## Dependencies\r\nThis project requires:\r\n - [axios]('https://axios-http.com')\r\n - A wonderful requests library.\r\n - Used for all web requests in this library.\r\n - [chrome-launcher]('https://github.com/GoogleChrome/chrome-launcher')\r\n - A simple library which does exactly what it should.\r\n - Used to display captchas for logging in and adding comments.\r\n - [chrome-remote-interface]('https://github.com/cyrus-and/chrome-remote-interface')\r\n - A library to interact with chrome instances. Works as intended, just hard to find how to do anything.\r\n - Used to find a captcha key.\r\n\r\n## API\r\nThe default export exposes:\r\n - gallery: All methods relating to a gallery, like getting a random id, or getting data from an id.\r\n - comments: All methods relating to user comments, like submitting or deleting.\r\n - search: All methods relating to searching nhentai's database.\r\n - user: All methods relating to a single user.\r\n - favorites: All methods relating to adding or removing favorites."
}