# -*- coding: utf-8 -*- # Copyright 2021 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 # published by the Free Software Foundation. """Extractors for https://kemono.party/""" from .common import Extractor, Message from .. import text import itertools import re BASE_PATTERN = r"(?:https?://)?kemono\.party/([^/?#]+)/user/([^/?#]+)" class KemonopartyExtractor(Extractor): """Base class for kemonoparty extractors""" category = "kemonoparty" root = "https://kemono.party" directory_fmt = ("{category}", "{service}", "{user}") filename_fmt = "{id}_{title}_{num:>02}_{filename}.{extension}" archive_fmt = "{service}_{user}_{id}_{num}" cookiedomain = ".kemono.party" _warning = True def items(self): if self._warning: if not self._check_cookies(("__ddg1", "__ddg2")): self.log.warning("no DDoS-GUARD cookies set (__ddg1, __ddg2)") KemonopartyExtractor._warning = False find_inline = re.compile(r'src="(/inline/[^"]+)').findall skip_service = \ "patreon" if self.config("patreon-skip-file", True) else None if self.config("metadata"): username = text.unescape(text.extract( self.request(self.user_url).text, ' data.kemono.party ("https://kemono.party/gumroad/user/trylsc/post/IURjT", { "pattern": r"https://kemono\.party/(file|attachment)s" r"/gumroad/trylsc/IURjT/", }), # username (#1548, #1652) ("https://kemono.party/gumroad/user/3252870377455/post/aJnAH", { "options": (("metadata", True),), "keyword": {"username": "Kudalyn's Creations"}, }), # skip patreon main file (#1667, #1689) ("https://kemono.party/patreon/user/4158582/post/32099982", { "count": 2, "keyword": {"type": "attachment"}, }), ("https://kemono.party/subscribestar/user/alcorart/post/184330"), ) def __init__(self, match): KemonopartyExtractor.__init__(self, match) service, user_id, post_id = match.groups() self.api_url = "{}/api/{}/user/{}/post/{}".format( self.root, service, user_id, post_id) self.user_url = "{}/{}/user/{}".format(self.root, service, user_id) def posts(self): posts = self.request(self.api_url).json() return (posts[0],) if len(posts) > 1 else posts