# -*- coding: utf-8 -*- # Copyright 2024 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://agn.ph/""" from . import booru from .. import text from xml.etree import ElementTree import collections import re BASE_PATTERN = r"(?:https?://)?agn\.ph" class AgnphExtractor(booru.BooruExtractor): category = "agnph" root = "https://agn.ph" page_start = 1 per_page = 45 TAG_TYPES = { "a": "artist", "b": "copyright", "c": "character", "d": "species", "m": "general", } def _init(self): self.cookies.set("confirmed_age", "true", domain="agn.ph") def _prepare(self, post): post["date"] = text.parse_timestamp(post["created_at"]) post["status"] = post["status"].strip() post["has_children"] = ("true" in post["has_children"]) def _xml_to_dict(self, xml): return {element.tag: element.text for element in xml} def _pagination(self, url, params): params["api"] = "xml" if "page" in params: params["page"] = \ self.page_start + text.parse_int(params["page"]) - 1 else: params["page"] = self.page_start while True: data = self.request(url, params=params).text root = ElementTree.fromstring(data) yield from map(self._xml_to_dict, root) attrib = root.attrib if int(attrib["offset"]) + len(root) >= int(attrib["count"]): return params["page"] += 1 def _html(self, post): url = "{}/gallery/post/show/{}/".format(self.root, post["id"]) return self.request(url).text def _tags(self, post, page): tag_container = text.extr( page, '