summaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/exhentai.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/extractor/exhentai.py')
-rw-r--r--gallery_dl/extractor/exhentai.py157
1 files changed, 52 insertions, 105 deletions
diff --git a/gallery_dl/extractor/exhentai.py b/gallery_dl/extractor/exhentai.py
index 9cd7ae4..44bfe7d 100644
--- a/gallery_dl/extractor/exhentai.py
+++ b/gallery_dl/extractor/exhentai.py
@@ -23,25 +23,28 @@ class ExhentaiExtractor(Extractor):
directory_fmt = ("{category}", "{gid} {title[:247]}")
filename_fmt = "{gid}_{num:>04}_{image_token}_{filename}.{extension}"
archive_fmt = "{gid}_{num}"
- cookienames = ("ipb_member_id", "ipb_pass_hash")
- cookiedomain = ".exhentai.org"
+ cookies_domain = ".exhentai.org"
+ cookies_names = ("ipb_member_id", "ipb_pass_hash")
root = "https://exhentai.org"
request_interval = 5.0
LIMIT = False
def __init__(self, match):
- # allow calling 'self.config()' before 'Extractor.__init__()'
- self._cfgpath = ("extractor", self.category, self.subcategory)
+ Extractor.__init__(self, match)
+ self.version = match.group(1)
- version = match.group(1)
+ def initialize(self):
domain = self.config("domain", "auto")
if domain == "auto":
- domain = ("ex" if version == "ex" else "e-") + "hentai.org"
+ domain = ("ex" if self.version == "ex" else "e-") + "hentai.org"
self.root = "https://" + domain
- self.cookiedomain = "." + domain
+ self.cookies_domain = "." + domain
- Extractor.__init__(self, match)
+ Extractor.initialize(self)
+
+ if self.version != "ex":
+ self.cookies.set("nw", "1", domain=self.cookies_domain)
self.original = self.config("original", True)
limits = self.config("limits", False)
@@ -51,10 +54,6 @@ class ExhentaiExtractor(Extractor):
else:
self.limits = False
- self.session.headers["Referer"] = self.root + "/"
- if version != "ex":
- self.session.cookies.set("nw", "1", domain=self.cookiedomain)
-
def request(self, url, **kwargs):
response = Extractor.request(self, url, **kwargs)
if response.history and response.headers.get("Content-Length") == "0":
@@ -66,17 +65,20 @@ class ExhentaiExtractor(Extractor):
"""Login and set necessary cookies"""
if self.LIMIT:
raise exception.StopExtraction("Image limit reached!")
- if self._check_cookies(self.cookienames):
+
+ if self.cookies_check(self.cookies_names):
return
+
username, password = self._get_auth_info()
if username:
- self._update_cookies(self._login_impl(username, password))
- else:
- self.log.info("no username given; using e-hentai.org")
- self.root = "https://e-hentai.org"
- self.original = False
- self.limits = False
- self.session.cookies["nw"] = "1"
+ return self.cookies_update(self._login_impl(username, password))
+
+ self.log.info("no username given; using e-hentai.org")
+ self.root = "https://e-hentai.org"
+ self.cookies_domain = ".e-hentai.org"
+ self.cookies.set("nw", "1", domain=self.cookies_domain)
+ self.original = False
+ self.limits = False
@cache(maxage=90*24*3600, keyarg=1)
def _login_impl(self, username, password):
@@ -97,7 +99,7 @@ class ExhentaiExtractor(Extractor):
response = self.request(url, method="POST", headers=headers, data=data)
if b"You are now logged in as:" not in response.content:
raise exception.AuthenticationError()
- return {c: response.cookies[c] for c in self.cookienames}
+ return {c: response.cookies[c] for c in self.cookies_names}
class ExhentaiGalleryExtractor(ExhentaiExtractor):
@@ -106,61 +108,7 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
pattern = (BASE_PATTERN +
r"(?:/g/(\d+)/([\da-f]{10})"
r"|/s/([\da-f]{10})/(\d+)-(\d+))")
- test = (
- ("https://exhentai.org/g/1200119/d55c44d3d0/", {
- "options": (("original", False),),
- "keyword": {
- "cost": int,
- "date": "dt:2018-03-18 20:14:00",
- "eh_category": "Non-H",
- "expunged": False,
- "favorites": r"re:^[12]\d$",
- "filecount": "4",
- "filesize": 1488978,
- "gid": 1200119,
- "height": int,
- "image_token": "re:[0-9a-f]{10}",
- "lang": "ja",
- "language": "Japanese",
- "parent": "",
- "rating": r"re:\d\.\d+",
- "size": int,
- "tags": [
- "parody:komi-san wa komyushou desu.",
- "character:shouko komi",
- "group:seventh lowlife",
- "other:sample",
- ],
- "thumb": "https://exhentai.org/t/ce/0a/ce0a5bcb583229a9b07c0f8"
- "3bcb1630ab1350640-624622-736-1036-jpg_250.jpg",
- "title": "C93 [Seventh_Lowlife] Komi-san ha Tokidoki Daitan de"
- "su (Komi-san wa Komyushou desu) [Sample]",
- "title_jpn": "(C93) [Comiketjack (わ!)] 古見さんは、時々大胆"
- "です。 (古見さんは、コミュ症です。) [見本]",
- "token": "d55c44d3d0",
- "torrentcount": "0",
- "uploader": "klorpa",
- "width": int,
- },
- "content": ("2c68cff8a7ca540a78c36fdbf5fbae0260484f87",
- "e9891a4c017ed0bb734cd1efba5cd03f594d31ff"),
- }),
- ("https://exhentai.org/g/960461/4f0e369d82/", {
- "exception": exception.NotFoundError,
- }),
- ("http://exhentai.org/g/962698/7f02358e00/", {
- "exception": exception.AuthorizationError,
- }),
- ("https://exhentai.org/s/f68367b4c8/1200119-3", {
- "options": (("original", False),),
- "count": 2,
- }),
- ("https://e-hentai.org/s/f68367b4c8/1200119-3", {
- "options": (("original", False),),
- "count": 2,
- }),
- ("https://g.e-hentai.org/g/1200119/d55c44d3d0/"),
- )
+ example = "https://e-hentai.org/g/12345/67890abcde/"
def __init__(self, match):
ExhentaiExtractor.__init__(self, match)
@@ -171,10 +119,25 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
self.image_token = match.group(4)
self.image_num = text.parse_int(match.group(6), 1)
+ def _init(self):
source = self.config("source")
if source == "hitomi":
self.items = self._items_hitomi
+ def favorite(self, slot="0"):
+ url = self.root + "/gallerypopups.php"
+ params = {
+ "gid": self.gallery_id,
+ "t" : self.gallery_token,
+ "act": "addfav",
+ }
+ data = {
+ "favcat" : slot,
+ "apply" : "Apply Changes",
+ "update" : "1",
+ }
+ self.request(url, method="POST", params=params, data=data)
+
def items(self):
self.login()
@@ -219,6 +182,10 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
data["_http_validate"] = None
yield Message.Url, url, data
+ fav = self.config("fav")
+ if fav is not None:
+ self.favorite(fav)
+
def _items_hitomi(self):
if self.config("metadata", False):
data = self.metadata_from_api()
@@ -390,8 +357,9 @@ class ExhentaiGalleryExtractor(ExhentaiExtractor):
url = "https://e-hentai.org/home.php"
cookies = {
cookie.name: cookie.value
- for cookie in self.session.cookies
- if cookie.domain == self.cookiedomain and cookie.name != "igneous"
+ for cookie in self.cookies
+ if cookie.domain == self.cookies_domain and
+ cookie.name != "igneous"
}
page = self.request(url, cookies=cookies).text
@@ -458,26 +426,10 @@ class ExhentaiSearchExtractor(ExhentaiExtractor):
"""Extractor for exhentai search results"""
subcategory = "search"
pattern = BASE_PATTERN + r"/(?:\?([^#]*)|tag/([^/?#]+))"
- test = (
- ("https://e-hentai.org/?f_search=touhou"),
- ("https://exhentai.org/?f_cats=767&f_search=touhou"),
- ("https://exhentai.org/tag/parody:touhou+project"),
- (("https://exhentai.org/?f_doujinshi=0&f_manga=0&f_artistcg=0"
- "&f_gamecg=0&f_western=0&f_non-h=1&f_imageset=0&f_cosplay=0"
- "&f_asianporn=0&f_misc=0&f_search=touhou&f_apply=Apply+Filter"), {
- "pattern": ExhentaiGalleryExtractor.pattern,
- "range": "1-30",
- "count": 30,
- "keyword": {
- "gallery_id": int,
- "gallery_token": r"re:^[0-9a-f]{10}$"
- },
- }),
- )
+ example = "https://e-hentai.org/?f_search=QUERY"
def __init__(self, match):
ExhentaiExtractor.__init__(self, match)
- self.search_url = self.root
_, query, tag = match.groups()
if tag:
@@ -492,6 +444,9 @@ class ExhentaiSearchExtractor(ExhentaiExtractor):
if "next" not in self.params:
self.params["page"] = text.parse_int(self.params.get("page"))
+ def _init(self):
+ self.search_url = self.root
+
def items(self):
self.login()
data = {"_extractor": ExhentaiGalleryExtractor}
@@ -528,15 +483,7 @@ class ExhentaiFavoriteExtractor(ExhentaiSearchExtractor):
"""Extractor for favorited exhentai galleries"""
subcategory = "favorite"
pattern = BASE_PATTERN + r"/favorites\.php(?:\?([^#]*)())?"
- test = (
- ("https://e-hentai.org/favorites.php", {
- "count": 1,
- "pattern": r"https?://e-hentai\.org/g/1200119/d55c44d3d0"
- }),
- ("https://exhentai.org/favorites.php?favcat=1&f_search=touhou"
- "&f_apply=Search+Favorites"),
- )
+ example = "https://e-hentai.org/favorites.php"
- def __init__(self, match):
- ExhentaiSearchExtractor.__init__(self, match)
+ def _init(self):
self.search_url = self.root + "/favorites.php"