NHentaiAPI 1.8.0

dotnet add package NHentaiAPI --version 1.8.0                
NuGet\Install-Package NHentaiAPI -Version 1.8.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NHentaiAPI" Version="1.8.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NHentaiAPI --version 1.8.0                
#r "nuget: NHentaiAPI, 1.8.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NHentaiAPI as a Cake Addin
#addin nuget:?package=NHentaiAPI&version=1.8.0

// Install NHentaiAPI as a Cake Tool
#tool nuget:?package=NHentaiAPI&version=1.8.0                

NHentaiAPI

Build status NuGet NuGet NuGet

A full nHentai API implementation for .NET

⚠️ If nHentai changes their API format, please create an issue to let me know!

Important Notes

User Agent Requirements

A User-Agent is required to use this API. The client will throw an error if none is provided. You can get your User-Agent by:

  1. Going to https://www.whatismybrowser.com/detect/what-is-my-user-agent/
  2. Or by opening Developer Tools (F12) in your browser, going to Network tab, and looking at the "User-Agent" header in any request

Example:

var client = new NHentaiClient("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36");

CSRF Token (If Required)

If nHentai implements CSRF protection, you can get the token by:

  1. Opening Developer Tools (F12)
  2. Going to Network tab
  3. Looking for a request header named 'x-csrf-token' or a cookie named 'csrf_token'
  4. Pass it to the client using the cookies dictionary

Important: The CSRF token must be obtained from the same IP address and User-Agent that will be used with the API. Using a token from a different IP or User-Agent will result in authentication failures.

var cookies = new Dictionary<string, string>
{
    {"csrf_token", "your-token-here"}
};
var client = new NHentaiClient("your-user-agent", cookies);

Features

Search Capabilities:

  1. Browse homepage content
  2. Search by keywords
  3. Search by tags with optional popularity sorting
  4. Filter tags using - prefix (exclusion)

Book Operations:

  1. Fetch book details
  2. Get related books

Image Operations:

  1. Page images (preview, thumbnail, and original quality)
  2. Cover images (preview and thumbnail)

Usage Examples

Search Books:

// Initialize client with User-Agent
var client = new NHentaiClient("your-user-agent-string");

// Search with filters
var result = await client.GetSearchPageListAsync("school swimsuit full color -loli", 2);

// Browse homepage
var homeResults = await client.GetHomePageListAsync(1);

Get Book Details:

var client = new NHentaiClient("your-user-agent-string");

// Get book by ID
var book = await client.GetBookAsync(123);

// Get related books
var related = await client.GetBookRecommendAsync(123);

Get Images:

var book = await client.GetBookAsync(123);

// Get full page image
byte[] picture = await client.GetPictureAsync(book, 1);

// Get cover image
byte[] cover = await client.GetBigCoverPictureAsync(book);

// Get thumbnails
byte[] thumbnail = await client.GetThumbPictureAsync(book, 1);
byte[] coverThumb = await client.GetBookThumbPictureAsync(book);

Check Out My Other Projects

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.8.0 110 11/15/2024
1.7.0 773 7/19/2023
1.6.0 192 7/19/2023
1.5.0 1,679 5/7/2022
1.4.0 617 9/8/2020
1.3.0 516 6/9/2020
1.2.0 730 6/23/2019
1.1.0 659 4/30/2019
1.0.0 737 12/8/2018

[1.8.0]
           - Switched to using System.Text.Json instead of Newtonsoft.
           - Added proper JSON type handling via converters.
           - Updated to .NET 8.0
           - Added proper async handling
           - Updated thumbnail and image urls to work with nhentais' load balancing urls.