ehentai 0.1__py2.py3-none-any.whl → 0.2__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ehentai/__init__.py CHANGED
@@ -0,0 +1 @@
1
+ from .api import Page,Gallery,get_search,get_popular
ehentai/__version__.py CHANGED
@@ -8,7 +8,7 @@
8
8
  """
9
9
  __title__="ehentai"
10
10
  __description__="Python for viewing e-hentai"
11
- __version__="0.1"
11
+ __version__="0.2"
12
12
  __url__="https://github.com/Homoarea/hentai"
13
13
  __build__=0x3f3f3f
14
14
  __author__="Homoarea"
ehentai/api.py ADDED
@@ -0,0 +1,32 @@
1
+ from ehentai.fetch import Gallery,Page
2
+ from ehentai.utils.connect import URL, get_sp, keyword
3
+
4
+ def get_Page(url: str=URL,params=None,encoding: str=None,direct: bool=False)->Page:
5
+ """
6
+ Args:
7
+ url (str, optional): ehentai has the galleries. Defaults to URL.
8
+ params (fetch.keyword, optional): use this to search. Defaults to None.
9
+ encoding (str, optional): 'utf-8'..,use this when encoding is wrong. Defaults to None.
10
+ direct (bool,optional): enable this to connect directly
11
+ Returns:
12
+ Page:
13
+ attr:gl_table,rangebar,search_text
14
+ """
15
+ return Page(get_sp(url,params,encoding,direct))
16
+
17
+ def get_search(search_content,cats_code=None,rating=None,expunged=None,torrent=None,cats_list=None,**args)->Page:
18
+ return get_Page(
19
+ url=URL,
20
+ params=keyword(
21
+ f_search=search_content,
22
+ f_cats=cats_code,
23
+ f_srdd=rating,
24
+ f_sh=expunged,
25
+ f_sto=torrent,
26
+ cats_list=cats_list
27
+ ),
28
+ **args
29
+ )
30
+
31
+ def get_popular(**args):
32
+ return get_Page(url="https://e-hentai.org/popular",**args)
ehentai/eh.py CHANGED
@@ -1,15 +1,14 @@
1
1
  import sys
2
- import pickle
3
2
  import os
4
3
  import json
5
4
  import click
6
5
  import json
7
6
  from click import echo
8
7
  from typing import List
9
- from ehentai.fetch import get_sp,Page,Gallery,url
10
- from ehentai import fetch
11
8
  from ehentai.conf import *
12
9
  from ehentai import __version__
10
+ from ehentai import Page,Gallery,get_search,get_popular
11
+
13
12
  HOME=os.path.abspath(os.path.join(os.getenv('HOME'),".hentai"))
14
13
 
15
14
  if not os.path.exists(HOME):
@@ -40,12 +39,6 @@ page: Page
40
39
  @click.group()
41
40
  def cli():
42
41
  pass
43
- # testing
44
- # @cli.command()
45
- # @click.option('--params','-p',default=None)
46
- # def t(params):
47
- # echo(params if params else "DEFAULT")
48
- # pass
49
42
  @cli.command(help="|show the version")
50
43
  def version():
51
44
  echo(f"""{FONT_COLOR.pink.value}
@@ -59,25 +52,16 @@ def version():
59
52
  echo(f"Version: {__version__.__version__}")
60
53
 
61
54
  @cli.command(help="|search from e-hentai")
62
- @click.option('--search-text','-s',default="",prompt=True,help="search content,tags")
55
+ @click.option('--search-content','-s',default="",type=str,prompt=True,help="search content,tags")
63
56
  @click.option('--cats','-c',default=255,type=int,help="Doujinshi,Manga...")
64
57
  @click.option('--rating','-r',default=None,type=int,help="the minium rating")
65
- @click.option('--show-expunged/--no-show-expunged','-sh',default=False,help="show the removed galleries")
66
- @click.option('--show-torrent/--no-show-torrent','-sto',default=False,help="filter galleries have torrent")
67
- def search(search_text,cats,rating,show_expunged,show_torrent):
68
- page = Page(
69
- get_sp(
70
- url,
71
- params=fetch.keyword(
72
- f_search=search_text,
73
- f_cats=fetch.get_f_cats(cats),
74
- f_srdd=rating,
75
- f_sh=show_expunged,
76
- f_sto=show_torrent,
77
- ),
78
- )
79
- )
58
+ @click.option('--show-expunged/--no-show-expunged','-sh/',default=False,help="show the removed galleries")
59
+ @click.option('--show-torrent/--no-show-torrent','-sto/',default=False,help="filter galleries have torrent")
60
+ @click.option('--use-direct/--no-direct','-u',default=False,help="enable this to connect directly")
61
+ def search(search_content,cats,rating,show_expunged,show_torrent,use_direct):
62
+ page=get_search(search_content,cats,rating,show_expunged,show_torrent,direct=use_direct)
80
63
  save_json("page.json",page)
64
+ print(page)
81
65
 
82
66
  @cli.command(help="|show the fetched galleries")
83
67
  @click.option("--detailed/--no-detailed", "-d/", default=False)
@@ -92,26 +76,31 @@ def list(detailed):
92
76
  @click.option('--path','-p',default=None,type=click.Path(),help="download path,default is current directory")
93
77
  @click.option('--comment/--no-comment', '-c/',default=False,help="echo the comment of gallery")
94
78
  def view(id,download,rename,path,comment):
95
- try:
96
- page=load_json("page.json",Page)
97
- gl=page.gl_table[id]
98
- echo(gl)
99
- if download:
100
- gl.download(name=rename,path=path)
101
- elif comment:
102
- comment=gl.comment()
103
- if comment:
104
- for nick,cs in comment:
105
- echo(f"{FONT_STYLE.bold.value}{FONT_COLOR.green.value}{nick}{RESET}")
106
- for c in cs:
107
- echo(f"\t{c}")
108
- else:
109
- echo("no comments")
110
- except Exception:
111
- echo(Exception)
112
-
79
+ page=load_json("page.json",Page)
80
+ gl=page.gl_table[id]
81
+ echo(gl)
82
+ if download:
83
+ gl.download(name=rename,path=path)
84
+ elif comment:
85
+ comment=gl.comment()
86
+ if comment:
87
+ for nick,cs in comment:
88
+ echo(f"{FONT_STYLE.bold.value}{FONT_COLOR.green.value}{nick}{RESET}")
89
+ for c in cs:
90
+ echo(f"\t{c}")
91
+ else:
92
+ echo("no comments")
93
+
113
94
  @cli.command(help="|fetch popular galleries")
114
- def popular():
115
- page=Page(get_sp("https://e-hentai.org/popular"))
95
+ @click.option('--use-direct/--no-direct','-u',default=False,help="enable this to connect directly")
96
+ def popular(use_direct):
97
+ page=get_popular(direct=use_direct)
116
98
  echo(f"Currently Popular Recent Galleries:{len(page.gl_table)}")
117
- save_json("page.json",page)
99
+ save_json("page.json",page)
100
+
101
+ # testing
102
+ @cli.command()
103
+ @click.option('--params','-p',default=None)
104
+ def t(params):
105
+ echo(params if params else "DEFAULT")
106
+ pass
ehentai/fetch.py CHANGED
@@ -1,9 +1,7 @@
1
- import json
2
- import requests
3
- import chardet
4
1
  from bs4 import BeautifulSoup
5
2
  import os
6
- from ehentai.conf import *
3
+ from ehentai.conf import FONT_STYLE,CATS_BG_COLOR,RESET
4
+ from ehentai.utils.connect import get_sp,next_view,get_response
7
5
  # book
8
6
  class Gallery:
9
7
  name=""#名字
@@ -25,7 +23,7 @@ class Gallery:
25
23
  def __repr__(self):
26
24
  return f"<{self.name}>"
27
25
 
28
- def download(self,name=None,path=None,img_suffix="webp",show=True):
26
+ def download(self,name=None,path=None,img_suffix="webp",show=True,chunk_size=8192):
29
27
  if show:
30
28
  print("fetching the URL...")
31
29
  path=path if path else "./"
@@ -43,7 +41,7 @@ class Gallery:
43
41
  print(f"Totals:{totals}")
44
42
 
45
43
  fdir=os.path.join(path,name if name else self.name)
46
- os.makedirs(fdir)
44
+ os.makedirs(fdir) if not os.path.exists(fdir) else None
47
45
 
48
46
  for i,v in enumerate(images):
49
47
 
@@ -51,10 +49,13 @@ class Gallery:
51
49
  print(f"Downloading...{i+1}/{totals}")
52
50
 
53
51
  img_src=get_sp(v).find('img',id="img").get('src')
54
- img=requests.get(img_src,headers=headers)
52
+ img=get_response(img_src,stream=True)
55
53
  with open(os.path.join(fdir,f"{i}.{img_suffix}"),"wb") as f:
56
- f.write(img.content)
57
-
54
+ for chunk in img.iter_content(chunk_size=chunk_size):
55
+ if chunk:
56
+ f.write(chunk)
57
+ f.flush()
58
+
58
59
  if show:
59
60
  print("Completed!!")
60
61
 
@@ -123,77 +124,3 @@ class Page:
123
124
  tags=list(map(lambda x:x.get('title'),td[2].find_all('div',class_="gt"))),
124
125
  s_tags=list(map(lambda x:x.get_text(),td[2].find_all('div',class_="gt"))),
125
126
  ))
126
-
127
-
128
- def keyword(
129
- f_search: str = None,
130
- f_cats: int = None,
131
- advsearch: bool = None,
132
- f_sh: bool = None,
133
- f_sto: bool = None,
134
- f_spf: int = None,
135
- f_spt: int = None,
136
- f_srdd: int = None,
137
- f_sfl: bool = None,
138
- f_sfu: bool = None,
139
- f_sft: bool = None,
140
- ):
141
-
142
- return {
143
- # search_kw
144
- "f_search":f_search,
145
- # category
146
- "f_cats":f_cats,
147
- # advanced search
148
- # show advanced options
149
- "advsearch":1 if advsearch or f_sh or f_sto or f_spf or f_spt or f_srdd or f_sfl or f_sfu or f_sft else None,
150
- # show expunged galleries
151
- "f_sh":"on" if f_sh else None,
152
- # require Gallery torrent
153
- "f_sto":"on" if f_sto else None,
154
- # between {f_spf} and {f_spt} Pages
155
- "f_spf":f_spf,
156
- "f_spt":f_spt,
157
- # minimum_rating
158
- "f_srdd":f_srdd,
159
- # disable filter language
160
- "f_sfl":"on" if f_sfl else None,
161
- # disable filter uploader
162
- "f_sfu":"on" if f_sfu else None,
163
- # disable filter tags
164
- "f_sft":"on" if f_sft else None,
165
- }
166
-
167
-
168
- def next_view(sp: BeautifulSoup):
169
- return sp.find('table',class_="ptt").find_all('td')[-1].find('a')
170
-
171
- # url:target_URL
172
- # parms:search_keyword
173
- def get_sp(url: str,params=None,encoding=None):
174
- # set encoding
175
- respone=requests.get(url,headers=headers,params=params)
176
- if encoding:
177
- respone.encoding=encoding
178
- else:
179
- encoding=chardet.detect(respone.content)["encoding"]
180
- respone.encoding=encoding
181
-
182
- return BeautifulSoup(respone.text,"lxml")
183
-
184
-
185
- # switch categories: doujinshi...
186
- def get_f_cats(cat_code=0b0011111111):
187
- res=0b1111111111
188
- for v in list(i.value for i in CATS):
189
- if cat_code&1:res&=v
190
- cat_code>>=1
191
- return res
192
-
193
-
194
- url="https://e-hentai.org/"
195
-
196
- headers={
197
- "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
198
- "Referer":"http://www.google.com",
199
- }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ehentai
3
- Version: 0.1
3
+ Version: 0.2
4
4
  Summary: Python for viewing e-hentai
5
5
  Home-page: https://github.com/Homoarea/hentai
6
6
  Author: Homoarea
@@ -11,8 +11,7 @@ Requires-Python: >=3.8
11
11
  License-File: LICENSE
12
12
  License-File: NOTICE
13
13
  Requires-Dist: click
14
- Requires-Dist: requests
15
- Requires-Dist: chardet
14
+ Requires-Dist: curl_cffi
16
15
  Requires-Dist: beautifulsoup4
17
16
  Requires-Dist: lxml
18
17
  Dynamic: author
@@ -0,0 +1,13 @@
1
+ ehentai/__init__.py,sha256=2nj4ZQ3qwERHMUCSE1S0I3wy0mDkCNwCxeSFk-QMZo4,52
2
+ ehentai/__version__.py,sha256=ItZgDjKTDWKAb-z5rJ4jLukDnSFQ7Ep6F-6NImOEqJk,1010
3
+ ehentai/api.py,sha256=zTPygliwFDJ4AxHg1OQgKGWXlEevyTOBiTBObi4aCBE,1121
4
+ ehentai/conf.py,sha256=_58VU-o5T4k7X1bHLNp_iZXimj9T-JOYYP6PPmeIaFA,1115
5
+ ehentai/eh.py,sha256=bkwYJF3mW1Vk5WxupvREWp0imKWTXSdH356aQBr5uBo,4485
6
+ ehentai/fetch.py,sha256=IZDVdnV2aMnUszd0S0e_H2yerc8oP_XFLopo7q-ulBo,4981
7
+ ehentai-0.2.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
8
+ ehentai-0.2.dist-info/licenses/NOTICE,sha256=mTsYLHfcXGcFMSSdkQX-LbKWxxieIA2L4sMNXitGN4k,30
9
+ ehentai-0.2.dist-info/METADATA,sha256=nkW-443IMUDLEZrNHnC90rc-ujDhwzSMJ-1fAgyLN1M,604
10
+ ehentai-0.2.dist-info/WHEEL,sha256=MAQBAzGbXNI3bUmkDsiV_duv8i-gcdnLzw7cfUFwqhU,109
11
+ ehentai-0.2.dist-info/entry_points.txt,sha256=lc9qUbtXSHccaXX_CLtlh605pt2r3zfw6Lbuem3mQO8,38
12
+ ehentai-0.2.dist-info/top_level.txt,sha256=NzB7Gi8Sxv8D3VNP4b9wiNdC-zQ4yntM0Uo9TAXnScE,8
13
+ ehentai-0.2.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- ehentai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- ehentai/__version__.py,sha256=2XCu8UZLyjNvRbALSQFtl0-zvouEuBrV0xP5dRAzbjc,1010
3
- ehentai/conf.py,sha256=_58VU-o5T4k7X1bHLNp_iZXimj9T-JOYYP6PPmeIaFA,1115
4
- ehentai/eh.py,sha256=qjsFVX0HMis5LoEn1u_N2XkUHj0cQa3ptXUu5cPkbPU,4612
5
- ehentai/fetch.py,sha256=-WdjNDgww3XW6ogUyuYelcvOOYiFM9wyInRL_gbSg5U,6721
6
- ehentai-0.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
7
- ehentai-0.1.dist-info/licenses/NOTICE,sha256=mTsYLHfcXGcFMSSdkQX-LbKWxxieIA2L4sMNXitGN4k,30
8
- ehentai-0.1.dist-info/METADATA,sha256=3sUpjIYwJWrZPxOYQ57uBQT_Ck7l70juRAywBdRW5oc,626
9
- ehentai-0.1.dist-info/WHEEL,sha256=MAQBAzGbXNI3bUmkDsiV_duv8i-gcdnLzw7cfUFwqhU,109
10
- ehentai-0.1.dist-info/entry_points.txt,sha256=lc9qUbtXSHccaXX_CLtlh605pt2r3zfw6Lbuem3mQO8,38
11
- ehentai-0.1.dist-info/top_level.txt,sha256=NzB7Gi8Sxv8D3VNP4b9wiNdC-zQ4yntM0Uo9TAXnScE,8
12
- ehentai-0.1.dist-info/RECORD,,
File without changes