Skip to content

Commit f5073d1

Browse files
committed
nhentai parser now uses the base mirror
1 parent 3ff3008 commit f5073d1

File tree

2 files changed

+23
-36
lines changed

2 files changed

+23
-36
lines changed

nlightreader/consts/urls.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
URL_REMANGA = "https://remanga.org"
2222
URL_REMANGA_API = "https://remanga.org/api"
2323

24-
URL_NHENTAI = "https://nhentai.to"
25-
URL_NHENTAI_API = "https://nhentai.net/api"
24+
URL_NHENTAI = "https://nhentai.net"
2625

2726
URL_ALLHENTAI = "https://20.allhen.online"
2827
URL_ALLHENTAI_API = ""

nlightreader/parsers/hentai_manga/nhentai_hmanga.py

+22-34
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from bs4 import BeautifulSoup
1+
import validators
2+
from bs4 import BeautifulSoup, element
23

34
from nlightreader.consts.urls import URL_NHENTAI
45
from nlightreader.models import Chapter, Image, Manga
@@ -13,7 +14,6 @@ class NHentai(AbstractHentaiMangaCatalog):
1314
def __init__(self):
1415
super().__init__()
1516
self.url = URL_NHENTAI
16-
self.url_api = URL_NHENTAI_API
1717

1818
def search_manga(self, form):
1919
url = f"{self.url}/search"
@@ -35,19 +35,26 @@ def search_manga(self, form):
3535
caption_tag = i.find("div", class_="caption")
3636
if caption_tag is not None:
3737
name = i.find("div", class_="caption").text
38-
cover_tag = i.find("a", {"class": "cover"})
38+
cover_tag: element.Tag = i.find("a", {"class": "cover"})
3939
if cover_tag is not None:
4040
manga_id = cover_tag["href"].split("/")[-2]
4141
if not manga_id:
4242
continue
43-
mangas.append(
44-
Manga(
45-
manga_id,
46-
self.CATALOG_ID,
47-
name,
48-
"",
49-
),
43+
44+
manga = Manga(
45+
manga_id,
46+
self.CATALOG_ID,
47+
name,
48+
"",
5049
)
50+
51+
if (noscript_img_tag := cover_tag.find("noscript")) and (
52+
img_tag := noscript_img_tag.find("img")
53+
):
54+
src = img_tag.get("src")
55+
if validators.url(src):
56+
manga.preview_url = src
57+
mangas.append(manga)
5158
return mangas
5259

5360
def get_chapters(self, manga: Manga):
@@ -71,14 +78,8 @@ def get_images(self, manga: Manga, chapter: Chapter):
7178
for i in html_items:
7279
img_tag = i.find("img", class_="")
7380
img_url: str = img_tag["src"]
74-
for img_format in ["png", "jpg", "gif"]:
75-
if img_url.endswith(f"t.{img_format}"):
76-
img_url = img_url.replace(
77-
f"t.{img_format}",
78-
f".{img_format}",
79-
1,
80-
)
81-
break
81+
if not validators.url(img_url):
82+
continue
8283
images.append(Image("", html_items.index(i) + 1, img_url))
8384
return images
8485

@@ -93,24 +94,11 @@ def get_image(self, image: Image):
9394
)
9495

9596
def get_preview(self, manga: Manga):
96-
url = f"{self.url}/g/{manga.content_id}"
97-
response = get_html(
98-
url,
97+
return get_html(
98+
manga.preview_url,
9999
headers=self.headers,
100-
content_type="text",
100+
content_type="content",
101101
)
102-
if response:
103-
soup = BeautifulSoup(response, "html.parser")
104-
if html_item := soup.find("div", id="cover"):
105-
if img_tag := html_item.find("img"):
106-
img_request_headers = self.headers | {
107-
"Referer": URL_NHENTAI,
108-
}
109-
return get_html(
110-
img_tag["src"],
111-
content_type="content",
112-
headers=img_request_headers,
113-
)
114102

115103
def get_manga_url(self, manga: Manga) -> str:
116104
return f"{self.url}/g/{manga.content_id}"

0 commit comments

Comments
 (0)