nhpdf 1.6__py3-none-any.whl → 1.8__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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import img2pdf
|
|
2
|
-
import
|
|
1
|
+
import img2pdf
|
|
2
|
+
import cloudscraper
|
|
3
3
|
from typing import NoReturn
|
|
4
4
|
from bs4 import BeautifulSoup
|
|
5
5
|
from concurrent.futures import ThreadPoolExecutor
|
|
@@ -9,10 +9,19 @@ import time
|
|
|
9
9
|
import threading
|
|
10
10
|
from pathlib import Path
|
|
11
11
|
from math import trunc
|
|
12
|
+
import io
|
|
13
|
+
from PIL import Image
|
|
12
14
|
|
|
13
15
|
nhpdf_dir = Path.home()/"Documents"/"nhpdf"
|
|
14
16
|
nhpdf_dir.mkdir(parents=True, exist_ok=True)
|
|
15
17
|
|
|
18
|
+
scraper = cloudscraper.create_scraper(
|
|
19
|
+
browser={
|
|
20
|
+
"browser": "chrome",
|
|
21
|
+
"platform": "windows",
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
|
|
16
25
|
def loading_animation() -> NoReturn:
|
|
17
26
|
global la, pages, page
|
|
18
27
|
spinner = ['|', '/', '-', '\\']
|
|
@@ -31,18 +40,34 @@ def download_image(raw_url: str) -> bytes:
|
|
|
31
40
|
page += 1
|
|
32
41
|
img_code, f_type = re.search(r'/(\d+)', raw_url['data-src']).group(), re.search(r'\b(.(jpg|jpeg|png|webp|gif|tiff|svg))\b', raw_url['data-src']).group()
|
|
33
42
|
url = f'https://i3.nhentai.net/galleries{img_code}/{page}{f_type}'
|
|
34
|
-
response =
|
|
43
|
+
response = scraper.get(url)
|
|
35
44
|
if response.status_code == 200:
|
|
36
|
-
|
|
45
|
+
content = check_alpha(response.content)
|
|
46
|
+
return content
|
|
37
47
|
return None
|
|
38
48
|
|
|
39
49
|
def compile_images(raw: list, name: str) -> NoReturn:
|
|
40
50
|
with ThreadPoolExecutor(max_workers=10) as executor:
|
|
41
51
|
raw_images = list(executor.map(download_image, raw))
|
|
52
|
+
for img in raw_images:
|
|
53
|
+
check_alpha(img)
|
|
42
54
|
nhpdf = nhpdf_dir/f"{name}.pdf"
|
|
43
55
|
with open(nhpdf, "wb") as file:
|
|
44
56
|
file.write(img2pdf.convert(raw_images))
|
|
45
57
|
|
|
58
|
+
def check_alpha(image: bytes) -> bytes:
|
|
59
|
+
try:
|
|
60
|
+
img2pdf.convert(image)
|
|
61
|
+
except img2pdf.AlphaChannelError:
|
|
62
|
+
buffered = io.BytesIO(image)
|
|
63
|
+
img = Image.open(buffered)
|
|
64
|
+
converted: Image = img.convert('RGB')
|
|
65
|
+
buf = io.BytesIO()
|
|
66
|
+
converted.save(buf, format='PNG')
|
|
67
|
+
image = buf.getvalue()
|
|
68
|
+
return image
|
|
69
|
+
|
|
70
|
+
|
|
46
71
|
def start_nhpdf():
|
|
47
72
|
global la, page, pages
|
|
48
73
|
if len(sys.argv) < 2:
|
|
@@ -61,7 +86,7 @@ def start_nhpdf():
|
|
|
61
86
|
print("\nThe code needs to be numbers (Ex: 177013) :) \n\ngoing to the next code...")
|
|
62
87
|
continue
|
|
63
88
|
url = f'https://nhentai.net/g/{code}/'
|
|
64
|
-
response =
|
|
89
|
+
response = scraper.get(url)
|
|
65
90
|
try:
|
|
66
91
|
soup = BeautifulSoup(response.text, "html.parser")
|
|
67
92
|
pages = len(soup.find_all(class_='gallerythumb'))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nhpdf
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.8
|
|
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
|
|
@@ -12,6 +12,7 @@ Classifier: Development Status :: 4 - Beta
|
|
|
12
12
|
Classifier: Programming Language :: Python
|
|
13
13
|
Requires-Python: >=3.8
|
|
14
14
|
Requires-Dist: beautifulsoup4
|
|
15
|
+
Requires-Dist: cloudscraper
|
|
15
16
|
Requires-Dist: img2pdf
|
|
16
17
|
Requires-Dist: requests
|
|
17
18
|
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
nhpdf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
nhpdf/nhpdf.py,sha256=JecJnkqs_vqf9kekuXXDzlawfbo-kcgKw9HjtyECx7M,3853
|
|
3
|
+
nhpdf-1.8.dist-info/METADATA,sha256=hK6ndatQvzByFGN12DAIjltPsE0N9_oFaRFe51Od6QA,2901
|
|
4
|
+
nhpdf-1.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
5
|
+
nhpdf-1.8.dist-info/entry_points.txt,sha256=Dn0ISURSvQrGZMCOxYEA5ocSWU5DUOiT50J7FHZk5Xs,50
|
|
6
|
+
nhpdf-1.8.dist-info/RECORD,,
|
nhpdf-1.6.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
nhpdf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
nhpdf/nhpdf.py,sha256=-o0ryeh69xNosrLmP8SD_MIOawLXvKb6x3vo1oFmpPw,3265
|
|
3
|
-
nhpdf-1.6.dist-info/METADATA,sha256=wqI6ZqBEwE6Vc2SSGehddMfwqH10JeaLObON9venzD8,2873
|
|
4
|
-
nhpdf-1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
5
|
-
nhpdf-1.6.dist-info/entry_points.txt,sha256=Dn0ISURSvQrGZMCOxYEA5ocSWU5DUOiT50J7FHZk5Xs,50
|
|
6
|
-
nhpdf-1.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|