2015-05-04 20:40:53 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2022-04-18 17:24:00 +02:00
|
|
|
# Copyright 2015-2022 Mike Fährmann
|
2015-05-04 20:40:53 +02:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
|
2022-04-18 17:24:00 +02:00
|
|
|
"""Extractors for https://nijie.info/"""
|
2015-05-04 20:40:53 +02:00
|
|
|
|
2019-02-04 14:21:19 +01:00
|
|
|
from .common import Extractor, Message, AsynchronousMixin
|
2018-04-20 14:53:21 +02:00
|
|
|
from .. import text, exception
|
2016-03-06 21:07:00 +01:00
|
|
|
from ..cache import cache
|
2015-05-04 20:40:53 +02:00
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2019-09-26 21:38:55 +02:00
|
|
|
BASE_PATTERN = r"(?:https?://)?(?:www\.)?nijie\.info"
|
|
|
|
|
|
|
|
|
2019-02-04 14:21:19 +01:00
|
|
|
class NijieExtractor(AsynchronousMixin, Extractor):
|
2016-09-19 08:51:49 +02:00
|
|
|
"""Base class for nijie extractors"""
|
2015-11-21 04:26:30 +01:00
|
|
|
category = "nijie"
|
2019-02-08 13:45:40 +01:00
|
|
|
directory_fmt = ("{category}", "{user_id}")
|
2019-11-04 20:47:38 +01:00
|
|
|
filename_fmt = "{image_id}_p{num}.{extension}"
|
2019-09-26 21:38:55 +02:00
|
|
|
archive_fmt = "{image_id}_{num}"
|
2017-07-22 15:43:35 +02:00
|
|
|
cookiedomain = "nijie.info"
|
2019-01-30 17:09:32 +01:00
|
|
|
cookienames = ("nemail", "nlogin")
|
2018-03-31 18:48:41 +02:00
|
|
|
root = "https://nijie.info"
|
2018-07-10 11:30:17 +02:00
|
|
|
view_url = "https://nijie.info/view.php?id="
|
2015-05-04 20:40:53 +02:00
|
|
|
popup_url = "https://nijie.info/view_popup.php?id="
|
|
|
|
|
2019-02-11 13:31:10 +01:00
|
|
|
def __init__(self, match):
|
|
|
|
Extractor.__init__(self, match)
|
2019-09-27 23:14:32 +02:00
|
|
|
self.user_id = text.parse_int(match.group(1))
|
|
|
|
self.user_name = None
|
2018-03-31 18:48:41 +02:00
|
|
|
self.session.headers["Referer"] = self.root + "/"
|
2015-05-04 20:40:53 +02:00
|
|
|
|
|
|
|
def items(self):
|
2017-01-08 17:33:25 +01:00
|
|
|
self.login()
|
2018-03-31 18:48:41 +02:00
|
|
|
|
2019-09-26 21:38:55 +02:00
|
|
|
for image_id in self.image_ids():
|
|
|
|
|
|
|
|
response = self.request(self.view_url + image_id, fatal=False)
|
|
|
|
if response.status_code >= 400:
|
|
|
|
continue
|
|
|
|
page = response.text
|
2015-05-04 20:40:53 +02:00
|
|
|
|
2019-09-26 21:38:55 +02:00
|
|
|
data = self._extract_data(page)
|
|
|
|
data["image_id"] = text.parse_int(image_id)
|
|
|
|
yield Message.Directory, data
|
|
|
|
|
|
|
|
for image in self._extract_images(page):
|
|
|
|
image.update(data)
|
|
|
|
if not image["extension"]:
|
|
|
|
image["extension"] = "jpg"
|
|
|
|
yield Message.Url, image["url"], image
|
|
|
|
|
|
|
|
def image_ids(self):
|
2018-03-31 18:48:41 +02:00
|
|
|
"""Collect all relevant image-ids"""
|
2019-09-26 21:38:55 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _extract_data(page):
|
|
|
|
"""Extract image metadata from 'page'"""
|
|
|
|
extr = text.extract_from(page)
|
|
|
|
keywords = text.unescape(extr(
|
2019-09-27 23:14:32 +02:00
|
|
|
'name="keywords" content="', '" />')).split(",")
|
|
|
|
data = {
|
2019-09-26 21:38:55 +02:00
|
|
|
"title" : keywords[0].strip(),
|
|
|
|
"description": text.unescape(extr(
|
2019-09-27 23:14:32 +02:00
|
|
|
'"description": "', '"').replace("&", "&")),
|
2019-09-26 21:38:55 +02:00
|
|
|
"date" : text.parse_datetime(extr(
|
2019-11-30 23:08:21 +01:00
|
|
|
'"datePublished": "', '"') + "+0900",
|
|
|
|
"%a %b %d %H:%M:%S %Y%z"),
|
2019-09-26 21:38:55 +02:00
|
|
|
"artist_id" : text.parse_int(extr(
|
|
|
|
'"sameAs": "https://nijie.info/members.php?id=', '"')),
|
|
|
|
"artist_name": keywords[1],
|
|
|
|
"tags" : keywords[2:-1],
|
|
|
|
}
|
2019-09-27 23:14:32 +02:00
|
|
|
data["user_id"] = data["artist_id"]
|
|
|
|
data["user_name"] = data["artist_name"]
|
|
|
|
return data
|
2019-09-26 21:38:55 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _extract_images(page):
|
|
|
|
"""Extract image URLs from 'page'"""
|
|
|
|
images = text.extract_iter(page, '<a href="./view_popup.php', '</a>')
|
|
|
|
for num, image in enumerate(images):
|
2018-07-10 11:30:17 +02:00
|
|
|
url = "https:" + text.extract(image, 'src="', '"')[0]
|
2019-09-26 21:38:55 +02:00
|
|
|
url = url.replace("/__rs_l120x120/", "/")
|
|
|
|
yield text.nameext_from_url(url, {
|
|
|
|
"num": num,
|
|
|
|
"url": url,
|
2015-11-16 17:32:26 +01:00
|
|
|
})
|
2015-12-11 00:07:21 +01:00
|
|
|
|
2022-05-01 17:45:38 +02:00
|
|
|
@staticmethod
|
|
|
|
def _extract_user_name(page):
|
|
|
|
return text.unescape(text.extract(page, "<br />", "<")[0] or "")
|
|
|
|
|
2017-01-08 17:33:25 +01:00
|
|
|
def login(self):
|
2019-01-30 17:09:32 +01:00
|
|
|
"""Login and obtain session cookies"""
|
|
|
|
if not self._check_cookies(self.cookienames):
|
2017-07-25 14:59:41 +02:00
|
|
|
username, password = self._get_auth_info()
|
2019-01-30 17:09:32 +01:00
|
|
|
self._update_cookies(self._login_impl(username, password))
|
2017-01-08 17:33:25 +01:00
|
|
|
|
2019-03-14 22:21:49 +01:00
|
|
|
@cache(maxage=150*24*3600, keyarg=1)
|
2017-01-08 17:33:25 +01:00
|
|
|
def _login_impl(self, username, password):
|
2020-12-22 14:40:18 +01:00
|
|
|
if not username or not password:
|
|
|
|
raise exception.AuthenticationError(
|
|
|
|
"Username and password required")
|
|
|
|
|
2017-03-17 09:42:59 +01:00
|
|
|
self.log.info("Logging in as %s", username)
|
2019-01-30 17:09:32 +01:00
|
|
|
url = "{}/login_int.php".format(self.root)
|
|
|
|
data = {"email": username, "password": password, "save": "on"}
|
|
|
|
|
|
|
|
response = self.request(url, method="POST", data=data)
|
|
|
|
if "//nijie.info/login.php" in response.text:
|
2016-07-20 14:21:13 +02:00
|
|
|
raise exception.AuthenticationError()
|
2016-03-06 21:07:00 +01:00
|
|
|
return self.session.cookies
|
2016-09-19 08:51:49 +02:00
|
|
|
|
2018-03-31 16:20:08 +02:00
|
|
|
def _pagination(self, path):
|
2018-03-31 18:48:41 +02:00
|
|
|
url = "{}/{}.php".format(self.root, path)
|
|
|
|
params = {"id": self.user_id, "p": 1}
|
|
|
|
|
2018-03-31 16:20:08 +02:00
|
|
|
while True:
|
2019-07-04 23:45:26 +02:00
|
|
|
page = self.request(url, params=params, notfound="artist").text
|
2019-09-27 23:14:32 +02:00
|
|
|
|
2022-05-01 17:45:38 +02:00
|
|
|
if self.user_name is None:
|
|
|
|
self.user_name = self._extract_user_name(page)
|
2019-07-04 23:45:26 +02:00
|
|
|
yield from text.extract_iter(page, 'illust_id="', '"')
|
2018-03-31 18:48:41 +02:00
|
|
|
|
|
|
|
if '<a rel="next"' not in page:
|
2018-03-31 16:20:08 +02:00
|
|
|
return
|
|
|
|
params["p"] += 1
|
|
|
|
|
2016-09-19 08:51:49 +02:00
|
|
|
|
|
|
|
class NijieUserExtractor(NijieExtractor):
|
2020-09-24 23:26:33 +02:00
|
|
|
"""Extractor for nijie user profiles"""
|
2016-09-19 08:51:49 +02:00
|
|
|
subcategory = "user"
|
2020-09-24 23:26:33 +02:00
|
|
|
cookiedomain = None
|
|
|
|
pattern = BASE_PATTERN + r"/members\.php\?id=(\d+)"
|
|
|
|
test = ("https://nijie.info/members.php?id=44",)
|
|
|
|
|
|
|
|
def items(self):
|
2022-05-01 17:45:38 +02:00
|
|
|
fmt = "{}/{{}}.php?id={}".format(self.root, self.user_id).format
|
2020-09-24 23:26:33 +02:00
|
|
|
return self._dispatch_extractors((
|
2022-05-01 17:45:38 +02:00
|
|
|
(NijieIllustrationExtractor, fmt("members_illust")),
|
|
|
|
(NijieDoujinExtractor , fmt("members_dojin")),
|
|
|
|
(NijieFavoriteExtractor , fmt("user_like_illust_view")),
|
|
|
|
(NijieNuitaExtractor , fmt("history_nuita")),
|
2020-09-24 23:26:33 +02:00
|
|
|
), ("illustration", "doujin"))
|
|
|
|
|
|
|
|
|
|
|
|
class NijieIllustrationExtractor(NijieExtractor):
|
|
|
|
"""Extractor for all illustrations of a nijie-user"""
|
|
|
|
subcategory = "illustration"
|
|
|
|
pattern = BASE_PATTERN + r"/members_illust\.php\?id=(\d+)"
|
2019-02-08 13:45:40 +01:00
|
|
|
test = (
|
2016-12-30 01:46:42 +01:00
|
|
|
("https://nijie.info/members_illust.php?id=44", {
|
2022-04-18 17:24:00 +02:00
|
|
|
"url": "1553e5144df50a676f5947d02469299b401ad6c0",
|
2019-09-26 21:38:55 +02:00
|
|
|
"keyword": {
|
|
|
|
"artist_id": 44,
|
|
|
|
"artist_name": "ED",
|
|
|
|
"date": "type:datetime",
|
|
|
|
"description": str,
|
|
|
|
"extension": "jpg",
|
|
|
|
"filename": str,
|
|
|
|
"image_id": int,
|
|
|
|
"num": int,
|
|
|
|
"tags": list,
|
|
|
|
"title": str,
|
2022-04-18 17:24:00 +02:00
|
|
|
"url": r"re:https://pic.nijie.net/\d+/nijie/.*jpg$",
|
2019-09-26 21:38:55 +02:00
|
|
|
"user_id": 44,
|
2019-09-27 23:14:32 +02:00
|
|
|
"user_name": "ED",
|
2019-09-26 21:38:55 +02:00
|
|
|
},
|
2016-12-30 01:46:42 +01:00
|
|
|
}),
|
|
|
|
("https://nijie.info/members_illust.php?id=43", {
|
|
|
|
"exception": exception.NotFoundError,
|
|
|
|
}),
|
2019-02-08 13:45:40 +01:00
|
|
|
)
|
2016-09-19 08:51:49 +02:00
|
|
|
|
2019-09-26 21:38:55 +02:00
|
|
|
def image_ids(self):
|
2018-03-31 18:48:41 +02:00
|
|
|
return self._pagination("members_illust")
|
2018-03-31 16:20:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
class NijieDoujinExtractor(NijieExtractor):
|
|
|
|
"""Extractor for doujin entries of a nijie-user"""
|
|
|
|
subcategory = "doujin"
|
2019-09-26 21:38:55 +02:00
|
|
|
pattern = BASE_PATTERN + r"/members_dojin\.php\?id=(\d+)"
|
2019-02-08 13:45:40 +01:00
|
|
|
test = ("https://nijie.info/members_dojin.php?id=6782", {
|
|
|
|
"count": ">= 18",
|
2019-09-27 23:14:32 +02:00
|
|
|
"keyword": {
|
|
|
|
"user_id" : 6782,
|
|
|
|
"user_name": "ジョニー@アビオン村",
|
|
|
|
},
|
2019-02-08 13:45:40 +01:00
|
|
|
})
|
2016-09-19 08:51:49 +02:00
|
|
|
|
2019-09-26 21:38:55 +02:00
|
|
|
def image_ids(self):
|
2018-03-31 18:48:41 +02:00
|
|
|
return self._pagination("members_dojin")
|
2016-09-19 08:51:49 +02:00
|
|
|
|
|
|
|
|
2018-03-31 18:54:25 +02:00
|
|
|
class NijieFavoriteExtractor(NijieExtractor):
|
|
|
|
"""Extractor for all favorites/bookmarks of a nijie-user"""
|
|
|
|
subcategory = "favorite"
|
2019-02-08 13:45:40 +01:00
|
|
|
directory_fmt = ("{category}", "bookmarks", "{user_id}")
|
2019-09-26 21:38:55 +02:00
|
|
|
archive_fmt = "f_{user_id}_{image_id}_{num}"
|
|
|
|
pattern = BASE_PATTERN + r"/user_like_illust_view\.php\?id=(\d+)"
|
2019-02-08 13:45:40 +01:00
|
|
|
test = ("https://nijie.info/user_like_illust_view.php?id=44", {
|
|
|
|
"count": ">= 16",
|
2019-09-27 23:14:32 +02:00
|
|
|
"keyword": {
|
|
|
|
"user_id" : 44,
|
|
|
|
"user_name": "ED",
|
|
|
|
},
|
2019-02-08 13:45:40 +01:00
|
|
|
})
|
2018-03-31 18:54:25 +02:00
|
|
|
|
2019-09-26 21:38:55 +02:00
|
|
|
def image_ids(self):
|
2018-03-31 18:54:25 +02:00
|
|
|
return self._pagination("user_like_illust_view")
|
|
|
|
|
2019-09-27 23:14:32 +02:00
|
|
|
def _extract_data(self, page):
|
|
|
|
data = NijieExtractor._extract_data(page)
|
|
|
|
data["user_id"] = self.user_id
|
|
|
|
data["user_name"] = self.user_name
|
|
|
|
return data
|
|
|
|
|
2018-03-31 18:54:25 +02:00
|
|
|
|
2022-05-01 17:45:38 +02:00
|
|
|
class NijieNuitaExtractor(NijieExtractor):
|
|
|
|
"""Extractor for a nijie user's 抜いた list"""
|
|
|
|
subcategory = "nuita"
|
|
|
|
directory_fmt = ("{category}", "nuita", "{user_id}")
|
|
|
|
archive_fmt = "n_{user_id}_{image_id}_{num}"
|
|
|
|
pattern = BASE_PATTERN + r"/history_nuita\.php\?id=(\d+)"
|
|
|
|
test = ("https://nijie.info/history_nuita.php?id=728995", {
|
|
|
|
"range": "1-10",
|
|
|
|
"count": 10,
|
|
|
|
"keyword": {
|
|
|
|
"user_id" : 728995,
|
|
|
|
"user_name": "莚",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
def image_ids(self):
|
|
|
|
return self._pagination("history_nuita")
|
|
|
|
|
|
|
|
def _extract_data(self, page):
|
|
|
|
data = NijieExtractor._extract_data(page)
|
|
|
|
data["user_id"] = self.user_id
|
|
|
|
data["user_name"] = self.user_name
|
|
|
|
return data
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _extract_user_name(page):
|
|
|
|
return text.unescape(text.extract(
|
|
|
|
page, "<title>", "さんの抜いた")[0] or "")
|
|
|
|
|
|
|
|
|
2016-09-19 08:51:49 +02:00
|
|
|
class NijieImageExtractor(NijieExtractor):
|
|
|
|
"""Extractor for a work/image from nijie.info"""
|
|
|
|
subcategory = "image"
|
2019-09-26 21:38:55 +02:00
|
|
|
pattern = BASE_PATTERN + r"/view(?:_popup)?\.php\?id=(\d+)"
|
2019-02-08 13:45:40 +01:00
|
|
|
test = (
|
2016-12-30 01:46:42 +01:00
|
|
|
("https://nijie.info/view.php?id=70720", {
|
2022-04-18 17:24:00 +02:00
|
|
|
"url": "3d654e890212ba823c9647754767336aebc0a743",
|
|
|
|
"keyword": "41da5d0e178b04f01fe72460185df52fadc3c91b",
|
2016-12-30 01:46:42 +01:00
|
|
|
"content": "d85e3ea896ed5e4da0bca2390ad310a4df716ca6",
|
|
|
|
}),
|
|
|
|
("https://nijie.info/view.php?id=70724", {
|
2019-09-26 21:38:55 +02:00
|
|
|
"count": 0,
|
2016-12-30 01:46:42 +01:00
|
|
|
}),
|
2019-02-08 13:45:40 +01:00
|
|
|
("https://nijie.info/view_popup.php?id=70720"),
|
|
|
|
)
|
2016-09-19 08:51:49 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
NijieExtractor.__init__(self, match)
|
2016-09-19 08:51:49 +02:00
|
|
|
self.image_id = match.group(1)
|
|
|
|
|
2019-09-26 21:38:55 +02:00
|
|
|
def image_ids(self):
|
2016-09-19 08:51:49 +02:00
|
|
|
return (self.image_id,)
|