nhpdf 1.0__py3-none-any.whl → 1.1__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.
nhpdf/nhpdf.py CHANGED
@@ -2,37 +2,42 @@ import img2pdf # type: ignore
2
2
  import requests
3
3
  from typing import NoReturn
4
4
  from bs4 import BeautifulSoup
5
+ from concurrent.futures import ThreadPoolExecutor
5
6
  import re
6
7
  import sys
7
8
  import time
8
9
  import threading
9
10
  from pathlib import Path
11
+ from math import trunc
10
12
 
11
13
  nhpdf_dir = Path.home()/"Documents"/"nhpdf"
12
14
  nhpdf_dir.mkdir(parents=True, exist_ok=True)
13
15
 
14
- def loading_animation():
16
+ def loading_animation() -> NoReturn:
15
17
  global la, pages, page
16
18
  spinner = ['|', '/', '-', '\\']
17
19
  while not la:
18
20
  for frame in spinner:
19
- sys.stdout.write(f'\rDownloading the pages ({page}/{pages})...{frame}')
21
+ sys.stdout.write(f'\rDownloading the pages ({trunc((page/pages)*100)}%/{100}%)...{frame}')
20
22
  sys.stdout.flush()
21
23
  time.sleep(0.1)
22
24
  if la:
23
25
  break
24
-
25
- def compile_images(raw: list, name: str) -> NoReturn:
26
+
27
+ def download_image(raw_url: str) -> bytes:
26
28
  global pages, page
27
- raw_images = []
28
- for item in raw:
29
- page += 1
30
- img_code, f_type = re.search(r'/(\d+)', item['data-src']).group(), re.search(r'\.([a-zA-Z0-9]+)$', item['data-src']).group()
31
- url = f'https://i3.nhentai.net/galleries{img_code}/{page}{f_type}'
32
- response = requests.get(url)
33
- raw_images.append(response.content)
34
- if page == pages:
35
- break
29
+ page += 1
30
+ img_code, f_type = re.search(r'/(\d+)', raw_url['data-src']).group(), re.search(r'\b(.(jpg|jpeg|png|webp))\b', raw_url['data-src']).group()
31
+ url = f'https://i3.nhentai.net/galleries{img_code}/{page}{f_type}'
32
+ response = requests.get(url)
33
+ if response.status_code == 200:
34
+ return response.content
35
+ return None
36
+
37
+
38
+ def compile_images(raw: list, name: str) -> NoReturn:
39
+ with ThreadPoolExecutor(max_workers=10) as executor:
40
+ raw_images = list(executor.map(download_image, raw))
36
41
  nhpdf = nhpdf_dir/f"{name}.pdf"
37
42
  with open(nhpdf, "wb") as file:
38
43
  file.write(img2pdf.convert(raw_images))
@@ -68,9 +73,10 @@ def start_nhpdf():
68
73
  print("\n[ERROR]: The code cannot be found in the website.\n\ngoing to the next code...")
69
74
  continue
70
75
  print(f"\nH-Doujin Details:\nname: {name}\nauthor: {author}\npages: {pages}\n")
76
+ raw_data.remove(raw_data[0])
71
77
  function_thread = threading.Thread(target=loading_animation)
72
78
  function_thread.start()
73
- compile_images(raw_data, name)
79
+ compile_images(raw_data[:pages], name)
74
80
  la = True
75
81
  function_thread.join()
76
82
  if item != items:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nhpdf
3
- Version: 1.0
3
+ Version: 1.1
4
4
  Summary: Download NHentai doujins as PDF
5
5
  Project-URL: Homepage, https://github.com/Aze543/NhentaiDoujinToPDFMaker
6
6
  Project-URL: Issues, https://github.com/Aze543/NhentaiDoujinToPDFMaker/issues
@@ -8,7 +8,7 @@ Author-email: Aze543 <eizen.9258437663@gmail.com>
8
8
  Maintainer-email: Aze543 <eizen.9258437663@gmail.com>
9
9
  License-Expression: MIT
10
10
  Keywords: goon,pdf,scraper
11
- Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Development Status :: 4 - Beta
12
12
  Classifier: Programming Language :: Python
13
13
  Requires-Python: >=3.8
14
14
  Requires-Dist: beautifulsoup4
@@ -0,0 +1,6 @@
1
+ nhpdf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ nhpdf/nhpdf.py,sha256=UCOMrCbjVINbv9tj-dxM--ajzOloU_4ti3DenI0arCY,3131
3
+ nhpdf-1.1.dist-info/METADATA,sha256=euYbpRlYPAQGxNFW0V3thJ3gV67qRJq4BkHqWtZ9C8E,2864
4
+ nhpdf-1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ nhpdf-1.1.dist-info/entry_points.txt,sha256=Dn0ISURSvQrGZMCOxYEA5ocSWU5DUOiT50J7FHZk5Xs,50
6
+ nhpdf-1.1.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- nhpdf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- nhpdf/nhpdf.py,sha256=H8fl4xUlBbO16MPuJVQ0WzYnHJSQvW7HItj5-AhjxoY,2873
3
- nhpdf-1.0.dist-info/METADATA,sha256=p0xAaaQL0xmpRk3xwRbyOm8En2Ue83VslE3ZbDFiFoc,2877
4
- nhpdf-1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
- nhpdf-1.0.dist-info/entry_points.txt,sha256=Dn0ISURSvQrGZMCOxYEA5ocSWU5DUOiT50J7FHZk5Xs,50
6
- nhpdf-1.0.dist-info/RECORD,,
File without changes