Перейти к содержанию

EHentai

Classes

EHentaiItem

Bases: BaseSearchItem

Represents a single e-hentai gallery item from search results.

Attributes:

Name Type Description
origin PyQuery

The raw PyQuery data of the search result item.

thumbnail str

URL of the gallery's thumbnail image.

url str

Direct URL to the gallery page.

title str

Title of the gallery.

type str

Category/type of the gallery (e.g., 'Doujinshi', 'Manga', etc.).

date str

Upload date of the gallery.

tags list[str]

List of tags associated with the gallery.

Source code in PicImageSearch/model/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
class EHentaiItem(BaseSearchItem):
    """Represents a single e-hentai gallery item from search results.

    Attributes:
        origin (PyQuery): The raw PyQuery data of the search result item.
        thumbnail (str): URL of the gallery's thumbnail image.
        url (str): Direct URL to the gallery page.
        title (str): Title of the gallery.
        type (str): Category/type of the gallery (e.g., 'Doujinshi', 'Manga', etc.).
        date (str): Upload date of the gallery.
        tags (list[str]): List of tags associated with the gallery.
    """

    def __init__(self, data: PyQuery, **kwargs: Any):
        """Initializes an EHentaiItem with data from a search result.

        Args:
            data (PyQuery): A PyQuery instance containing the search result item's data.
        """
        super().__init__(data, **kwargs)

    def _parse_data(self, data: PyQuery, **kwargs: Any) -> None:
        """Initialize and parse the gallery data from search results.

        Args:
            data (PyQuery): PyQuery object containing the gallery's HTML data.
            **kwargs (Any): Additional keyword arguments (unused).
        """
        self.type: str = ""
        self.date: str = ""
        self.tags: list[str] = []
        self._arrange(data)

    def _arrange(self, data: PyQuery) -> None:
        """Extract and organize gallery information from the PyQuery data.

        Processes the HTML data to extract various gallery attributes including:
        - Title and URL
        - Thumbnail image URL
        - Gallery type/category
        - Upload date
        - Associated tags

        Args:
            data (PyQuery): PyQuery object containing the gallery's HTML data.
        """
        glink = data.find(".glink")
        self.title = glink.text()
        if glink.parent("div"):
            self.url = glink.parent("div").parent("a").attr("href")
        else:
            self.url = glink.parent("a").attr("href")
        thumbnail = (
            data.find(".glthumb img")
            or data.find(".gl1e img")
            or data.find(".gl3t img")
        )
        self.thumbnail = thumbnail.attr("data-src") or thumbnail.attr("src")
        _type = data.find(".cs") or data.find(".cn")
        self.type = _type.eq(0).text()
        self.date = data.find("[id^='posted']").eq(0).text()
        self.tags = [
            i.attr("title") for i in data.find("div[class=gt],div[class=gtl]").items()
        ]

Functions

__init__(data, **kwargs)

Initializes an EHentaiItem with data from a search result.

Parameters:

Name Type Description Default
data PyQuery

A PyQuery instance containing the search result item's data.

required
Source code in PicImageSearch/model/ehentai.py
22
23
24
25
26
27
28
def __init__(self, data: PyQuery, **kwargs: Any):
    """Initializes an EHentaiItem with data from a search result.

    Args:
        data (PyQuery): A PyQuery instance containing the search result item's data.
    """
    super().__init__(data, **kwargs)

EHentaiResponse

Bases: BaseSearchResponse[EHentaiItem]

Represents the complete response from an e-hentai reverse image search.

This class processes and organizes the search results from e-hentai, handling both filtered and unfiltered results in different HTML layouts.

Attributes:

Name Type Description
origin PyQuery

The raw PyQuery data of the entire response.

raw list[EHentaiItem]

List of parsed gallery items from the search.

url str

URL of the search results page.

Source code in PicImageSearch/model/ehentai.py
 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
109
110
111
112
113
114
115
116
class EHentaiResponse(BaseSearchResponse[EHentaiItem]):
    """Represents the complete response from an e-hentai reverse image search.

    This class processes and organizes the search results from e-hentai,
    handling both filtered and unfiltered results in different HTML layouts.

    Attributes:
        origin (PyQuery): The raw PyQuery data of the entire response.
        raw (list[EHentaiItem]): List of parsed gallery items from the search.
        url (str): URL of the search results page.
    """

    def __init__(self, resp_data: str, resp_url: str, **kwargs: Any):
        """Initializes with the response text and URL.

        Args:
            resp_data (str): The text of the response.
            resp_url (str): URL to the search result page.
        """
        super().__init__(resp_data, resp_url, **kwargs)

    def _parse_response(self, resp_data: str, **kwargs: Any) -> None:
        """Parse the HTML response data from e-hentai search.

        Handles different result layouts:
        - Table layout (.itg > tr)
        - Grid layout (.itg > .gl1t)
        - No results case

        Args:
            resp_data (str): Raw HTML string from the search response.
            **kwargs (Any): Additional keyword arguments (unused).
        """
        data = parse_html(resp_data)
        self.origin: PyQuery = data
        if "No unfiltered results" in resp_data:
            self.raw = []
        elif tr_items := data.find(".itg").children("tr").items():
            self.raw = [EHentaiItem(i) for i in tr_items if i.children("td")]
        else:
            gl1t_items = data.find(".itg").children(".gl1t").items()
            self.raw = [EHentaiItem(i) for i in gl1t_items]

Functions

__init__(resp_data, resp_url, **kwargs)

Initializes with the response text and URL.

Parameters:

Name Type Description Default
resp_data str

The text of the response.

required
resp_url str

URL to the search result page.

required
Source code in PicImageSearch/model/ehentai.py
87
88
89
90
91
92
93
94
def __init__(self, resp_data: str, resp_url: str, **kwargs: Any):
    """Initializes with the response text and URL.

    Args:
        resp_data (str): The text of the response.
        resp_url (str): URL to the search result page.
    """
    super().__init__(resp_data, resp_url, **kwargs)

Functions