Code Monkey home page Code Monkey logo

nhentai-api's Introduction

CodeFactor PyPI download month codecov Python 3.9+ PyPI license

NHentai API

A NHentai API made using python webscrapping.
For update notes follow me on Twitter or join on NHentai-API discord server

Installation

pip install --upgrade NHentai-API

or

pip3 install --upgrade NHentai-API

Library Features

  • Home page pagination;
  • Doujin information;
  • Random doujin;
  • Search;
  • Comment Listing;
  • Today's Popular Doujins.

Home

from NHentai import NHentai

nhentai = NHentai()
random_doujin: HomePage = nhentai.get_pages(page=1)

The expected output is a HomePage instance:

Page(
    doujins: List[
        Doujin(
            id: int
            media_id: str
            upload_at: datetime
            url: str
            title: List[Title]
            tags: List[Tag]
            artists: List[Tag]
            languages: List[Tag]
            categories: List[Tag]
            characters: List[Tag]
            parodies: List[Tag]
            groups: List[Tag]
            cover: Cover
            images: List[DoujinPage]
            total_favorites: int = 0
            total_pages: int = 0
        )
    ],
    total_pages: int,
    total_results: int,
    per_page: int)

Random

from NHentai import NHentai

nhentai = NHentai()
random_doujin: Doujin = nhentai.get_random()

The expected output is a Doujin instance:

Doujin(
    id: int
    media_id: str
    upload_at: datetime
    url: str
    title: List[Title]
    tags: List[Tag]
    artists: List[Tag]
    languages: List[Tag]
    categories: List[Tag]
    characters: List[Tag]
    parodies: List[Tag]
    groups: List[Tag]
    cover: Cover
    images: List[DoujinPage]
    total_favorites: int = 0
    total_pages: int = 0
)

Note: Not all doujins have certain properties like tags, artists, etc. They could be an empty list or a NoneType value.

Search

from NHentai import NHentai, Sort

nhentai = NHentai()
search_obj: SearchPage = nhentai.search(query='naruto', sort=Sort.RECENT, page=1)
search_obj: SearchPage = nhentai.search(query='30955', page=1)

The expected output is a SearchPage instance:

SearchPage(
    query: str
    sort: str
    total_results: int
    total_pages: int
    doujins: List[
        Doujin(
            id: int
            media_id: str
            upload_at: datetime
            url: str
            title: List[Title]
            tags: List[Tag]
            artists: List[Tag]
            languages: List[Tag]
            categories: List[Tag]
            characters: List[Tag]
            parodies: List[Tag]
            groups: List[Tag]
            cover: Cover
            images: List[DoujinPage]
            total_favorites: int = 0
            total_pages: int = 0
        )
    ]
)

Doujin

from NHentai import NHentai

nhentai = NHentai()
doujin: Doujin = nhentai.get_doujin(doujin_id=287167)

The expected output is a Doujin instance:

Doujin(
    id: int
    media_id: str
    upload_at: datetime
    url: str
    title: List[Title]
    tags: List[Tag]
    artists: List[Tag]
    languages: List[Tag]
    categories: List[Tag]
    characters: List[Tag]
    parodies: List[Tag]
    groups: List[Tag]
    cover: Cover
    images: List[DoujinPage]
    total_favorites: int = 0
    total_pages: int = 0
)

Comments

from NHentai import NHentai

nhentai = NHentai()
comments: CommentPage = nhentai.get_comments(doujin_id=1)

The expected output is a CharacterListPage instance:

CommentPage(total_comments: int
            comments: List[Comment(id: int, 
                                   gallery_id: int, 
                                   poster=User(id: int, 
                                               username: str, slug: str, 
                                               avatar_url: str, 
                                               is_superuser: bool, 
                                               is_staff: bool), 
                                    post_date: str, 
                                    body: str)])

Most Popular

from NHentai import NHentai

nhentai = NHentai()
doujins: PopularPage = nhentai.get_popular_now()

The expected output is a PopularPage instance:

PopularPage(
    total_doujins: int
    doujins: List[
        Doujin(
            id: int
            media_id: str
            upload_at: datetime
            url: str
            title: List[Title]
            tags: List[Tag]
            artists: List[Tag]
            languages: List[Tag]
            categories: List[Tag]
            characters: List[Tag]
            parodies: List[Tag]
            groups: List[Tag]
            cover: Cover
            images: List[DoujinPage]
            total_favorites: int = 0
            total_pages: int = 0
        )
    ],
)

NHentai API Async

This is the first version of the asynchronous nhentai scrapper. The methods work in the very same way as the base nhentai scrapper, but to make it work you'll have to work with asyncio module using an event loop that you can import from it or get from NHentaiAsync class property: event_loop.

Since we're working with async functions, you can only call the NHentaiAsync methods from inside an async funcion or context. If you are already working in an async event loop, such as a python Discord API like discord.py, you can simply await calls that you would otherwise have to call run_until_complete on top of.

Async example 1:

from NHentai import NHentaiAsync

nhentai_async = NHentaiAsync()
event_loop = nhentai_async.event_loop
popular = event_loop.run_until_complete(nhentai_async.get_popular_now())
print(popular)

Async example 2:

from NHentai import NHentaiAsync

nhentai_async = NHentaiAsync()

async def get_popular():
    popular = await nhentai_async.get_popular_now()
    print(popular)

event_loop = nhentai_async.event_loop
event_loop.run_until_complete(get_popular())

Await example:

from NHentai import NHentaiAsync
nhentai_async = NHentaiAsync()

# Run in an async function or you will get an error: `'await' outside async function`.
popular = await nhentai_async.get_popular_now()
print(popular)

nhentai-api's People

Contributors

alexandresenpai avatar ilexisthemadcat avatar nadiefiind avatar murilo-bracero avatar nyasume avatar kiranajij avatar sdvcrx avatar

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.