aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/nijie.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/extractor/nijie.py')
-rw-r--r--gallery_dl/extractor/nijie.py47
1 files changed, 17 insertions, 30 deletions
diff --git a/gallery_dl/extractor/nijie.py b/gallery_dl/extractor/nijie.py
index b01c591..c6df835 100644
--- a/gallery_dl/extractor/nijie.py
+++ b/gallery_dl/extractor/nijie.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright 2015-2023 Mike Fährmann
+# Copyright 2015-2025 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -8,7 +8,7 @@
"""Extractors for nijie instances"""
-from .common import BaseExtractor, Message, AsynchronousMixin
+from .common import BaseExtractor, Message, Dispatch, AsynchronousMixin
from .. import text, exception
from ..cache import cache
@@ -23,7 +23,7 @@ class NijieExtractor(AsynchronousMixin, BaseExtractor):
def __init__(self, match):
BaseExtractor.__init__(self, match)
- self.user_id = text.parse_int(match.group(match.lastindex))
+ self.user_id = text.parse_int(self.groups[-1])
def initialize(self):
self.cookies_domain = "." + self.root.rpartition("/")[2]
@@ -40,7 +40,7 @@ class NijieExtractor(AsynchronousMixin, BaseExtractor):
for image_id in self.image_ids():
- url = "{}/view.php?id={}".format(self.root, image_id)
+ url = f"{self.root}/view.php?id={image_id}"
response = self.request(url, fatal=False)
if response.status_code >= 400:
continue
@@ -73,8 +73,7 @@ class NijieExtractor(AsynchronousMixin, BaseExtractor):
def image_ids(self):
"""Collect all relevant image-ids"""
- @staticmethod
- def _extract_data(page):
+ def _extract_data(self, page):
"""Extract image metadata from 'page'"""
extr = text.extract_from(page)
keywords = text.unescape(extr(
@@ -90,8 +89,7 @@ class NijieExtractor(AsynchronousMixin, BaseExtractor):
"tags" : keywords[2:-1],
}
- @staticmethod
- def _extract_data_horne(page):
+ def _extract_data_horne(self, page):
"""Extract image metadata from 'page'"""
extr = text.extract_from(page)
keywords = text.unescape(extr(
@@ -111,20 +109,20 @@ class NijieExtractor(AsynchronousMixin, BaseExtractor):
def _extract_images(self, image_id, page):
if '&#diff_1" ' in page:
# multiple images
- url = "{}/view_popup.php?id={}".format(self.root, image_id)
+ url = f"{self.root}/view_popup.php?id={image_id}"
page = self.request(url).text
return [
text.extr(media, ' src="', '"')
for media in text.extract_iter(
page, 'href="javascript:void(0);"><', '>')
+ if ' src="' in media
]
else:
pos = page.find('id="view-center"') + 1
# do NOT use text.extr() here, as it doesn't support a pos argument
return (text.extract(page, 'itemprop="image" src="', '"', pos)[0],)
- @staticmethod
- def _extract_user_name(page):
+ def _extract_user_name(self, page):
return text.unescape(text.extr(page, "<br />", "<"))
def login(self):
@@ -141,7 +139,7 @@ class NijieExtractor(AsynchronousMixin, BaseExtractor):
def _login_impl(self, username, password):
self.log.info("Logging in as %s", username)
- url = "{}/login_int.php".format(self.root)
+ url = f"{self.root}/login_int.php"
data = {"email": username, "password": password, "save": "on"}
response = self.request(url, method="POST", data=data)
@@ -150,7 +148,7 @@ class NijieExtractor(AsynchronousMixin, BaseExtractor):
return self.cookies
def _pagination(self, path):
- url = "{}/{}.php".format(self.root, path)
+ url = f"{self.root}/{path}.php"
params = {"id": self.user_id, "p": 1}
while True:
@@ -177,18 +175,13 @@ BASE_PATTERN = NijieExtractor.update({
})
-class NijieUserExtractor(NijieExtractor):
+class NijieUserExtractor(Dispatch, NijieExtractor):
"""Extractor for nijie user profiles"""
- subcategory = "user"
- cookies_domain = None
pattern = BASE_PATTERN + r"/members\.php\?id=(\d+)"
example = "https://nijie.info/members.php?id=12345"
- def initialize(self):
- pass
-
def items(self):
- fmt = "{}/{{}}.php?id={}".format(self.root, self.user_id).format
+ fmt = f"{self.root}/{{}}.php?id={self.user_id}".format
return self._dispatch_extractors((
(NijieIllustrationExtractor, fmt("members_illust")),
(NijieDoujinExtractor , fmt("members_dojin")),
@@ -252,8 +245,7 @@ class NijieNuitaExtractor(NijieExtractor):
data["user_name"] = self.user_name
return data
- @staticmethod
- def _extract_user_name(page):
+ def _extract_user_name(self, page):
return text.unescape(text.extr(page, "<title>", "さんの抜いた"))
@@ -266,8 +258,7 @@ class NijieFeedExtractor(NijieExtractor):
def image_ids(self):
return self._pagination("like_user_view")
- @staticmethod
- def _extract_user_name(page):
+ def _extract_user_name(self, page):
return ""
@@ -289,7 +280,7 @@ class NijieFollowedExtractor(NijieExtractor):
for user_id in text.extract_iter(
page, '"><a href="/members.php?id=', '"'):
- user_url = "{}/members.php?id={}".format(self.root, user_id)
+ user_url = f"{self.root}/members.php?id={user_id}"
yield Message.Queue, user_url, data
if '<a rel="next"' not in page:
@@ -303,9 +294,5 @@ class NijieImageExtractor(NijieExtractor):
pattern = BASE_PATTERN + r"/view(?:_popup)?\.php\?id=(\d+)"
example = "https://nijie.info/view.php?id=12345"
- def __init__(self, match):
- NijieExtractor.__init__(self, match)
- self.image_id = match.group(match.lastindex)
-
def image_ids(self):
- return (self.image_id,)
+ return (self.groups[-1],)