Giter VIP home page Giter VIP logo

nhentai_dart's Introduction

Client for nhentai.net undocumented APIs

Features

  • Full model (books, images, tags, comments, users).
  • Search for text query.
  • Search by tag(s).
  • Get random book.
  • Configurable hosts.
  • Support for custom Client (via package:http).
  • Out-of-box HTTP proxy support (configurable via URI).
  • Out-of-box User Agent override and Cookies support.

Notes about web usage

Using this module on web platform is experimental and has some drawbacks:

  • You can't access nhentai directly due to CORS.
    • Workaround: use CORS enabled mirror (for example you can use dev-mirror).
  • API#getRandomBook doesn't work due to limitations of XHR.
  • Proxy isn't supported on web.
  • User Agent override isn't supported on web.
  • Cookies helper functions aren't supported on web.

Usage

Import the package:

import 'package:nhentai/nhentai.dart';

Create client instance:

final api = API();

Get the data:

/// Throws if book is not found, or parse failed, see docs.
final Book book = await api.getBook(421025);

// Short book summary
print(
  'Book: $book\n'
  'Artists: ${book.tags.artists.join(', ')}\n'
  'Languages: ${book.tags.languages.join(', ')}\n'
  'Cover: ${book.cover.getUrl(api: api)}\n'
  'First page: ${book.pages.first.getUrl(api: api)}\n'
  'First page thumbnail: ${book.pages.first.thumbnail.getUrl(api: api)}\n',
);

See more usage at example folder.

License

  • ISC License

nhentai_dart's People

Contributors

lacticwhale avatar zekfad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

lacticwhale

nhentai_dart's Issues

SearchSort.popular causes does not exist error

When using

searchedBooks = await _api.searchSinglePage(
        "*",
        sort: SearchSort.popular,
        page: 1,
      );

I get this error API Exception: does not exist

This query does however work with all the other SearchSort options, just not with popular... Might be due to an unexpected API change?

web: redirects

For now, to be able to use this module on web I'm using universal_io, but it lacks support of http redirects (due to XHR).
We can use fetch API with manual redirects to get this functionality, but it requires either new dedicated package or find existing with such functionality.
The pitfall here is that we have to maintain ability to use custom HttpClient on native platforms.

Feature Request: Get popular and new books

On the nHentai home page you can see the currently popular and new uploads. It would be great if such a feature existed in in this library, an easy way to get the new and popular books

Get multiple specific books at a time

Currently you have a request limit, so when calling .getBook() too many times in too short durations, you will receive ApiClientException. Is there a way to get a list of specific books, similar to getBook, but for multiple books specified by their id?

make API an interface with implementation

splitting API class into interface and implementation will allow external packages to implement different API client.
this is groundwork to make client based on http parsing (mostly because search is subject to multiple unclear restrictions)

Update to use newer dependencies

I am primarily interested in the http dependency which is quite outdated, it would be great if it could be updated to v 1.0.0 or higher. This is primarily since other projects using this dependency might run into the below:

Because nhentai 1.0.0-dev.11 depends on http ^0.13.5 and no versions of nhentai match >1.0.0-dev.11 <2.0.0, nhentai ^1.0.0-dev.11 requires http ^0.13.5.
So, because this app depends on both nhentai ^1.0.0-dev.11 and http ^1.1.0, version solving failed.

This can be an issue if http has features or security patches in later versions

403 (Forbidden) error on data request

I tried using the example you provided in the readme:

final api = API();

    try {
      /// Throws if book is not found, or parse failed, see docs.
      final Book book = await api.getBook(177013);
    } on ApiClientException catch (e) {
      debugPrint(e.response?.statusCode.toString());
    }

I seem to be getting a 403 error response. This is currently only running in a basic Dart project , no Flutter or anything else

It is making a request to https://nhentai.net/api/gallery/177013 which when visited in browser seems to work fine

Unhandled exception while parsing response.

Description:
An error can be thrown if you have reached the nhentai.net request rate limit.

Posibble solution:
Add check for nhentai.net response status code.

Debug console:

Unhandled exception:
FormatException: Unexpected character (at character 1)
<html>
^

#0      _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1405:5)
#1      _ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1272:9)
#2      _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:937:22)
#3      _parseJson (dart:convert-patch/convert_patch.dart:40:10)
#4      JsonDecoder.convert (dart:convert/json.dart:612:36)
#5      JsonCodec.decode (dart:convert/json.dart:216:41)
#6      jsonDecode (dart:convert/json.dart:155:10)
#7      API._getJson
<asynchronous suspension>
#8      API._searchSinglePage
<asynchronous suspension>
#9      main
<asynchronous suspension>

Exited (255)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.