ehentai 0.2.1__py2.py3-none-any.whl → 0.2.3__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/__version__.py CHANGED
@@ -8,7 +8,7 @@
8
8
  """
9
9
  __title__="ehentai"
10
10
  __description__="Python for viewing e-hentai"
11
- __version__="0.2.1"
11
+ __version__="0.2.3"
12
12
  __url__="https://github.com/Homoarea/hentai"
13
13
  __build__=0x3f3f3f
14
14
  __author__="Homoarea"
ehentai/api.py CHANGED
@@ -1,10 +1,10 @@
1
1
  from ehentai.fetch import Gallery,Page
2
- from ehentai.connect import URL, get_sp, keyword
2
+ from ehentai.connect import URL_E, get_sp, keyword
3
3
 
4
- def get_Page(url: str=URL,params=None,encoding: str=None,direct: bool=False)->Page:
4
+ def get_Page(url: str=URL_E,params=None,encoding: str=None,direct: bool=False)->Page:
5
5
  """
6
6
  Args:
7
- url (str, optional): ehentai has the galleries. Defaults to URL.
7
+ url (str, optional): ehentai has the galleries. Defaults to URL_E.
8
8
  params (fetch.keyword, optional): use this to search. Defaults to None.
9
9
  encoding (str, optional): 'utf-8'..,use this when encoding is wrong. Defaults to None.
10
10
  direct (bool,optional): enable this to connect directly
@@ -16,7 +16,7 @@ def get_Page(url: str=URL,params=None,encoding: str=None,direct: bool=False)->Pa
16
16
 
17
17
  def get_search(search_content,cats_code=None,rating=None,expunged=None,torrent=None,cats_list=None,**args)->Page:
18
18
  return get_Page(
19
- url=URL,
19
+ url=URL_E,
20
20
  params=keyword(
21
21
  f_search=search_content,
22
22
  f_cats=cats_code,
ehentai/connect.py CHANGED
@@ -3,31 +3,34 @@ import time
3
3
  from ehentai.conf import CATS
4
4
  from curl_cffi import requests
5
5
 
6
- DOMAIN="e-hentai.org"
7
- URL="https://e-hentai.org"
6
+ DOMAIN_E="e-hentai.org"
7
+ URL_E="https://e-hentai.org"
8
8
 
9
9
  headers={
10
- "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",
10
+ "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
11
11
  "Referer":"http://www.google.com",
12
+ "Accept":"image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
13
+ "Accept-Language":"zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"
12
14
  }
13
15
 
14
16
  hosts=["104.20.19.168", "172.67.2.238", "104.20.18.168"]
15
17
 
16
- def get_response(url: str,direct: bool=False,hosts=hosts,headers=headers,params=None,**args)->requests.Response:
18
+ def get_response(url: str,direct: bool=False,hosts=hosts,headers=headers,params=None,timeout=6.1,**args)->requests.Response:
17
19
 
18
20
  if not direct:
19
21
  for ip in hosts:
20
- if url.find(DOMAIN)!=-1:
21
- headers['Host']=DOMAIN
22
- url=url[:url.find(DOMAIN)]+ip+url[url.find(DOMAIN)+len(DOMAIN):]
22
+ if url.find(DOMAIN_E)!=-1:
23
+ domain=url.split('/')[2]
24
+ headers['Host']=domain
25
+ url=f"{url[:url.find(domain)]}{ip}{url[url.find(domain)+len(domain):]}"
23
26
  try:
24
- print(url)
25
27
  response = requests.get(
26
28
  url,
27
29
  params=params,
28
30
  impersonate="chrome",
29
31
  headers=headers,
30
32
  verify=False,
33
+ timeout=timeout,
31
34
  **args,
32
35
  )
33
36
 
@@ -35,15 +38,18 @@ def get_response(url: str,direct: bool=False,hosts=hosts,headers=headers,params=
35
38
  return response
36
39
  except requests.exceptions.ConnectionError as e:
37
40
  time.sleep(1)
38
- print("fetch again..")
41
+ print("fetch again..",type(e))
42
+ except requests.exceptions.RequestException as e:
43
+ time.sleep(1)
44
+ print("fetch again..",type(e))
39
45
  except requests.exceptions.ReadTimeout as e:
40
46
  time.sleep(1)
41
- print("fetch again..")
47
+ print("fetch again..",type(e))
42
48
  except Exception as e:
43
49
  time.sleep(1)
44
- print("fetch again..")
50
+ print("fetch again..",type(e))
45
51
 
46
- return requests.get(url,params=params,headers=headers,impersonate="chrome",timeout=27.03,**args)
52
+ return requests.get(url,params=params,headers=headers,impersonate="chrome",timeout=timeout,**args)
47
53
 
48
54
  def keyword(
49
55
  f_search: str = None,
@@ -92,9 +98,9 @@ def next_view(sp: BeautifulSoup):
92
98
  # url:target_URL
93
99
  # parms:search_keyword
94
100
  def get_sp(url: str,params=None,encoding=None,direct=False)->BeautifulSoup:
95
- # set encoding
96
101
  response=get_response(url,direct,params=params)
97
102
 
103
+ # set encoding
98
104
  if encoding:
99
105
  response.encoding=encoding
100
106
 
ehentai/eh.py CHANGED
@@ -8,11 +8,7 @@ from typing import List
8
8
  from ehentai.conf import *
9
9
  from ehentai import __version__
10
10
  from ehentai import Page,Gallery,get_search,get_popular
11
-
12
- HOME=os.path.abspath(os.path.join(os.getenv('HOME'),".hentai"))
13
-
14
- if not os.path.exists(HOME):
15
- os.makedirs(HOME)
11
+ from ehentai.utils import save_json,load_json
16
12
 
17
13
  def echo_gl_table(detail=False,gl_table: List[Gallery]=None):
18
14
  if gl_table:
@@ -26,16 +22,6 @@ def echo_gl_table(detail=False,gl_table: List[Gallery]=None):
26
22
  echo("Page's Gallery Table is None.")
27
23
 
28
24
 
29
- def save_json(filename: str,data: object):
30
- with open(os.path.join(HOME,filename),"w") as f:
31
- f.write(json.dumps(data,default=lambda obj:obj.__dict__))
32
- def load_json(filename: str,data_type):
33
- with open(os.path.join(HOME,filename),"r") as f:
34
- return data_type(**json.loads(f.read()))
35
-
36
- page: Page
37
-
38
-
39
25
  @click.group()
40
26
  def cli():
41
27
  pass
@@ -74,13 +60,14 @@ def list(detailed):
74
60
  @click.option('--download/--no-download','-d/',default=False,help="select this to download gallery")
75
61
  @click.option('--rename',default=None,type=str,help="rename gallery when download")
76
62
  @click.option('--path','-p',default=None,type=click.Path(),help="download path,default is current directory")
63
+ @click.option('--stream/--no-stream','-s/',default=True,type=bool,help="enable stream download")
77
64
  @click.option('--comment/--no-comment', '-c/',default=False,help="echo the comment of gallery")
78
- def view(id,download,rename,path,comment):
65
+ def view(id,download,rename,path,stream,comment):
79
66
  page=load_json("page.json",Page)
80
67
  gl=page.gl_table[id]
81
68
  echo(gl)
82
69
  if download:
83
- gl.download(name=rename,path=path)
70
+ gl.download(name=rename,path=path,stream=stream)
84
71
  elif comment:
85
72
  comment=gl.comment()
86
73
  if comment:
@@ -99,8 +86,8 @@ def popular(use_direct):
99
86
  save_json("page.json",page)
100
87
 
101
88
  # testing
102
- @cli.command()
103
- @click.option('--params','-p',default=None)
104
- def t(params):
105
- echo(params if params else "DEFAULT")
106
- pass
89
+ # @cli.command()
90
+ # @click.option('--params','-p',default=None)
91
+ # def t(params):
92
+ # echo(params if params else "DEFAULT")
93
+ # pass
ehentai/fetch.py CHANGED
@@ -2,6 +2,7 @@ from bs4 import BeautifulSoup
2
2
  import os
3
3
  from ehentai.conf import FONT_STYLE,CATS_BG_COLOR,RESET
4
4
  from ehentai.connect import get_sp,next_view,get_response
5
+ import time
5
6
  # book
6
7
  class Gallery:
7
8
  name=""#名字
@@ -23,7 +24,8 @@ class Gallery:
23
24
  def __repr__(self):
24
25
  return f"<{self.name}>"
25
26
 
26
- def download(self,name=None,path=None,img_suffix="webp",show=True,chunk_size=8192):
27
+ def download(self,name=None,path=None,img_suffix="webp",show=True,stream=True,chunk_size=8192):
28
+ start_time=time.time()
27
29
  if show:
28
30
  print("fetching the URL...")
29
31
  path=path if path else "./"
@@ -49,15 +51,18 @@ class Gallery:
49
51
  print(f"Downloading...{i+1}/{totals}")
50
52
 
51
53
  img_src=get_sp(v).find('img',id="img").get('src')
52
- img=get_response(img_src,stream=True)
54
+ img=get_response(img_src,stream=stream)
53
55
  with open(os.path.join(fdir,f"{i}.{img_suffix}"),"wb") as f:
54
- for chunk in img.iter_content(chunk_size=chunk_size):
55
- if chunk:
56
- f.write(chunk)
57
- f.flush()
56
+ if stream:
57
+ for chunk in img.iter_content(chunk_size=chunk_size):
58
+ if chunk:
59
+ f.write(chunk)
60
+ f.flush()
61
+ else:
62
+ f.write(img.content)
58
63
 
59
64
  if show:
60
- print("Completed!!")
65
+ print(f"Completed!! consum:{time.time()-start_time}")
61
66
 
62
67
  # @return:list(author,list[str])
63
68
  def comment(self):
ehentai/utils.py ADDED
@@ -0,0 +1,28 @@
1
+ import json
2
+ import os
3
+ from PIL import Image
4
+ import platform
5
+
6
+ # home path
7
+ HOME:str
8
+ match platform.system():
9
+ case 'Windows':HOME=os.path.abspath(os.path.join(os.getenv('HOMEPATH'),".hentai"))
10
+ case _:HOME=os.path.abspath(os.path.join(os.getenv('HOME'),".hentai"))
11
+
12
+ # json data
13
+ if not os.path.exists(HOME):
14
+ os.makedirs(HOME)
15
+ def save_json(filename: str,data: object):
16
+ with open(os.path.join(HOME,filename),"w") as f:
17
+ f.write(json.dumps(data,default=lambda obj:obj.__dict__))
18
+ def load_json(filename: str,data_type):
19
+ with open(os.path.join(HOME,filename),"r") as f:
20
+ return data_type(**json.loads(f.read()))
21
+
22
+ # args:list[Image]
23
+ def merge_img():
24
+ pass
25
+
26
+ # args:list[Image]
27
+ def img2pdf():
28
+ pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ehentai
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Python for viewing e-hentai
5
5
  Home-page: https://github.com/Homoarea/hentai
6
6
  Author: Homoarea
@@ -0,0 +1,15 @@
1
+ ehentai/__init__.py,sha256=2nj4ZQ3qwERHMUCSE1S0I3wy0mDkCNwCxeSFk-QMZo4,52
2
+ ehentai/__version__.py,sha256=rqpPrT4Y3eMAcfDqfstGBzzIbei-vK0ENoNe8H4mBUg,1012
3
+ ehentai/api.py,sha256=IGCwJiGgQBu9Q0XNJb4_vbNsO7VPOzx31KkqQC2FmtI,1123
4
+ ehentai/conf.py,sha256=_58VU-o5T4k7X1bHLNp_iZXimj9T-JOYYP6PPmeIaFA,1115
5
+ ehentai/connect.py,sha256=F-TQNrKvTpR1vu4XyP8IlLRu8z8XwMteC-Mts0breVk,3846
6
+ ehentai/eh.py,sha256=CcseQ1nXdjkjAwlcvCJpWE_pGAMVDJbaJcSJDxeWOZ8,4224
7
+ ehentai/fetch.py,sha256=UxBFd8FpKXQ3KO746IpA7p3o8B0T7PKDt8ZLpoQ3Zo8,5171
8
+ ehentai/utils.py,sha256=KP0O7zGJl7_gBz5II5Ls5KQljk2v6Q6SL_uggw6sCs8,727
9
+ ehentai-0.2.3.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
10
+ ehentai-0.2.3.dist-info/licenses/NOTICE,sha256=mTsYLHfcXGcFMSSdkQX-LbKWxxieIA2L4sMNXitGN4k,30
11
+ ehentai-0.2.3.dist-info/METADATA,sha256=OxdQPeBFJ-AZVArBrpyxOaoZ9m4WnkJ7JJa7US_cFPs,606
12
+ ehentai-0.2.3.dist-info/WHEEL,sha256=MAQBAzGbXNI3bUmkDsiV_duv8i-gcdnLzw7cfUFwqhU,109
13
+ ehentai-0.2.3.dist-info/entry_points.txt,sha256=lc9qUbtXSHccaXX_CLtlh605pt2r3zfw6Lbuem3mQO8,38
14
+ ehentai-0.2.3.dist-info/top_level.txt,sha256=NzB7Gi8Sxv8D3VNP4b9wiNdC-zQ4yntM0Uo9TAXnScE,8
15
+ ehentai-0.2.3.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- ehentai/__init__.py,sha256=2nj4ZQ3qwERHMUCSE1S0I3wy0mDkCNwCxeSFk-QMZo4,52
2
- ehentai/__version__.py,sha256=tEY2wJZdUS7tYb5RmztuKRSgueXqaNjuVbuxO-E1h0A,1012
3
- ehentai/api.py,sha256=pSZUt_tYSyKz4HLVAvfrrNilRWjUnh7qIaLUTjUPruw,1115
4
- ehentai/conf.py,sha256=_58VU-o5T4k7X1bHLNp_iZXimj9T-JOYYP6PPmeIaFA,1115
5
- ehentai/connect.py,sha256=65ZXrWIZkBk6IhMqBHpXKMJmR5L2ARFZGCTrNhEESbQ,3467
6
- ehentai/eh.py,sha256=bkwYJF3mW1Vk5WxupvREWp0imKWTXSdH356aQBr5uBo,4485
7
- ehentai/fetch.py,sha256=UsSKZLem3RwCsPJi4KO5sRnHjK6TYpDzD6UZJ0_j3EY,4975
8
- ehentai-0.2.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
9
- ehentai-0.2.1.dist-info/licenses/NOTICE,sha256=mTsYLHfcXGcFMSSdkQX-LbKWxxieIA2L4sMNXitGN4k,30
10
- ehentai-0.2.1.dist-info/METADATA,sha256=7CaX-ZL_IcECJZlBaOfONVDyPDvVTwr2R8Vm9TtBG_E,606
11
- ehentai-0.2.1.dist-info/WHEEL,sha256=MAQBAzGbXNI3bUmkDsiV_duv8i-gcdnLzw7cfUFwqhU,109
12
- ehentai-0.2.1.dist-info/entry_points.txt,sha256=lc9qUbtXSHccaXX_CLtlh605pt2r3zfw6Lbuem3mQO8,38
13
- ehentai-0.2.1.dist-info/top_level.txt,sha256=NzB7Gi8Sxv8D3VNP4b9wiNdC-zQ4yntM0Uo9TAXnScE,8
14
- ehentai-0.2.1.dist-info/RECORD,,