Skip to main content

nHentai API implementation

Project description

Introduction to nhentei

About:

Short: nhentei is a python implementation of nHentai's API. Why: Because nHentai's documentation of their API is really...short. That's why nhentei exists. nhentei is an asynchronous library, keep that in mind.

Required packages:

Following packages will be installed too when pip installing nhentei:

  • aiohttp
  • requests
  • asyncio

Made in python 3

Getting started:

Install nhentei via pip:

pip install nhentei

If you do not have pip installed, get pip first. To use it in your project, put

from nhentei import nfunctions

at the top of your python file. We'll refer to the commands with

nfunctions.*functionName()*

later

Basic example:

nhentei basically consists out of utility functions containing direct API requests.

from nhentei import nfunctions
#Get a dictionary containing metadata:
dict = await nfunctions.getByID("1")
#This will return a dictionary containing all data of hentai with ID 1
pages = dict['num_pages']
#pages now contains the number of pages the hentai has

Hentai dictionaries: What do they store?

You will find a list of keys you can use to get data from the dictionary below:

key description
id unique nhentai identifier, starting from 1
media_id used to get images or media
title returns a dictionary (more to that later)
images returns a dictionary (more to that later)
scanlator name of the scanlator
upload_date date in unix timestamp format)
tags returns an array of tags(more to that later)
num_pages number of pages
num_favorites number of favorites

"title" dictionary

The returned dictionary for the key "title" contains following keys:

"english" --> Returns the title in english (string)(always exists)
"japanese" --> Returns the title in japanese (string)(not guaranteed to exist)
"pretty" --> Returns the title in a pretty format (string)(not guaranteed to exist)

"images" dictionary

The returned dictionary for the key "images" contains following keys:

"pages"--> Returns an array containing dictionaries, if the hentai has
	    14 pages, the array will go from 0-13.
	    Every dictionary contains following keys:
	    "t" --> returns a single char
	    "w" --> returns the width of the image
	    "h" --> returns the height of the image
"cover"-->This dictionary contains following keys:
	    "t" --> returns a single char
	    "w" --> returns the width of the image
	    "h" --> returns the height of the image
"thumbnail"-->This dictionary contains following keys:
	    "t" --> returns a single char
	    "w" --> returns the width of the image
	    "h" --> returns the height of the image

"tags" array / list

Every array slot / list slot contains a dictionary representing a "tag", it has following keys:

"id" --> Identifier for the tag
"type" --> Returns tag type: can be either "artist", "tag", "group", "parody", "character", "language", "category"
"name" --> Depends on the "type": for artists, this will be the name of the artist, for tag it will be the name of the tag.
"url" --> the payload url
"count" --> number of hentai with this tag/artist/etc.

Functions:

getByID(id)

parameter name type returns
id String Dictionary containing hentai metadata

This function will return the above explained dictionary by giving it an ID

getByTags(tags, page, sort, num)

Takes parameters:

  • tags (String format, separated by commas) The tags you want to search with
  • page (int format)(optional, defaults to 1) The result page to get
  • sort (String format)(optional, defaults to "popular") The sorting algorithm
  • num (int format)(optional, defaults to "popular") The number of entries

Returns: list -- Contains dictionaries with hentai with the tags

getPayloadSearch(payload)

Takes parameters:

  • payload (In string format, more to payloads soon)

Returns: dictionary

getByTitle(title, page, sort)

Takes parameters:

  • tags (String format, separated by commas)
  • page (integer format)(optional, defaults to 1)
  • sort (String format)(optional, defaults to "popular")

Returns: list -- Contains dictionary of hentai with the title

getByCharacter(character, page, sort)

Takes parameters:

  • character (String format, separated by commas)
  • page (integer format)(optional, defaults to 1)
  • sort (String format)(optional, defaults to "popular")

Returns: list -- Contains dictionary of hentai with the character(s)

getByParody(title, page, sort)

Takes parameters:

  • title (String format, separated by commas)
  • page (integer format)(optional, defaults to 1)
  • sort (String format)(optional, defaults to "popular")

Returns: list -- Contains dictionary of hentai that are a parody of the title

getCover(media_id)

Takes parameters:

  • media_id (String format, separated by commas)

Returns: url to the source image

getPageImage(media_id, page)

Takes parameters:

  • media_id (String format, separated by commas)
  • page (String format, separated by commas) The page of the hentai, starts with 0

Returns: url to the source image

Credits to:

EpicGamer for crawling through API outputs nhentai.net for the API and art

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nhentei-2.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nhentei-2.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file nhentei-2.0.tar.gz.

File metadata

  • Download URL: nhentei-2.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.0

File hashes

Hashes for nhentei-2.0.tar.gz
Algorithm Hash digest
SHA256 fbd196083ef6ca71e39f89f31535fa2852e881de8ca64ea52a71dfd8c82e100e
MD5 702e50ef2dc5e0d8441b941a1cac7900
BLAKE2b-256 b3c450ca3f2ad98c224c7fda0ace35a68ba35754bc1780e89347082ab3a41c83

See more details on using hashes here.

File details

Details for the file nhentei-2.0-py3-none-any.whl.

File metadata

  • Download URL: nhentei-2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.0

File hashes

Hashes for nhentei-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d6a928d82579c4a5bc718f4ab96002d755beda12bd8a31aaf6e8e5920536c34
MD5 e4a6a80efd039c25cabed7bca609742f
BLAKE2b-256 171fc9b2a7696d9bbee60e7c99eb25baa97a7c29ca92c6d8681736cf8206cdff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page