コンテンツにスキップ

EHentai

Classes

EHentai

Bases: BaseSearchEngine[EHentaiResponse]

API client for the EHentai image search engine.

Used for performing reverse image searches using EHentai service.

Attributes:

Name Type Description
base_url str

The base URL for EHentai searches.

is_ex bool

If True, search on exhentai.org; otherwise, use e-hentai.org.

covers bool

A flag to search only for covers.

similar bool

A flag to enable similarity scanning.

exp bool

A flag to include results from expunged galleries.

Source code in PicImageSearch/engines/ehentai.py
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
class EHentai(BaseSearchEngine[EHentaiResponse]):
    """API client for the EHentai image search engine.

    Used for performing reverse image searches using EHentai service.

    Attributes:
        base_url (str): The base URL for EHentai searches.
        is_ex (bool): If True, search on exhentai.org; otherwise, use e-hentai.org.
        covers (bool): A flag to search only for covers.
        similar (bool): A flag to enable similarity scanning.
        exp (bool): A flag to include results from expunged galleries.
    """

    def __init__(
        self,
        is_ex: bool = False,
        covers: bool = False,
        similar: bool = True,
        exp: bool = False,
        **request_kwargs: Any,
    ):
        """Initializes an EHentai API client with specified configurations.

        Args:
            is_ex (bool): If True, search on exhentai.org; otherwise, use e-hentai.org.
            covers (bool): If True, search only for covers; otherwise, search all images.
            similar (bool): If True, enable similarity scanning for more results.
            exp (bool): If True, include results from expunged galleries.
            **request_kwargs (Any): Additional arguments for network requests (e.g., cookies, proxies).

        Note:
            - For exhentai.org searches (is_ex=True), valid cookies must be provided in request_kwargs.
            - The base URL is automatically selected based on the is_ex parameter.
        """
        base_url = "https://upld.exhentai.org" if is_ex else "https://upld.e-hentai.org"
        super().__init__(base_url, **request_kwargs)
        self.is_ex = is_ex
        self.covers = covers
        self.similar = similar
        self.exp = exp

    async def search(
        self,
        url: Optional[str] = None,
        file: Union[str, bytes, Path, None] = None,
        **kwargs: Any,
    ) -> EHentaiResponse:
        """Performs a reverse image search on EHentai/ExHentai.

        This method supports two ways of searching:
            1. Search by image URL
            2. Search by uploading a local image file

        Args:
            url (Optional[str]): URL of the image to search.
            file (Union[str, bytes, Path, None]): Local image file, can be a path string, bytes data, or Path object.
            **kwargs (Any): Additional arguments passed to the parent class.

        Returns:
            EHentaiResponse: Contains search results and metadata, including:
                - Similar gallery entries
                - Gallery URLs and titles
                - Similarity scores
                - Additional metadata from the search results

        Raises:
            ValueError: If neither `url` nor `file` is provided.
            RuntimeError: If searching on ExHentai without proper authentication.

        Note:
            - Only one of `url` or `file` should be provided.
            - For ExHentai searches, valid cookies must be provided in the request_kwargs.
            - Search behavior is affected by the covers, similar, and exp flags set during initialization.
        """
        self._validate_args(url, file)

        endpoint = "upld/image_lookup.php" if self.is_ex else "image_lookup.php"
        data: dict[str, Any] = {"f_sfile": "File Search"}
        files: dict[str, Any] = {}

        if url:
            files = {"sfile": await self.download(url)}
        elif file:
            files = {"sfile": read_file(file)}

        if self.covers:
            data["fs_covers"] = "on"
        if self.similar:
            data["fs_similar"] = "on"
        if self.exp:
            data["fs_exp"] = "on"

        resp = await self._make_request(
            method="post",
            endpoint=endpoint,
            data=data,
            files=files,
        )

        return EHentaiResponse(resp.text, resp.url)

Attributes

covers = covers instance-attribute
exp = exp instance-attribute
is_ex = is_ex instance-attribute
similar = similar instance-attribute

Functions

__init__(is_ex=False, covers=False, similar=True, exp=False, **request_kwargs)

Initializes an EHentai API client with specified configurations.

Parameters:

Name Type Description Default
is_ex bool

If True, search on exhentai.org; otherwise, use e-hentai.org.

False
covers bool

If True, search only for covers; otherwise, search all images.

False
similar bool

If True, enable similarity scanning for more results.

True
exp bool

If True, include results from expunged galleries.

False
**request_kwargs Any

Additional arguments for network requests (e.g., cookies, proxies).

{}
Note
  • For exhentai.org searches (is_ex=True), valid cookies must be provided in request_kwargs.
  • The base URL is automatically selected based on the is_ex parameter.
Source code in PicImageSearch/engines/ehentai.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def __init__(
    self,
    is_ex: bool = False,
    covers: bool = False,
    similar: bool = True,
    exp: bool = False,
    **request_kwargs: Any,
):
    """Initializes an EHentai API client with specified configurations.

    Args:
        is_ex (bool): If True, search on exhentai.org; otherwise, use e-hentai.org.
        covers (bool): If True, search only for covers; otherwise, search all images.
        similar (bool): If True, enable similarity scanning for more results.
        exp (bool): If True, include results from expunged galleries.
        **request_kwargs (Any): Additional arguments for network requests (e.g., cookies, proxies).

    Note:
        - For exhentai.org searches (is_ex=True), valid cookies must be provided in request_kwargs.
        - The base URL is automatically selected based on the is_ex parameter.
    """
    base_url = "https://upld.exhentai.org" if is_ex else "https://upld.e-hentai.org"
    super().__init__(base_url, **request_kwargs)
    self.is_ex = is_ex
    self.covers = covers
    self.similar = similar
    self.exp = exp
search(url=None, file=None, **kwargs) async

Performs a reverse image search on EHentai/ExHentai.

This method supports two ways of searching
  1. Search by image URL
  2. Search by uploading a local image file

Parameters:

Name Type Description Default
url Optional[str]

URL of the image to search.

None
file Union[str, bytes, Path, None]

Local image file, can be a path string, bytes data, or Path object.

None
**kwargs Any

Additional arguments passed to the parent class.

{}

Returns:

Name Type Description
EHentaiResponse EHentaiResponse

Contains search results and metadata, including: - Similar gallery entries - Gallery URLs and titles - Similarity scores - Additional metadata from the search results

Raises:

Type Description
ValueError

If neither url nor file is provided.

RuntimeError

If searching on ExHentai without proper authentication.

Note
  • Only one of url or file should be provided.
  • For ExHentai searches, valid cookies must be provided in the request_kwargs.
  • Search behavior is affected by the covers, similar, and exp flags set during initialization.
Source code in PicImageSearch/engines/ehentai.py
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
async def search(
    self,
    url: Optional[str] = None,
    file: Union[str, bytes, Path, None] = None,
    **kwargs: Any,
) -> EHentaiResponse:
    """Performs a reverse image search on EHentai/ExHentai.

    This method supports two ways of searching:
        1. Search by image URL
        2. Search by uploading a local image file

    Args:
        url (Optional[str]): URL of the image to search.
        file (Union[str, bytes, Path, None]): Local image file, can be a path string, bytes data, or Path object.
        **kwargs (Any): Additional arguments passed to the parent class.

    Returns:
        EHentaiResponse: Contains search results and metadata, including:
            - Similar gallery entries
            - Gallery URLs and titles
            - Similarity scores
            - Additional metadata from the search results

    Raises:
        ValueError: If neither `url` nor `file` is provided.
        RuntimeError: If searching on ExHentai without proper authentication.

    Note:
        - Only one of `url` or `file` should be provided.
        - For ExHentai searches, valid cookies must be provided in the request_kwargs.
        - Search behavior is affected by the covers, similar, and exp flags set during initialization.
    """
    self._validate_args(url, file)

    endpoint = "upld/image_lookup.php" if self.is_ex else "image_lookup.php"
    data: dict[str, Any] = {"f_sfile": "File Search"}
    files: dict[str, Any] = {}

    if url:
        files = {"sfile": await self.download(url)}
    elif file:
        files = {"sfile": read_file(file)}

    if self.covers:
        data["fs_covers"] = "on"
    if self.similar:
        data["fs_similar"] = "on"
    if self.exp:
        data["fs_exp"] = "on"

    resp = await self._make_request(
        method="post",
        endpoint=endpoint,
        data=data,
        files=files,
    )

    return EHentaiResponse(resp.text, resp.url)

Functions