Expand description
hentai
The aptly named hentai crate provides an easy mechanism to consume nhentai’s public facing APIs in Rust. As of now, hentai relies solely on these APIs instead of scraping their website. However, this capability may be added in the near future.
hentai will provide information about a doujin given its six-digit code. Alternatively, the JSON response from nhentai’s /api/gallery/{id} endpoint may be provided directly.
hentai is based on the similar package for python.
Examples
more info for these samples is provided in the documentation for Hentai
use hentai::{Hentai, Result, Website};
#[tokio::main]
async fn main() -> Result<()> {
let response = Hentai::new(165961, Website::NET).await?;
println!("{:?}", response); // makes use of the Debug trait on Hentai
Ok(())
}
use hentai::{Hentai, Result, Website};
#[tokio::main]
async fn main() -> Result<()> {
let response = Hentai::random(Website::XXX).await?;
println!("{:?}", response);
Ok(())
}
use hentai::{Hentai, Result, Website};
use std::env;
fn main() -> Result<()> {
let mut path = env::current_exe()?;
path.pop();
path.push("sample.json");
let response = Hentai::from_json(path, Website::XXX)?;
println!("{:?}", response);
Ok(())
}
Structs
The main object containing the formatted information retrieved from nhentai. The raw image data is converted to into image URLs. A brief explanation of each field is located below.
Tags are used to categorize doujins. Each doujin published on nhentai has tags indicating its content and additional data like the language and artist. For example, the tag with the category field equal to “artist” contains the name by which the author is recognized on nhentai.
nhentai provides three different types of titles. The first one is pretty
, which is a
simple title meant to stand out. The english
and japanese
titles are also provided.
These are more fleshed out versions of the pretty
title.
Enums
Global error type for Hentai that catches all other types of errors that may occur. This still provides the original error message when printed.
In cases where the standard output domain nhentai.net may be restricted
on the end user’s network, an option can be provided to use nhentai.xxx
URLs instead. Note that the Hentai::new()
constructor will not work if the standard output
domain is blocked. This is because nhentai.xxx does not reimplement
nhentai’s API and requests must still be made to the original URL.
Type Definitions
Shorthand for Result<T, HentaiError> meant to make catching errors slightly more simple.