Skip to content

Commit

Permalink
[exhentai] fall back to e-hentai if no username is given
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Apr 28, 2017
1 parent 48a5b11 commit af56887
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gallery_dl/extractor/deviantart.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class DeviantartFavoriteExtractor(DeviantartExtractor):
}),
("http://rosuuri.deviantart.com/favourites/58951174/Useful", {
"url": "9e8d971c80db099b95d1c785399e2bc6eb96cd07",
"keyword": "ea42a4e238f7e54caa250fa2f5abef103cbf30ab",
"keyword": "623dc7cf7178bcce57290931b2f99e21ba318bfd",
}),
]

Expand Down
20 changes: 13 additions & 7 deletions gallery_dl/extractor/exhentai.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ExhentaiGalleryExtractor(Extractor):
"exception": exception.AuthorizationError,
}),
]
api_url = "https://exhentai.org/api.php"
root = "https://exhentai.org"

def __init__(self, match):
Extractor.__init__(self)
Expand All @@ -54,7 +54,7 @@ def items(self):
yield Message.Headers, self.setup_headers()
yield Message.Cookies, self.session.cookies

url = "https://exhentai.org/g/{}/{}/".format(self.gid, self.token)
url = "{}/g/{}/{}/".format(self.root, self.gid, self.token)
response = self.session.get(url)
page = response.text
if response.status_code == 404 and "Gallery Not Available" in page:
Expand All @@ -79,7 +79,7 @@ def setup_headers(self):
"Accept": "text/html,application/xhtml+xml,"
"application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Referer": "https://exhentai.org/",
"Referer": self.root + "/",
})
headers = self.session.headers.copy()
headers["Accept"] = "image/png,image/*;q=0.8,*/*;q=0.5"
Expand Down Expand Up @@ -108,7 +108,7 @@ def get_job_metadata(self, page):
def get_images(self, page):
"""Collect url and metadata for all images in this gallery"""
part = text.extract(page, 'hentai.org/s/', '"')[0]
yield self.image_from_page("https://exhentai.org/s/" + part)
yield self.image_from_page(self.root + "/s/" + part)
yield from self.images_from_api()

def image_from_page(self, url):
Expand All @@ -119,7 +119,7 @@ def image_from_page(self, url):
(None , '<div id="i3"><a onclick="return load_image(', ''),
("nextkey" , "'", "'"),
("url" , '<img id="img" src="', '"'),
("origurl" , 'https://exhentai.org/fullimg.php', '"'),
("origurl" , 'hentai.org/fullimg.php', '"'),
("startkey", 'var startkey="', '";'),
("showkey" , 'var showkey="', '";'),
))[0]
Expand All @@ -129,7 +129,7 @@ def image_from_page(self, url):

if self.original and data["origurl"]:
part = text.unescape(data["origurl"])
url = "https://exhentai.org/fullimg.php" + part
url = self.root + "/fullimg.php" + part
else:
url = data["url"]

Expand All @@ -140,6 +140,7 @@ def image_from_page(self, url):

def images_from_api(self):
"""Get image url and data from api calls"""
api_url = self.root + "/api.php"
nextkey = self.key["next"]
request = {
"method" : "showpage",
Expand All @@ -151,7 +152,7 @@ def images_from_api(self):
while True:
try:
self.wait()
page = self.session.post(self.api_url, json=request).json()
page = self.session.post(api_url, json=request).json()
break
except requests.exceptions.ConnectionError:
pass
Expand Down Expand Up @@ -182,6 +183,11 @@ def wait(self, waittime=None):
def login(self):
"""Login and set necessary cookies"""
username = self.config("username")
if not username:
self.log.info("no username given; using e-hentai.org")
self.root = "https://e-hentai.org"
self.original = False
return
password = self.config("password")
cookies = self._login_impl(username, password)
for key, value in cookies.items():
Expand Down
2 changes: 1 addition & 1 deletion gallery_dl/extractor/hbrowse.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HbrowseMangaExtractor(Extractor):
subcategory = "manga"
pattern = [r"(?:https?://)?(?:www\.)?hbrowse\.com/(\d+)/?$"]
test = [("http://www.hbrowse.com/10363", {
"url": "4d9def5df21c23f8c3d36de2076c189c02ea43bd",
"url": "b89682bfb86c11d2af0dc47463804ec3ac4aadd6",
})]

def __init__(self, match):
Expand Down
4 changes: 2 additions & 2 deletions gallery_dl/extractor/pawoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PawooAccountExtractor(PawooExtractor):
test = [
("https://pawoo.net/@kuroda", {
"url": "1507de8fe69a35d9ceb837c7082e25425eeed593",
"keyword": "841b641adbcd18846474ef2e9eb2d104d4afbc7e",
"keyword": "ece8ba650f6f1519949bc94fd06c37721fc2f65e",
}),
("https://pawoo.net/@zZzZz/", {
"exception": exception.NotFoundError,
Expand Down Expand Up @@ -85,7 +85,7 @@ class PawooStatusExtractor(PawooExtractor):
test = [
("https://pawoo.net/@takehana_note/559043", {
"url": "bff6f435c0101a911eebd985d6b752c2b61721ef",
"keyword": "b922582f8eb8cee306ae05920fbad5a7992acbd5",
"keyword": "752615b20fb9490f18da69ce3822343e03ec61ff",
"content": "3b148cf90174173355fe34179741ce476921b2fc",
}),
("https://pawoo.net/@zZzZz/12346", {
Expand Down

0 comments on commit af56887

Please sign in to comment.