2015-04-10 15:29:09 +02:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
2022-04-29 16:29:12 +02:00
|
|
|
|
# Copyright 2014-2022 Mike Fährmann
|
2015-04-10 15:29:09 +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.
|
|
|
|
|
|
2021-07-07 02:22:44 +02:00
|
|
|
|
"""Extractors for https://www.pixiv.net/"""
|
2015-04-10 15:29:09 +02:00
|
|
|
|
|
2015-10-05 17:15:31 +02:00
|
|
|
|
from .common import Extractor, Message
|
2021-07-07 02:22:44 +02:00
|
|
|
|
from .. import text, util, exception
|
2022-04-29 16:29:12 +02:00
|
|
|
|
from ..cache import cache, memcache
|
2018-05-13 22:24:21 +02:00
|
|
|
|
from datetime import datetime, timedelta
|
2020-03-09 21:17:16 +01:00
|
|
|
|
import itertools
|
2019-09-02 22:34:04 +02:00
|
|
|
|
import hashlib
|
2014-10-12 21:56:44 +02:00
|
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
|
2017-06-04 16:33:36 +02:00
|
|
|
|
class PixivExtractor(Extractor):
|
|
|
|
|
"""Base class for pixiv extractors"""
|
2015-11-21 04:26:30 +01:00
|
|
|
|
category = "pixiv"
|
2022-05-01 21:12:23 +02:00
|
|
|
|
root = "https://www.pixiv.net"
|
2019-02-08 13:45:40 +01:00
|
|
|
|
directory_fmt = ("{category}", "{user[id]} {user[account]}")
|
2019-08-15 13:32:47 +02:00
|
|
|
|
filename_fmt = "{id}_p{num}.{extension}"
|
2019-08-04 22:35:56 +02:00
|
|
|
|
archive_fmt = "{id}{suffix}.{extension}"
|
2020-01-01 16:07:23 +01:00
|
|
|
|
cookiedomain = None
|
2014-10-12 21:56:44 +02:00
|
|
|
|
|
2019-02-11 13:31:10 +01:00
|
|
|
|
def __init__(self, match):
|
|
|
|
|
Extractor.__init__(self, match)
|
2018-05-13 22:24:21 +02:00
|
|
|
|
self.api = PixivAppAPI(self)
|
2017-04-25 17:12:48 +02:00
|
|
|
|
self.load_ugoira = self.config("ugoira", True)
|
2021-05-24 17:49:46 +02:00
|
|
|
|
self.max_posts = self.config("max-posts", 0)
|
2014-10-12 21:56:44 +02:00
|
|
|
|
|
2015-04-10 15:29:09 +02:00
|
|
|
|
def items(self):
|
2021-04-27 23:51:37 +02:00
|
|
|
|
tags = self.config("tags", "japanese")
|
2021-05-07 20:41:54 +02:00
|
|
|
|
if tags == "original":
|
2021-04-27 23:51:37 +02:00
|
|
|
|
transform_tags = None
|
|
|
|
|
elif tags == "translated":
|
|
|
|
|
def transform_tags(work):
|
2022-11-22 19:11:37 +01:00
|
|
|
|
work["tags"] = list(dict.fromkeys(
|
2021-04-27 23:51:37 +02:00
|
|
|
|
tag["translated_name"] or tag["name"]
|
|
|
|
|
for tag in work["tags"]))
|
|
|
|
|
else:
|
|
|
|
|
def transform_tags(work):
|
|
|
|
|
work["tags"] = [tag["name"] for tag in work["tags"]]
|
|
|
|
|
|
2020-02-01 01:36:06 +01:00
|
|
|
|
ratings = {0: "General", 1: "R-18", 2: "R-18G"}
|
2022-10-16 15:32:31 +02:00
|
|
|
|
userdata = self.config("metadata")
|
2020-02-09 13:54:58 +01:00
|
|
|
|
metadata = self.metadata()
|
2015-05-14 19:08:20 +02:00
|
|
|
|
|
2021-05-24 17:49:46 +02:00
|
|
|
|
works = self.works()
|
|
|
|
|
if self.max_posts:
|
|
|
|
|
works = itertools.islice(works, self.max_posts)
|
|
|
|
|
for work in works:
|
2018-05-13 22:24:21 +02:00
|
|
|
|
if not work["user"]["id"]:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
meta_single_page = work["meta_single_page"]
|
|
|
|
|
meta_pages = work["meta_pages"]
|
|
|
|
|
del work["meta_single_page"]
|
|
|
|
|
del work["image_urls"]
|
|
|
|
|
del work["meta_pages"]
|
2021-04-27 23:51:37 +02:00
|
|
|
|
|
2022-10-16 15:32:31 +02:00
|
|
|
|
if userdata:
|
|
|
|
|
work.update(self.api.user_detail(work["user"]["id"]))
|
2021-04-27 23:51:37 +02:00
|
|
|
|
if transform_tags:
|
|
|
|
|
transform_tags(work)
|
2019-08-04 22:35:56 +02:00
|
|
|
|
work["num"] = 0
|
2019-05-09 21:53:17 +02:00
|
|
|
|
work["date"] = text.parse_datetime(work["create_date"])
|
2020-02-01 01:36:06 +01:00
|
|
|
|
work["rating"] = ratings.get(work["x_restrict"])
|
2019-08-04 22:35:56 +02:00
|
|
|
|
work["suffix"] = ""
|
2018-05-13 22:24:21 +02:00
|
|
|
|
work.update(metadata)
|
2017-06-04 16:33:36 +02:00
|
|
|
|
|
2018-12-11 20:37:47 +01:00
|
|
|
|
yield Message.Directory, work
|
|
|
|
|
|
2015-05-14 19:08:20 +02:00
|
|
|
|
if work["type"] == "ugoira":
|
2016-07-20 14:19:46 +02:00
|
|
|
|
if not self.load_ugoira:
|
|
|
|
|
continue
|
2022-05-08 20:05:38 +02:00
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
ugoira = self.api.ugoira_metadata(work["id"])
|
|
|
|
|
except exception.StopExtraction as exc:
|
|
|
|
|
self.log.warning(
|
|
|
|
|
"Unable to retrieve Ugoira metatdata (%s - %s)",
|
|
|
|
|
work.get("id"), exc.message)
|
|
|
|
|
continue
|
2018-05-13 22:24:21 +02:00
|
|
|
|
|
|
|
|
|
url = ugoira["zip_urls"]["medium"].replace(
|
|
|
|
|
"_ugoira600x600", "_ugoira1920x1080")
|
2018-06-18 17:25:52 +02:00
|
|
|
|
work["frames"] = ugoira["frames"]
|
2022-12-15 11:40:20 +01:00
|
|
|
|
work["date_url"] = self._date_from_url(url)
|
2021-04-27 00:48:53 +02:00
|
|
|
|
work["_http_adjust_extension"] = False
|
2019-08-04 22:35:56 +02:00
|
|
|
|
yield Message.Url, url, text.nameext_from_url(url, work)
|
2018-05-13 22:24:21 +02:00
|
|
|
|
|
2015-05-14 19:08:20 +02:00
|
|
|
|
elif work["page_count"] == 1:
|
2018-05-13 22:24:21 +02:00
|
|
|
|
url = meta_single_page["original_image_url"]
|
2022-12-15 11:40:20 +01:00
|
|
|
|
work["date_url"] = self._date_from_url(url)
|
2019-08-02 22:35:10 +02:00
|
|
|
|
yield Message.Url, url, text.nameext_from_url(url, work)
|
2014-10-12 21:56:44 +02:00
|
|
|
|
|
|
|
|
|
else:
|
2019-08-04 22:35:56 +02:00
|
|
|
|
for work["num"], img in enumerate(meta_pages):
|
2018-05-13 22:24:21 +02:00
|
|
|
|
url = img["image_urls"]["original"]
|
2022-12-15 11:40:20 +01:00
|
|
|
|
work["date_url"] = self._date_from_url(url)
|
2019-08-04 22:35:56 +02:00
|
|
|
|
work["suffix"] = "_p{:02}".format(work["num"])
|
2019-08-02 22:35:10 +02:00
|
|
|
|
yield Message.Url, url, text.nameext_from_url(url, work)
|
2015-05-14 19:08:20 +02:00
|
|
|
|
|
2022-12-15 11:40:20 +01:00
|
|
|
|
@staticmethod
|
|
|
|
|
def _date_from_url(url, offset=timedelta(hours=9)):
|
|
|
|
|
try:
|
|
|
|
|
_, _, _, _, _, y, m, d, H, M, S, _ = url.split("/")
|
|
|
|
|
return datetime(
|
|
|
|
|
int(y), int(m), int(d), int(H), int(M), int(S)) - offset
|
|
|
|
|
except Exception:
|
|
|
|
|
return None
|
|
|
|
|
|
2022-05-01 21:12:23 +02:00
|
|
|
|
@staticmethod
|
|
|
|
|
def _make_work(kind, url, user):
|
2022-05-03 16:11:49 +02:00
|
|
|
|
p = url.split("/")
|
2022-05-01 21:12:23 +02:00
|
|
|
|
return {
|
2022-05-03 16:11:49 +02:00
|
|
|
|
"create_date" : "{}-{}-{}T{}:{}:{}+09:00".format(
|
|
|
|
|
p[5], p[6], p[7], p[8], p[9], p[10]) if len(p) > 9 else None,
|
2022-05-01 21:12:23 +02:00
|
|
|
|
"height" : 0,
|
|
|
|
|
"id" : kind,
|
|
|
|
|
"image_urls" : None,
|
|
|
|
|
"meta_pages" : (),
|
|
|
|
|
"meta_single_page": {"original_image_url": url},
|
|
|
|
|
"page_count" : 1,
|
|
|
|
|
"sanity_level" : 0,
|
|
|
|
|
"tags" : (),
|
|
|
|
|
"title" : kind,
|
|
|
|
|
"type" : kind,
|
|
|
|
|
"user" : user,
|
|
|
|
|
"width" : 0,
|
|
|
|
|
"x_restrict" : 0,
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-04 16:33:36 +02:00
|
|
|
|
def works(self):
|
2022-05-01 21:12:23 +02:00
|
|
|
|
"""Return an iterable containing all relevant 'work' objects"""
|
2014-10-12 21:56:44 +02:00
|
|
|
|
|
2020-02-09 13:54:58 +01:00
|
|
|
|
def metadata(self):
|
2022-05-01 21:12:23 +02:00
|
|
|
|
"""Collect metadata for extractor job"""
|
2020-02-09 13:54:58 +01:00
|
|
|
|
return {}
|
2017-06-04 16:33:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PixivUserExtractor(PixivExtractor):
|
2022-05-01 21:12:23 +02:00
|
|
|
|
"""Extractor for a pixiv user profile"""
|
2017-06-04 16:33:36 +02:00
|
|
|
|
subcategory = "user"
|
2020-01-10 13:31:06 +01:00
|
|
|
|
pattern = (r"(?:https?://)?(?:www\.|touch\.)?pixiv\.net/(?:"
|
2022-05-01 21:12:23 +02:00
|
|
|
|
r"(?:en/)?u(?:sers)?/|member\.php\?id=|(?:mypage\.php)?#id="
|
|
|
|
|
r")(\d+)(?:$|[?#])")
|
|
|
|
|
test = (
|
|
|
|
|
("https://www.pixiv.net/en/users/173530"),
|
|
|
|
|
("https://www.pixiv.net/u/173530"),
|
|
|
|
|
("https://www.pixiv.net/member.php?id=173530"),
|
|
|
|
|
("https://www.pixiv.net/mypage.php#id=173530"),
|
|
|
|
|
("https://www.pixiv.net/#id=173530"),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
|
PixivExtractor.__init__(self, match)
|
|
|
|
|
self.user_id = match.group(1)
|
|
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
|
base = "{}/users/{}/".format(self.root, self.user_id)
|
|
|
|
|
return self._dispatch_extractors((
|
|
|
|
|
(PixivAvatarExtractor , base + "avatar"),
|
|
|
|
|
(PixivBackgroundExtractor, base + "background"),
|
|
|
|
|
(PixivArtworksExtractor , base + "artworks"),
|
|
|
|
|
(PixivFavoriteExtractor , base + "bookmarks/artworks"),
|
2022-05-03 16:11:49 +02:00
|
|
|
|
), ("artworks",))
|
2022-05-01 21:12:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PixivArtworksExtractor(PixivExtractor):
|
|
|
|
|
"""Extractor for artworks of a pixiv user"""
|
|
|
|
|
subcategory = "artworks"
|
|
|
|
|
pattern = (r"(?:https?://)?(?:www\.|touch\.)?pixiv\.net/(?:"
|
|
|
|
|
r"(?:en/)?users/(\d+)/(?:artworks|illustrations|manga)"
|
|
|
|
|
r"(?:/([^/?#]+))?/?(?:$|[?#])"
|
|
|
|
|
r"|member_illust\.php\?id=(\d+)(?:&([^#]+))?)")
|
2019-02-08 13:45:40 +01:00
|
|
|
|
test = (
|
2020-01-10 13:31:06 +01:00
|
|
|
|
("https://www.pixiv.net/en/users/173530/artworks", {
|
2017-06-04 16:33:36 +02:00
|
|
|
|
"url": "852c31ad83b6840bacbce824d85f2a997889efb7",
|
|
|
|
|
}),
|
2018-05-18 16:55:24 +02:00
|
|
|
|
# illusts with specific tag
|
2020-01-10 13:31:06 +01:00
|
|
|
|
(("https://www.pixiv.net/en/users/173530/artworks"
|
|
|
|
|
"/%E6%89%8B%E3%81%B6%E3%82%8D"), {
|
|
|
|
|
"url": "25b1cd81153a8ff82eec440dd9f20a4a22079658",
|
|
|
|
|
}),
|
2017-07-12 08:21:29 +02:00
|
|
|
|
(("https://www.pixiv.net/member_illust.php?id=173530"
|
|
|
|
|
"&tag=%E6%89%8B%E3%81%B6%E3%82%8D"), {
|
|
|
|
|
"url": "25b1cd81153a8ff82eec440dd9f20a4a22079658",
|
2017-06-04 16:33:36 +02:00
|
|
|
|
}),
|
2020-03-09 21:17:16 +01:00
|
|
|
|
# deleted account
|
2017-06-04 16:33:36 +02:00
|
|
|
|
("http://www.pixiv.net/member_illust.php?id=173531", {
|
2021-05-14 20:30:28 +02:00
|
|
|
|
"options": (("metadata", True),),
|
|
|
|
|
"exception": exception.NotFoundError,
|
2017-06-04 16:33:36 +02:00
|
|
|
|
}),
|
2020-01-10 13:31:06 +01:00
|
|
|
|
("https://www.pixiv.net/en/users/173530/manga"),
|
|
|
|
|
("https://www.pixiv.net/en/users/173530/illustrations"),
|
|
|
|
|
("https://www.pixiv.net/member_illust.php?id=173530"),
|
2019-02-08 13:45:40 +01:00
|
|
|
|
("https://touch.pixiv.net/member_illust.php?id=173530"),
|
|
|
|
|
)
|
2015-04-10 15:29:09 +02:00
|
|
|
|
|
2017-06-04 16:33:36 +02:00
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
|
PixivExtractor.__init__(self, match)
|
2022-05-01 21:12:23 +02:00
|
|
|
|
u1, t1, u2, t2 = match.groups()
|
2020-01-10 13:31:06 +01:00
|
|
|
|
if t1:
|
|
|
|
|
t1 = text.unquote(t1)
|
|
|
|
|
elif t2:
|
|
|
|
|
t2 = text.parse_query(t2).get("tag")
|
2022-05-01 21:12:23 +02:00
|
|
|
|
self.user_id = u1 or u2
|
2020-01-10 13:31:06 +01:00
|
|
|
|
self.tag = t1 or t2
|
2017-06-04 16:33:36 +02:00
|
|
|
|
|
2021-05-14 20:30:28 +02:00
|
|
|
|
def metadata(self):
|
|
|
|
|
if self.config("metadata"):
|
2022-10-16 15:32:31 +02:00
|
|
|
|
self.api.user_detail(self.user_id)
|
2021-05-14 20:30:28 +02:00
|
|
|
|
return {}
|
|
|
|
|
|
2017-06-04 16:33:36 +02:00
|
|
|
|
def works(self):
|
2018-05-18 15:30:06 +02:00
|
|
|
|
works = self.api.user_illusts(self.user_id)
|
|
|
|
|
|
2020-01-10 13:31:06 +01:00
|
|
|
|
if self.tag:
|
|
|
|
|
tag = self.tag.lower()
|
2018-10-03 16:08:36 +02:00
|
|
|
|
works = (
|
|
|
|
|
work for work in works
|
|
|
|
|
if tag in [t["name"].lower() for t in work["tags"]]
|
|
|
|
|
)
|
2018-05-18 15:30:06 +02:00
|
|
|
|
|
|
|
|
|
return works
|
2017-06-25 20:18:27 +02:00
|
|
|
|
|
2022-05-01 21:12:23 +02:00
|
|
|
|
|
|
|
|
|
class PixivAvatarExtractor(PixivExtractor):
|
|
|
|
|
"""Extractor for pixiv avatars"""
|
|
|
|
|
subcategory = "avatar"
|
2022-05-03 16:11:49 +02:00
|
|
|
|
filename_fmt = "avatar{date:?_//%Y-%m-%d}.{extension}"
|
|
|
|
|
archive_fmt = "avatar_{user[id]}_{date}"
|
2022-05-01 21:12:23 +02:00
|
|
|
|
pattern = (r"(?:https?://)?(?:www\.)?pixiv\.net"
|
|
|
|
|
r"/(?:en/)?users/(\d+)/avatar")
|
|
|
|
|
test = ("https://www.pixiv.net/en/users/173530/avatar", {
|
|
|
|
|
"content": "4e57544480cc2036ea9608103e8f024fa737fe66",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
|
PixivExtractor.__init__(self, match)
|
|
|
|
|
self.user_id = match.group(1)
|
|
|
|
|
|
|
|
|
|
def works(self):
|
|
|
|
|
user = self.api.user_detail(self.user_id)["user"]
|
|
|
|
|
url = user["profile_image_urls"]["medium"].replace("_170.", ".")
|
|
|
|
|
return (self._make_work("avatar", url, user),)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PixivBackgroundExtractor(PixivExtractor):
|
|
|
|
|
"""Extractor for pixiv background banners"""
|
|
|
|
|
subcategory = "background"
|
2022-07-11 00:35:23 +02:00
|
|
|
|
filename_fmt = "background{date:?_//%Y-%m-%d}.{extension}"
|
2022-05-03 16:11:49 +02:00
|
|
|
|
archive_fmt = "background_{user[id]}_{date}"
|
2022-05-01 21:12:23 +02:00
|
|
|
|
pattern = (r"(?:https?://)?(?:www\.)?pixiv\.net"
|
|
|
|
|
r"/(?:en/)?users/(\d+)/background")
|
|
|
|
|
test = ("https://www.pixiv.net/en/users/194921/background", {
|
|
|
|
|
"pattern": r"https://i\.pximg\.net/background/img/2021/01/30/16/12/02"
|
|
|
|
|
r"/194921_af1f71e557a42f499213d4b9eaccc0f8\.jpg",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
|
PixivExtractor.__init__(self, match)
|
|
|
|
|
self.user_id = match.group(1)
|
|
|
|
|
|
|
|
|
|
def works(self):
|
|
|
|
|
detail = self.api.user_detail(self.user_id)
|
|
|
|
|
url = detail["profile"]["background_image_url"]
|
|
|
|
|
if not url:
|
|
|
|
|
return ()
|
|
|
|
|
if "/c/" in url:
|
|
|
|
|
parts = url.split("/")
|
|
|
|
|
del parts[3:5]
|
|
|
|
|
url = "/".join(parts)
|
|
|
|
|
url = url.replace("_master1200.", ".")
|
|
|
|
|
work = self._make_work("background", url, detail["user"])
|
|
|
|
|
if url.endswith(".jpg"):
|
2022-06-03 17:25:23 +02:00
|
|
|
|
url = url[:-4]
|
|
|
|
|
work["_fallback"] = (url + ".png", url + ".gif")
|
2022-05-01 21:12:23 +02:00
|
|
|
|
return (work,)
|
2022-04-21 13:53:02 +02:00
|
|
|
|
|
2017-06-04 16:33:36 +02:00
|
|
|
|
|
2017-06-25 20:18:27 +02:00
|
|
|
|
class PixivMeExtractor(PixivExtractor):
|
|
|
|
|
"""Extractor for pixiv.me URLs"""
|
|
|
|
|
subcategory = "me"
|
2020-10-22 23:12:59 +02:00
|
|
|
|
pattern = r"(?:https?://)?pixiv\.me/([^/?#]+)"
|
2019-02-08 13:45:40 +01:00
|
|
|
|
test = (
|
2017-06-25 20:18:27 +02:00
|
|
|
|
("https://pixiv.me/del_shannon", {
|
2020-01-10 13:31:06 +01:00
|
|
|
|
"url": "29c295ce75150177e6b0a09089a949804c708fbf",
|
2017-06-25 20:18:27 +02:00
|
|
|
|
}),
|
|
|
|
|
("https://pixiv.me/del_shanno", {
|
|
|
|
|
"exception": exception.NotFoundError,
|
|
|
|
|
}),
|
2019-02-08 13:45:40 +01:00
|
|
|
|
)
|
2017-06-25 20:18:27 +02:00
|
|
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
|
PixivExtractor.__init__(self, match)
|
2017-06-25 20:18:27 +02:00
|
|
|
|
self.account = match.group(1)
|
|
|
|
|
|
|
|
|
|
def items(self):
|
2018-06-25 22:39:43 +02:00
|
|
|
|
url = "https://pixiv.me/" + self.account
|
2019-12-29 23:37:34 +01:00
|
|
|
|
data = {"_extractor": PixivUserExtractor}
|
2018-06-25 22:39:43 +02:00
|
|
|
|
response = self.request(
|
2019-07-04 23:45:26 +02:00
|
|
|
|
url, method="HEAD", allow_redirects=False, notfound="user")
|
2019-12-29 23:37:34 +01:00
|
|
|
|
yield Message.Queue, response.headers["Location"], data
|
2017-06-25 20:18:27 +02:00
|
|
|
|
|
|
|
|
|
|
2017-06-04 16:33:36 +02:00
|
|
|
|
class PixivWorkExtractor(PixivExtractor):
|
2016-09-12 10:20:57 +02:00
|
|
|
|
"""Extractor for a single pixiv work/illustration"""
|
2015-11-30 01:11:13 +01:00
|
|
|
|
subcategory = "work"
|
2019-02-08 13:45:40 +01:00
|
|
|
|
pattern = (r"(?:https?://)?(?:(?:www\.|touch\.)?pixiv\.net"
|
2019-09-24 21:42:31 +02:00
|
|
|
|
r"/(?:(?:en/)?artworks/"
|
|
|
|
|
r"|member_illust\.php\?(?:[^&]+&)*illust_id=)(\d+)"
|
2019-02-08 12:03:10 +01:00
|
|
|
|
r"|(?:i(?:\d+\.pixiv|\.pximg)\.net"
|
|
|
|
|
r"/(?:(?:.*/)?img-[^/]+/img/\d{4}(?:/\d\d){5}|img\d+/img/[^/]+)"
|
2019-02-08 13:45:40 +01:00
|
|
|
|
r"|img\d*\.pixiv\.net/img/[^/]+|(?:www\.)?pixiv\.net/i)/(\d+))")
|
|
|
|
|
test = (
|
2019-09-24 21:42:31 +02:00
|
|
|
|
("https://www.pixiv.net/artworks/966412", {
|
2017-04-14 14:40:36 +02:00
|
|
|
|
"url": "90c1715b07b0d1aad300bce256a0bc71f42540ba",
|
2016-08-25 20:10:02 +02:00
|
|
|
|
"content": "69a8edfb717400d1c2e146ab2b30d2c235440c5a",
|
2022-12-15 11:40:20 +01:00
|
|
|
|
"keyword": {
|
|
|
|
|
"date" : "dt:2008-06-12 15:29:13",
|
|
|
|
|
"date_url": "dt:2008-06-12 15:29:13",
|
|
|
|
|
},
|
2016-08-25 20:10:02 +02:00
|
|
|
|
}),
|
2017-02-01 00:53:19 +01:00
|
|
|
|
(("http://www.pixiv.net/member_illust.php"
|
|
|
|
|
"?mode=medium&illust_id=966411"), {
|
2016-12-30 01:46:42 +01:00
|
|
|
|
"exception": exception.NotFoundError,
|
|
|
|
|
}),
|
2018-02-19 08:51:09 +01:00
|
|
|
|
# ugoira
|
|
|
|
|
(("https://www.pixiv.net/member_illust.php"
|
|
|
|
|
"?mode=medium&illust_id=66806629"), {
|
2018-06-18 19:22:54 +02:00
|
|
|
|
"url": "7267695a985c4db8759bebcf8d21dbdd2d2317ef",
|
2022-12-15 11:40:20 +01:00
|
|
|
|
"keyword": {
|
|
|
|
|
"frames" : list,
|
|
|
|
|
"date" : "dt:2018-01-14 15:06:08",
|
|
|
|
|
"date_url": "dt:2018-01-15 04:24:48",
|
|
|
|
|
},
|
2018-02-19 08:51:09 +01:00
|
|
|
|
}),
|
2021-01-17 16:37:07 +01:00
|
|
|
|
# related works (#1237)
|
|
|
|
|
("https://www.pixiv.net/artworks/966412", {
|
|
|
|
|
"options": (("related", True),),
|
2021-01-21 21:35:42 +01:00
|
|
|
|
"range": "1-10",
|
2021-01-17 16:37:07 +01:00
|
|
|
|
"count": ">= 10",
|
|
|
|
|
}),
|
2019-09-24 21:42:31 +02:00
|
|
|
|
("https://www.pixiv.net/en/artworks/966412"),
|
|
|
|
|
("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=96641"),
|
2019-02-08 13:45:40 +01:00
|
|
|
|
("http://i1.pixiv.net/c/600x600/img-master"
|
|
|
|
|
"/img/2008/06/13/00/29/13/966412_p0_master1200.jpg"),
|
|
|
|
|
("https://i.pximg.net/img-original"
|
|
|
|
|
"/img/2017/04/25/07/33/29/62568267_p0.png"),
|
|
|
|
|
("https://www.pixiv.net/i/966412"),
|
|
|
|
|
("http://img.pixiv.net/img/soundcross/42626136.jpg"),
|
|
|
|
|
("http://i2.pixiv.net/img76/img/snailrin/42672235.jpg"),
|
|
|
|
|
)
|
2015-11-22 02:21:02 +01:00
|
|
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
|
PixivExtractor.__init__(self, match)
|
2019-02-08 12:03:10 +01:00
|
|
|
|
self.illust_id = match.group(1) or match.group(2)
|
2015-11-22 02:21:02 +01:00
|
|
|
|
|
2017-06-04 16:33:36 +02:00
|
|
|
|
def works(self):
|
2021-01-17 16:37:07 +01:00
|
|
|
|
works = (self.api.illust_detail(self.illust_id),)
|
|
|
|
|
if self.config("related", False):
|
|
|
|
|
related = self.api.illust_related(self.illust_id)
|
|
|
|
|
works = itertools.chain(works, related)
|
|
|
|
|
return works
|
2015-11-22 02:21:02 +01:00
|
|
|
|
|
|
|
|
|
|
2017-06-04 16:33:36 +02:00
|
|
|
|
class PixivFavoriteExtractor(PixivExtractor):
|
2016-09-12 10:20:57 +02:00
|
|
|
|
"""Extractor for all favorites/bookmarks of a pixiv-user"""
|
2015-11-30 01:11:13 +01:00
|
|
|
|
subcategory = "favorite"
|
2019-02-08 13:45:40 +01:00
|
|
|
|
directory_fmt = ("{category}", "bookmarks",
|
|
|
|
|
"{user_bookmark[id]} {user_bookmark[account]}")
|
2018-05-13 22:24:21 +02:00
|
|
|
|
archive_fmt = "f_{user_bookmark[id]}_{id}{num}.{extension}"
|
2020-02-06 23:42:13 +01:00
|
|
|
|
pattern = (r"(?:https?://)?(?:www\.|touch\.)?pixiv\.net/(?:(?:en/)?"
|
2021-03-25 14:59:33 +01:00
|
|
|
|
r"users/(\d+)/(bookmarks/artworks|following)(?:/([^/?#]+))?"
|
|
|
|
|
r"|bookmark\.php)(?:\?([^#]*))?")
|
2019-02-08 13:45:40 +01:00
|
|
|
|
test = (
|
2020-01-10 13:31:06 +01:00
|
|
|
|
("https://www.pixiv.net/en/users/173530/bookmarks/artworks", {
|
2022-05-01 21:12:23 +02:00
|
|
|
|
"url": "85a3104eaaaf003c7b3947117ca2f1f0b1cfc949",
|
2020-01-10 13:31:06 +01:00
|
|
|
|
}),
|
2017-10-17 16:49:42 +02:00
|
|
|
|
("https://www.pixiv.net/bookmark.php?id=173530", {
|
2022-05-01 21:12:23 +02:00
|
|
|
|
"url": "85a3104eaaaf003c7b3947117ca2f1f0b1cfc949",
|
2017-10-17 16:49:42 +02:00
|
|
|
|
}),
|
2018-05-18 16:55:24 +02:00
|
|
|
|
# bookmarks with specific tag
|
2020-02-06 23:42:13 +01:00
|
|
|
|
(("https://www.pixiv.net/en/users/3137110"
|
|
|
|
|
"/bookmarks/artworks/%E3%81%AF%E3%82%93%E3%82%82%E3%82%93"), {
|
|
|
|
|
"url": "379b28275f786d946e01f721e54afe346c148a8c",
|
|
|
|
|
}),
|
|
|
|
|
# bookmarks with specific tag (legacy url)
|
2018-05-18 16:55:24 +02:00
|
|
|
|
(("https://www.pixiv.net/bookmark.php?id=3137110"
|
|
|
|
|
"&tag=%E3%81%AF%E3%82%93%E3%82%82%E3%82%93&p=1"), {
|
2020-02-06 23:42:13 +01:00
|
|
|
|
"url": "379b28275f786d946e01f721e54afe346c148a8c",
|
2018-05-18 16:55:24 +02:00
|
|
|
|
}),
|
|
|
|
|
# own bookmarks
|
|
|
|
|
("https://www.pixiv.net/bookmark.php", {
|
|
|
|
|
"url": "90c1715b07b0d1aad300bce256a0bc71f42540ba",
|
|
|
|
|
}),
|
2020-02-01 01:44:21 +01:00
|
|
|
|
# own bookmarks with tag (#596)
|
|
|
|
|
("https://www.pixiv.net/bookmark.php?tag=foobar", {
|
|
|
|
|
"count": 0,
|
|
|
|
|
}),
|
2019-12-26 23:42:42 +01:00
|
|
|
|
# followed users (#515)
|
2020-01-10 13:31:06 +01:00
|
|
|
|
("https://www.pixiv.net/en/users/173530/following", {
|
|
|
|
|
"pattern": PixivUserExtractor.pattern,
|
|
|
|
|
"count": ">= 12",
|
|
|
|
|
}),
|
2020-02-06 23:42:13 +01:00
|
|
|
|
# followed users (legacy url) (#515)
|
2019-12-26 23:42:42 +01:00
|
|
|
|
("https://www.pixiv.net/bookmark.php?id=173530&type=user", {
|
|
|
|
|
"pattern": PixivUserExtractor.pattern,
|
|
|
|
|
"count": ">= 12",
|
|
|
|
|
}),
|
2018-05-18 16:55:24 +02:00
|
|
|
|
# touch URLs
|
2019-02-08 13:45:40 +01:00
|
|
|
|
("https://touch.pixiv.net/bookmark.php?id=173530"),
|
|
|
|
|
("https://touch.pixiv.net/bookmark.php"),
|
|
|
|
|
)
|
2015-11-23 00:15:43 +01:00
|
|
|
|
|
|
|
|
|
def __init__(self, match):
|
2020-02-06 23:42:13 +01:00
|
|
|
|
uid, kind, self.tag, query = match.groups()
|
2021-06-16 19:56:09 +02:00
|
|
|
|
query = text.parse_query(query)
|
2020-01-10 13:31:06 +01:00
|
|
|
|
|
2021-06-16 19:56:09 +02:00
|
|
|
|
if not uid:
|
|
|
|
|
uid = query.get("id")
|
2020-01-10 13:31:06 +01:00
|
|
|
|
if not uid:
|
|
|
|
|
self.subcategory = "bookmark"
|
2021-06-16 19:56:09 +02:00
|
|
|
|
|
|
|
|
|
if kind == "following" or query.get("type") == "user":
|
|
|
|
|
self.subcategory = "following"
|
|
|
|
|
self.items = self._items_following
|
2020-01-10 13:31:06 +01:00
|
|
|
|
|
2019-02-11 13:31:10 +01:00
|
|
|
|
PixivExtractor.__init__(self, match)
|
2021-06-16 19:56:09 +02:00
|
|
|
|
self.query = query
|
2020-01-10 13:31:06 +01:00
|
|
|
|
self.user_id = uid
|
2017-06-04 16:33:36 +02:00
|
|
|
|
|
|
|
|
|
def works(self):
|
2018-05-18 16:55:24 +02:00
|
|
|
|
tag = None
|
|
|
|
|
if "tag" in self.query:
|
|
|
|
|
tag = text.unquote(self.query["tag"])
|
2020-02-06 23:42:13 +01:00
|
|
|
|
elif self.tag:
|
|
|
|
|
tag = text.unquote(self.tag)
|
|
|
|
|
|
2021-06-16 19:56:09 +02:00
|
|
|
|
restrict = "public"
|
|
|
|
|
if self.query.get("rest") == "hide":
|
2018-05-18 16:55:24 +02:00
|
|
|
|
restrict = "private"
|
2015-11-23 00:15:43 +01:00
|
|
|
|
|
2018-10-03 16:08:36 +02:00
|
|
|
|
return self.api.user_bookmarks_illust(self.user_id, tag, restrict)
|
2015-11-23 02:58:31 +01:00
|
|
|
|
|
2020-02-09 13:54:58 +01:00
|
|
|
|
def metadata(self):
|
2020-01-10 13:31:06 +01:00
|
|
|
|
if self.user_id:
|
2022-04-21 13:53:02 +02:00
|
|
|
|
user = self.api.user_detail(self.user_id)["user"]
|
2018-05-18 16:55:24 +02:00
|
|
|
|
else:
|
|
|
|
|
self.api.login()
|
|
|
|
|
user = self.api.user
|
|
|
|
|
|
|
|
|
|
self.user_id = user["id"]
|
|
|
|
|
return {"user_bookmark": user}
|
2015-10-06 17:19:54 +02:00
|
|
|
|
|
2019-12-26 23:42:42 +01:00
|
|
|
|
def _items_following(self):
|
2021-06-16 19:56:09 +02:00
|
|
|
|
restrict = "public"
|
|
|
|
|
if self.query.get("rest") == "hide":
|
|
|
|
|
restrict = "private"
|
2019-12-26 23:42:42 +01:00
|
|
|
|
|
2021-06-16 19:56:09 +02:00
|
|
|
|
for preview in self.api.user_following(self.user_id, restrict):
|
2019-12-26 23:42:42 +01:00
|
|
|
|
user = preview["user"]
|
|
|
|
|
user["_extractor"] = PixivUserExtractor
|
2020-01-29 22:54:31 +01:00
|
|
|
|
url = "https://www.pixiv.net/users/{}".format(user["id"])
|
2019-12-26 23:42:42 +01:00
|
|
|
|
yield Message.Queue, url, user
|
|
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
|
2017-08-20 20:21:52 +02:00
|
|
|
|
class PixivRankingExtractor(PixivExtractor):
|
|
|
|
|
"""Extractor for pixiv ranking pages"""
|
|
|
|
|
subcategory = "ranking"
|
2018-03-02 16:11:53 +01:00
|
|
|
|
archive_fmt = "r_{ranking[mode]}_{ranking[date]}_{id}{num}.{extension}"
|
2019-02-08 13:45:40 +01:00
|
|
|
|
directory_fmt = ("{category}", "rankings",
|
|
|
|
|
"{ranking[mode]}", "{ranking[date]}")
|
|
|
|
|
pattern = (r"(?:https?://)?(?:www\.|touch\.)?pixiv\.net"
|
|
|
|
|
r"/ranking\.php(?:\?([^#]*))?")
|
|
|
|
|
test = (
|
|
|
|
|
("https://www.pixiv.net/ranking.php?mode=daily&date=20170818"),
|
|
|
|
|
("https://www.pixiv.net/ranking.php"),
|
|
|
|
|
("https://touch.pixiv.net/ranking.php"),
|
2022-11-15 12:17:53 +01:00
|
|
|
|
("https://www.pixiv.net/ranking.php?mode=unknown", {
|
|
|
|
|
"exception": exception.StopExtraction,
|
|
|
|
|
}),
|
2019-02-08 13:45:40 +01:00
|
|
|
|
)
|
2017-08-20 20:21:52 +02:00
|
|
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
|
PixivExtractor.__init__(self, match)
|
2018-05-15 13:28:08 +02:00
|
|
|
|
self.query = match.group(1)
|
|
|
|
|
self.mode = self.date = None
|
2017-08-20 20:21:52 +02:00
|
|
|
|
|
2018-05-15 13:28:08 +02:00
|
|
|
|
def works(self):
|
|
|
|
|
return self.api.illust_ranking(self.mode, self.date)
|
|
|
|
|
|
2020-02-09 13:54:58 +01:00
|
|
|
|
def metadata(self):
|
2018-05-15 13:28:08 +02:00
|
|
|
|
query = text.parse_query(self.query)
|
|
|
|
|
|
|
|
|
|
mode = query.get("mode", "daily").lower()
|
|
|
|
|
mode_map = {
|
2018-05-13 22:24:21 +02:00
|
|
|
|
"daily": "day",
|
|
|
|
|
"daily_r18": "day_r18",
|
2022-11-15 11:47:57 +01:00
|
|
|
|
"daily_ai": "day_ai",
|
|
|
|
|
"daily_r18_ai": "day_r18_ai",
|
2018-05-13 22:24:21 +02:00
|
|
|
|
"weekly": "week",
|
|
|
|
|
"weekly_r18": "week_r18",
|
|
|
|
|
"monthly": "month",
|
|
|
|
|
"male": "day_male",
|
|
|
|
|
"male_r18": "day_male_r18",
|
|
|
|
|
"female": "day_female",
|
|
|
|
|
"female_r18": "day_female_r18",
|
|
|
|
|
"original": "week_original",
|
|
|
|
|
"rookie": "week_rookie",
|
|
|
|
|
"r18g": "week_r18g",
|
2018-03-02 16:11:53 +01:00
|
|
|
|
}
|
2022-11-15 12:17:53 +01:00
|
|
|
|
try:
|
|
|
|
|
self.mode = mode = mode_map[mode]
|
|
|
|
|
except KeyError:
|
|
|
|
|
raise exception.StopExtraction("Invalid mode '%s'", mode)
|
2017-06-04 16:33:36 +02:00
|
|
|
|
|
2018-05-13 22:24:21 +02:00
|
|
|
|
date = query.get("date")
|
|
|
|
|
if date:
|
|
|
|
|
if len(date) == 8 and date.isdecimal():
|
|
|
|
|
date = "{}-{}-{}".format(date[0:4], date[4:6], date[6:8])
|
|
|
|
|
else:
|
|
|
|
|
self.log.warning("invalid date '%s'", date)
|
|
|
|
|
date = None
|
|
|
|
|
if not date:
|
|
|
|
|
date = (datetime.utcnow() - timedelta(days=1)).strftime("%Y-%m-%d")
|
|
|
|
|
self.date = date
|
2017-06-04 16:33:36 +02:00
|
|
|
|
|
2018-05-15 13:28:08 +02:00
|
|
|
|
return {"ranking": {
|
|
|
|
|
"mode": mode,
|
|
|
|
|
"date": self.date,
|
|
|
|
|
}}
|
2018-05-07 20:05:44 +02:00
|
|
|
|
|
|
|
|
|
|
2018-05-14 14:46:05 +02:00
|
|
|
|
class PixivSearchExtractor(PixivExtractor):
|
|
|
|
|
"""Extractor for pixiv search results"""
|
|
|
|
|
subcategory = "search"
|
|
|
|
|
archive_fmt = "s_{search[word]}_{id}{num}.{extension}"
|
2019-02-08 13:45:40 +01:00
|
|
|
|
directory_fmt = ("{category}", "search", "{search[word]}")
|
|
|
|
|
pattern = (r"(?:https?://)?(?:www\.|touch\.)?pixiv\.net"
|
2020-10-22 23:12:59 +02:00
|
|
|
|
r"/(?:(?:en/)?tags/([^/?#]+)(?:/[^/?#]+)?/?"
|
2019-12-06 18:10:22 +01:00
|
|
|
|
r"|search\.php)(?:\?([^#]+))?")
|
2019-02-08 13:45:40 +01:00
|
|
|
|
test = (
|
2019-12-06 18:10:22 +01:00
|
|
|
|
("https://www.pixiv.net/en/tags/Original", {
|
|
|
|
|
"range": "1-10",
|
|
|
|
|
"count": 10,
|
|
|
|
|
}),
|
2022-11-15 12:17:53 +01:00
|
|
|
|
("https://pixiv.net/en/tags/foo/artworks?order=week&s_mode=s_tag", {
|
|
|
|
|
"exception": exception.StopExtraction,
|
|
|
|
|
}),
|
|
|
|
|
("https://pixiv.net/en/tags/foo/artworks?order=date&s_mode=tag", {
|
|
|
|
|
"exception": exception.StopExtraction,
|
|
|
|
|
}),
|
|
|
|
|
("https://www.pixiv.net/search.php?s_mode=s_tag&name=Original", {
|
|
|
|
|
"exception": exception.StopExtraction,
|
|
|
|
|
}),
|
2019-12-06 18:10:22 +01:00
|
|
|
|
("https://www.pixiv.net/en/tags/foo/artworks?order=date&s_mode=s_tag"),
|
2019-02-08 13:45:40 +01:00
|
|
|
|
("https://www.pixiv.net/search.php?s_mode=s_tag&word=Original"),
|
|
|
|
|
("https://touch.pixiv.net/search.php?word=Original"),
|
|
|
|
|
)
|
2018-05-14 14:46:05 +02:00
|
|
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
|
PixivExtractor.__init__(self, match)
|
2019-12-06 18:10:22 +01:00
|
|
|
|
self.word, self.query = match.groups()
|
|
|
|
|
self.sort = self.target = None
|
2018-05-15 13:28:08 +02:00
|
|
|
|
|
|
|
|
|
def works(self):
|
2021-12-23 23:03:39 +01:00
|
|
|
|
return self.api.search_illust(
|
|
|
|
|
self.word, self.sort, self.target,
|
|
|
|
|
date_start=self.date_start, date_end=self.date_end)
|
2018-05-14 14:46:05 +02:00
|
|
|
|
|
2020-02-09 13:54:58 +01:00
|
|
|
|
def metadata(self):
|
2018-05-15 13:28:08 +02:00
|
|
|
|
query = text.parse_query(self.query)
|
2018-05-14 14:46:05 +02:00
|
|
|
|
|
2019-12-06 18:10:22 +01:00
|
|
|
|
if self.word:
|
|
|
|
|
self.word = text.unquote(self.word)
|
|
|
|
|
else:
|
2022-11-15 12:17:53 +01:00
|
|
|
|
try:
|
|
|
|
|
self.word = query["word"]
|
|
|
|
|
except KeyError:
|
2019-12-06 18:10:22 +01:00
|
|
|
|
raise exception.StopExtraction("Missing search term")
|
2018-05-14 14:46:05 +02:00
|
|
|
|
|
|
|
|
|
sort = query.get("order", "date_d")
|
|
|
|
|
sort_map = {
|
|
|
|
|
"date": "date_asc",
|
|
|
|
|
"date_d": "date_desc",
|
|
|
|
|
}
|
2022-11-15 12:17:53 +01:00
|
|
|
|
try:
|
|
|
|
|
self.sort = sort = sort_map[sort]
|
|
|
|
|
except KeyError:
|
|
|
|
|
raise exception.StopExtraction("Invalid search order '%s'", sort)
|
2018-05-14 14:46:05 +02:00
|
|
|
|
|
2022-10-24 14:16:40 +02:00
|
|
|
|
target = query.get("s_mode", "s_tag_full")
|
2018-05-14 14:46:05 +02:00
|
|
|
|
target_map = {
|
|
|
|
|
"s_tag": "partial_match_for_tags",
|
|
|
|
|
"s_tag_full": "exact_match_for_tags",
|
|
|
|
|
"s_tc": "title_and_caption",
|
|
|
|
|
}
|
2022-11-15 12:17:53 +01:00
|
|
|
|
try:
|
|
|
|
|
self.target = target = target_map[target]
|
|
|
|
|
except KeyError:
|
|
|
|
|
raise exception.StopExtraction("Invalid search mode '%s'", target)
|
2018-05-14 14:46:05 +02:00
|
|
|
|
|
2021-12-23 23:03:39 +01:00
|
|
|
|
self.date_start = query.get("scd")
|
|
|
|
|
self.date_end = query.get("ecd")
|
|
|
|
|
|
2018-05-15 13:28:08 +02:00
|
|
|
|
return {"search": {
|
2018-05-14 14:46:05 +02:00
|
|
|
|
"word": self.word,
|
|
|
|
|
"sort": self.sort,
|
|
|
|
|
"target": self.target,
|
2021-12-23 23:03:39 +01:00
|
|
|
|
"date_start": self.date_start,
|
|
|
|
|
"date_end": self.date_end,
|
2018-05-15 13:28:08 +02:00
|
|
|
|
}}
|
2018-05-14 14:46:05 +02:00
|
|
|
|
|
|
|
|
|
|
2018-05-15 13:02:49 +02:00
|
|
|
|
class PixivFollowExtractor(PixivExtractor):
|
|
|
|
|
"""Extractor for new illustrations from your followed artists"""
|
|
|
|
|
subcategory = "follow"
|
|
|
|
|
archive_fmt = "F_{user_follow[id]}_{id}{num}.{extension}"
|
2019-02-08 13:45:40 +01:00
|
|
|
|
directory_fmt = ("{category}", "following")
|
|
|
|
|
pattern = (r"(?:https?://)?(?:www\.|touch\.)?pixiv\.net"
|
|
|
|
|
r"/bookmark_new_illust\.php")
|
|
|
|
|
test = (
|
|
|
|
|
("https://www.pixiv.net/bookmark_new_illust.php"),
|
|
|
|
|
("https://touch.pixiv.net/bookmark_new_illust.php"),
|
|
|
|
|
)
|
2018-05-15 13:02:49 +02:00
|
|
|
|
|
|
|
|
|
def works(self):
|
|
|
|
|
return self.api.illust_follow()
|
|
|
|
|
|
2020-02-09 13:54:58 +01:00
|
|
|
|
def metadata(self):
|
2018-05-15 13:02:49 +02:00
|
|
|
|
self.api.login()
|
|
|
|
|
return {"user_follow": self.api.user}
|
|
|
|
|
|
|
|
|
|
|
2021-07-07 02:22:44 +02:00
|
|
|
|
class PixivPixivisionExtractor(PixivExtractor):
|
|
|
|
|
"""Extractor for illustrations from a pixivision article"""
|
|
|
|
|
subcategory = "pixivision"
|
|
|
|
|
directory_fmt = ("{category}", "pixivision",
|
|
|
|
|
"{pixivision_id} {pixivision_title}")
|
|
|
|
|
archive_fmt = "V{pixivision_id}_{id}{suffix}.{extension}"
|
|
|
|
|
pattern = r"(?:https?://)?(?:www\.)?pixivision\.net/(?:en/)?a/(\d+)"
|
|
|
|
|
test = (
|
|
|
|
|
("https://www.pixivision.net/en/a/2791"),
|
|
|
|
|
("https://pixivision.net/a/2791", {
|
|
|
|
|
"count": 7,
|
|
|
|
|
"keyword": {
|
|
|
|
|
"pixivision_id": "2791",
|
|
|
|
|
"pixivision_title": "What's your favorite music? Editor’s "
|
|
|
|
|
"picks featuring: “CD Covers”!",
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
|
PixivExtractor.__init__(self, match)
|
|
|
|
|
self.pixivision_id = match.group(1)
|
|
|
|
|
|
|
|
|
|
def works(self):
|
|
|
|
|
return (
|
|
|
|
|
self.api.illust_detail(illust_id)
|
|
|
|
|
for illust_id in util.unique_sequence(text.extract_iter(
|
|
|
|
|
self.page, '<a href="https://www.pixiv.net/en/artworks/', '"'))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def metadata(self):
|
|
|
|
|
url = "https://www.pixivision.net/en/a/" + self.pixivision_id
|
|
|
|
|
headers = {"User-Agent": "Mozilla/5.0"}
|
|
|
|
|
self.page = self.request(url, headers=headers).text
|
|
|
|
|
|
2022-11-04 23:39:38 +01:00
|
|
|
|
title = text.extr(self.page, '<title>', '<')
|
2021-07-07 02:22:44 +02:00
|
|
|
|
return {
|
|
|
|
|
"pixivision_id" : self.pixivision_id,
|
|
|
|
|
"pixivision_title": text.unescape(title),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-09-27 22:57:07 +02:00
|
|
|
|
class PixivSeriesExtractor(PixivExtractor):
|
|
|
|
|
"""Extractor for illustrations from a Pixiv series"""
|
|
|
|
|
subcategory = "series"
|
|
|
|
|
directory_fmt = ("{category}", "{user[id]} {user[account]}",
|
|
|
|
|
"{series[id]} {series[title]}")
|
|
|
|
|
filename_fmt = "{num_series:>03}_{id}_p{num}.{extension}"
|
|
|
|
|
pattern = (r"(?:https?://)?(?:www\.)?pixiv\.net"
|
|
|
|
|
r"/user/(\d+)/series/(\d+)")
|
|
|
|
|
test = ("https://www.pixiv.net/user/10509347/series/21859", {
|
|
|
|
|
"range": "1-10",
|
|
|
|
|
"count": 10,
|
|
|
|
|
"keyword": {
|
|
|
|
|
"num_series": int,
|
|
|
|
|
"series": {
|
|
|
|
|
"canonical": "https://www.pixiv.net/user/10509347"
|
|
|
|
|
"/series/21859",
|
|
|
|
|
"description": str,
|
|
|
|
|
"ogp": dict,
|
|
|
|
|
"title": "先輩がうざい後輩の話",
|
|
|
|
|
"total": int,
|
|
|
|
|
"twitter": dict,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
|
PixivExtractor.__init__(self, match)
|
|
|
|
|
self.user_id, self.series_id = match.groups()
|
|
|
|
|
|
|
|
|
|
def works(self):
|
|
|
|
|
url = self.root + "/ajax/series/" + self.series_id
|
|
|
|
|
params = {"p": 1}
|
|
|
|
|
headers = {
|
|
|
|
|
"Accept": "application/json",
|
|
|
|
|
"Referer": "{}/user/{}/series/{}".format(
|
|
|
|
|
self.root, self.user_id, self.series_id),
|
|
|
|
|
"Alt-Used": "www.pixiv.net",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
data = self.request(url, params=params, headers=headers).json()
|
|
|
|
|
body = data["body"]
|
|
|
|
|
page = body["page"]
|
|
|
|
|
|
|
|
|
|
series = body["extraData"]["meta"]
|
|
|
|
|
series["id"] = self.series_id
|
|
|
|
|
series["total"] = page["total"]
|
2022-11-04 23:39:38 +01:00
|
|
|
|
series["title"] = text.extr(series["title"], '"', '"')
|
2022-09-27 22:57:07 +02:00
|
|
|
|
|
|
|
|
|
for info in page["series"]:
|
|
|
|
|
work = self.api.illust_detail(info["workId"])
|
|
|
|
|
work["num_series"] = info["order"]
|
|
|
|
|
work["series"] = series
|
|
|
|
|
yield work
|
|
|
|
|
|
|
|
|
|
if len(page["series"]) < 10:
|
|
|
|
|
return
|
|
|
|
|
params["p"] += 1
|
|
|
|
|
|
|
|
|
|
|
2021-10-12 20:50:11 +02:00
|
|
|
|
class PixivSketchExtractor(Extractor):
|
|
|
|
|
"""Extractor for user pages on sketch.pixiv.net"""
|
|
|
|
|
category = "pixiv"
|
|
|
|
|
subcategory = "sketch"
|
|
|
|
|
directory_fmt = ("{category}", "sketch", "{user[unique_name]}")
|
|
|
|
|
filename_fmt = "{post_id} {id}.{extension}"
|
|
|
|
|
archive_fmt = "S{user[id]}_{id}"
|
|
|
|
|
root = "https://sketch.pixiv.net"
|
|
|
|
|
cookiedomain = ".pixiv.net"
|
|
|
|
|
pattern = r"(?:https?://)?sketch\.pixiv\.net/@([^/?#]+)"
|
|
|
|
|
test = ("https://sketch.pixiv.net/@nicoby", {
|
|
|
|
|
"pattern": r"https://img\-sketch\.pixiv\.net/uploads/medium"
|
|
|
|
|
r"/file/\d+/\d+\.(jpg|png)",
|
|
|
|
|
"count": ">= 35",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
|
Extractor.__init__(self, match)
|
|
|
|
|
self.username = match.group(1)
|
|
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
|
headers = {"Referer": "{}/@{}".format(self.root, self.username)}
|
|
|
|
|
|
|
|
|
|
for post in self.posts():
|
|
|
|
|
media = post["media"]
|
|
|
|
|
post["post_id"] = post["id"]
|
|
|
|
|
post["date"] = text.parse_datetime(
|
|
|
|
|
post["created_at"], "%Y-%m-%dT%H:%M:%S.%f%z")
|
|
|
|
|
util.delete_items(post, ("id", "media", "_links"))
|
|
|
|
|
|
|
|
|
|
yield Message.Directory, post
|
|
|
|
|
post["_http_headers"] = headers
|
|
|
|
|
|
|
|
|
|
for photo in media:
|
|
|
|
|
original = photo["photo"]["original"]
|
|
|
|
|
post["id"] = photo["id"]
|
|
|
|
|
post["width"] = original["width"]
|
|
|
|
|
post["height"] = original["height"]
|
|
|
|
|
|
|
|
|
|
url = original["url"]
|
|
|
|
|
text.nameext_from_url(url, post)
|
|
|
|
|
yield Message.Url, url, post
|
|
|
|
|
|
|
|
|
|
def posts(self):
|
|
|
|
|
url = "{}/api/walls/@{}/posts/public.json".format(
|
|
|
|
|
self.root, self.username)
|
|
|
|
|
headers = {
|
|
|
|
|
"Accept": "application/vnd.sketch-v4+json",
|
|
|
|
|
"X-Requested-With": "{}/@{}".format(self.root, self.username),
|
|
|
|
|
"Referer": self.root + "/",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
data = self.request(url, headers=headers).json()
|
|
|
|
|
yield from data["data"]["items"]
|
|
|
|
|
|
|
|
|
|
next_url = data["_links"].get("next")
|
|
|
|
|
if not next_url:
|
|
|
|
|
return
|
|
|
|
|
url = self.root + next_url["href"]
|
|
|
|
|
|
|
|
|
|
|
2018-05-07 20:05:44 +02:00
|
|
|
|
class PixivAppAPI():
|
2018-05-13 22:24:21 +02:00
|
|
|
|
"""Minimal interface for the Pixiv App API for mobile devices
|
2018-05-07 20:05:44 +02:00
|
|
|
|
|
2018-05-13 22:24:21 +02:00
|
|
|
|
For a more complete implementation or documentation, see
|
2018-05-07 20:05:44 +02:00
|
|
|
|
- https://github.com/upbit/pixivpy
|
2018-05-13 22:24:21 +02:00
|
|
|
|
- https://gist.github.com/ZipFile/3ba99b47162c23f8aea5d5942bb557b1
|
2018-05-07 20:05:44 +02:00
|
|
|
|
"""
|
|
|
|
|
CLIENT_ID = "MOBrBDS8blbauoSck0ZfDbtuzpyT"
|
|
|
|
|
CLIENT_SECRET = "lsACyCD94FhDUtGTXi3QzcFE2uU1hqtDaKeqrdwj"
|
2019-09-02 22:34:04 +02:00
|
|
|
|
HASH_SECRET = ("28c1fdd170a5204386cb1313c7077b34"
|
|
|
|
|
"f83e4aaf4aa829ce78c231e05b0bae2c")
|
2018-05-07 20:05:44 +02:00
|
|
|
|
|
|
|
|
|
def __init__(self, extractor):
|
2018-12-22 14:40:35 +01:00
|
|
|
|
self.extractor = extractor
|
2018-05-07 20:05:44 +02:00
|
|
|
|
self.log = extractor.log
|
2021-02-12 18:03:06 +01:00
|
|
|
|
self.username = extractor._get_auth_info()[0]
|
2018-05-15 13:02:49 +02:00
|
|
|
|
self.user = None
|
2018-05-07 20:05:44 +02:00
|
|
|
|
|
2021-02-12 18:03:06 +01:00
|
|
|
|
extractor.session.headers.update({
|
|
|
|
|
"App-OS" : "ios",
|
|
|
|
|
"App-OS-Version": "13.1.2",
|
|
|
|
|
"App-Version" : "7.7.6",
|
|
|
|
|
"User-Agent" : "PixivIOSApp/7.7.6 (iOS 13.1.2; iPhone11,8)",
|
|
|
|
|
"Referer" : "https://app-api.pixiv.net/",
|
|
|
|
|
})
|
|
|
|
|
|
2018-05-07 20:05:44 +02:00
|
|
|
|
self.client_id = extractor.config(
|
|
|
|
|
"client-id", self.CLIENT_ID)
|
|
|
|
|
self.client_secret = extractor.config(
|
|
|
|
|
"client-secret", self.CLIENT_SECRET)
|
2021-02-12 18:03:06 +01:00
|
|
|
|
|
|
|
|
|
token = extractor.config("refresh-token")
|
|
|
|
|
if token is None or token == "cache":
|
|
|
|
|
token = _refresh_token_cache(self.username)
|
|
|
|
|
self.refresh_token = token
|
2018-05-07 20:05:44 +02:00
|
|
|
|
|
2018-05-13 22:24:21 +02:00
|
|
|
|
def login(self):
|
|
|
|
|
"""Login and gain an access token"""
|
2021-02-12 18:03:06 +01:00
|
|
|
|
self.user, auth = self._login_impl(self.username)
|
2018-12-22 14:40:35 +01:00
|
|
|
|
self.extractor.session.headers["Authorization"] = auth
|
2018-05-07 20:05:44 +02:00
|
|
|
|
|
2019-03-14 22:21:49 +01:00
|
|
|
|
@cache(maxage=3600, keyarg=1)
|
2021-02-12 18:03:06 +01:00
|
|
|
|
def _login_impl(self, username):
|
|
|
|
|
if not self.refresh_token:
|
2020-12-22 14:40:18 +01:00
|
|
|
|
raise exception.AuthenticationError(
|
2021-02-12 18:03:06 +01:00
|
|
|
|
"'refresh-token' required.\n"
|
|
|
|
|
"Run `gallery-dl oauth:pixiv` to get one.")
|
2020-12-22 14:40:18 +01:00
|
|
|
|
|
2021-02-12 18:03:06 +01:00
|
|
|
|
self.log.info("Refreshing access token")
|
2018-05-07 20:05:44 +02:00
|
|
|
|
url = "https://oauth.secure.pixiv.net/auth/token"
|
|
|
|
|
data = {
|
2021-02-12 18:03:06 +01:00
|
|
|
|
"client_id" : self.client_id,
|
|
|
|
|
"client_secret" : self.client_secret,
|
|
|
|
|
"grant_type" : "refresh_token",
|
|
|
|
|
"refresh_token" : self.refresh_token,
|
|
|
|
|
"get_secure_url": "1",
|
2018-05-07 20:05:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-02 22:34:04 +02:00
|
|
|
|
time = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S+00:00")
|
|
|
|
|
headers = {
|
|
|
|
|
"X-Client-Time": time,
|
|
|
|
|
"X-Client-Hash": hashlib.md5(
|
|
|
|
|
(time + self.HASH_SECRET).encode()).hexdigest(),
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-22 14:40:35 +01:00
|
|
|
|
response = self.extractor.request(
|
2019-09-02 22:34:04 +02:00
|
|
|
|
url, method="POST", headers=headers, data=data, fatal=False)
|
2018-05-07 20:05:44 +02:00
|
|
|
|
if response.status_code >= 400:
|
2020-12-22 14:59:31 +01:00
|
|
|
|
self.log.debug(response.text)
|
2021-02-12 18:03:06 +01:00
|
|
|
|
raise exception.AuthenticationError("Invalid refresh token")
|
2018-05-07 20:05:44 +02:00
|
|
|
|
|
|
|
|
|
data = response.json()["response"]
|
|
|
|
|
return data["user"], "Bearer " + data["access_token"]
|
|
|
|
|
|
2018-05-13 22:24:21 +02:00
|
|
|
|
def illust_detail(self, illust_id):
|
|
|
|
|
params = {"illust_id": illust_id}
|
2022-04-29 16:29:12 +02:00
|
|
|
|
return self._call("/v1/illust/detail", params)["illust"]
|
2018-05-13 22:24:21 +02:00
|
|
|
|
|
2018-05-15 13:02:49 +02:00
|
|
|
|
def illust_follow(self, restrict="all"):
|
|
|
|
|
params = {"restrict": restrict}
|
2022-04-29 16:29:12 +02:00
|
|
|
|
return self._pagination("/v2/illust/follow", params)
|
2018-05-15 13:02:49 +02:00
|
|
|
|
|
2018-05-13 22:24:21 +02:00
|
|
|
|
def illust_ranking(self, mode="day", date=None):
|
|
|
|
|
params = {"mode": mode, "date": date}
|
2022-04-29 16:29:12 +02:00
|
|
|
|
return self._pagination("/v1/illust/ranking", params)
|
2018-05-13 22:24:21 +02:00
|
|
|
|
|
2021-01-17 16:37:07 +01:00
|
|
|
|
def illust_related(self, illust_id):
|
|
|
|
|
params = {"illust_id": illust_id}
|
2022-04-29 16:29:12 +02:00
|
|
|
|
return self._pagination("/v2/illust/related", params)
|
2021-01-17 16:37:07 +01:00
|
|
|
|
|
2021-12-23 23:03:39 +01:00
|
|
|
|
def search_illust(self, word, sort=None, target=None, duration=None,
|
|
|
|
|
date_start=None, date_end=None):
|
2018-05-14 14:46:05 +02:00
|
|
|
|
params = {"word": word, "search_target": target,
|
2021-12-23 23:03:39 +01:00
|
|
|
|
"sort": sort, "duration": duration,
|
|
|
|
|
"start_date": date_start, "end_date": date_end}
|
2022-04-29 16:29:12 +02:00
|
|
|
|
return self._pagination("/v1/search/illust", params)
|
2018-05-14 14:46:05 +02:00
|
|
|
|
|
2018-05-18 16:55:24 +02:00
|
|
|
|
def user_bookmarks_illust(self, user_id, tag=None, restrict="public"):
|
|
|
|
|
params = {"user_id": user_id, "tag": tag, "restrict": restrict}
|
2022-04-29 16:29:12 +02:00
|
|
|
|
return self._pagination("/v1/user/bookmarks/illust", params)
|
2018-05-13 22:24:21 +02:00
|
|
|
|
|
2022-05-01 21:12:23 +02:00
|
|
|
|
@memcache(keyarg=1)
|
2018-05-13 22:24:21 +02:00
|
|
|
|
def user_detail(self, user_id):
|
|
|
|
|
params = {"user_id": user_id}
|
2022-04-29 16:29:12 +02:00
|
|
|
|
return self._call("/v1/user/detail", params)
|
2018-05-13 22:24:21 +02:00
|
|
|
|
|
2021-06-16 19:56:09 +02:00
|
|
|
|
def user_following(self, user_id, restrict="public"):
|
|
|
|
|
params = {"user_id": user_id, "restrict": restrict}
|
2022-04-29 16:29:12 +02:00
|
|
|
|
return self._pagination("/v1/user/following", params, "user_previews")
|
2019-12-26 23:42:42 +01:00
|
|
|
|
|
2018-05-18 15:30:06 +02:00
|
|
|
|
def user_illusts(self, user_id):
|
|
|
|
|
params = {"user_id": user_id}
|
2022-04-29 16:29:12 +02:00
|
|
|
|
return self._pagination("/v1/user/illusts", params)
|
2018-05-13 22:24:21 +02:00
|
|
|
|
|
|
|
|
|
def ugoira_metadata(self, illust_id):
|
|
|
|
|
params = {"illust_id": illust_id}
|
2022-04-29 16:29:12 +02:00
|
|
|
|
return self._call("/v1/ugoira/metadata", params)["ugoira_metadata"]
|
2018-05-13 22:24:21 +02:00
|
|
|
|
|
2018-05-07 20:05:44 +02:00
|
|
|
|
def _call(self, endpoint, params=None):
|
2022-04-29 16:29:12 +02:00
|
|
|
|
url = "https://app-api.pixiv.net" + endpoint
|
2018-05-07 20:05:44 +02:00
|
|
|
|
|
2022-04-29 16:29:12 +02:00
|
|
|
|
while True:
|
|
|
|
|
self.login()
|
|
|
|
|
response = self.extractor.request(url, params=params, fatal=False)
|
|
|
|
|
data = response.json()
|
|
|
|
|
|
|
|
|
|
if "error" not in data:
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
self.log.debug(data)
|
2018-05-07 20:05:44 +02:00
|
|
|
|
|
2019-12-28 22:06:58 +01:00
|
|
|
|
if response.status_code == 404:
|
|
|
|
|
raise exception.NotFoundError()
|
|
|
|
|
|
|
|
|
|
error = data["error"]
|
|
|
|
|
if "rate limit" in (error.get("message") or "").lower():
|
2022-04-29 16:29:12 +02:00
|
|
|
|
self.extractor.wait(seconds=300)
|
|
|
|
|
continue
|
2019-12-28 22:06:58 +01:00
|
|
|
|
|
2022-04-29 16:29:12 +02:00
|
|
|
|
raise exception.StopExtraction("API request failed: %s", error)
|
2018-05-07 20:05:44 +02:00
|
|
|
|
|
2019-12-26 23:42:42 +01:00
|
|
|
|
def _pagination(self, endpoint, params, key="illusts"):
|
2018-05-07 20:05:44 +02:00
|
|
|
|
while True:
|
|
|
|
|
data = self._call(endpoint, params)
|
2019-12-26 23:42:42 +01:00
|
|
|
|
yield from data[key]
|
2018-05-07 20:05:44 +02:00
|
|
|
|
|
|
|
|
|
if not data["next_url"]:
|
|
|
|
|
return
|
2018-05-18 16:55:24 +02:00
|
|
|
|
query = data["next_url"].rpartition("?")[2]
|
|
|
|
|
params = text.parse_query(query)
|
2018-10-12 22:26:27 +02:00
|
|
|
|
|
|
|
|
|
|
2019-03-14 22:21:49 +01:00
|
|
|
|
@cache(maxage=10*365*24*3600, keyarg=0)
|
2018-10-12 22:26:27 +02:00
|
|
|
|
def _refresh_token_cache(username):
|
|
|
|
|
return None
|