# -*- coding: utf-8 -*- # Copyright 2014-2018 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. """Extract images from https://chan.sankakucomplex.com/""" from .common import SharedConfigExtractor, Message from .. import text, util, exception from ..cache import cache import collections import random import time import re class SankakuExtractor(SharedConfigExtractor): """Base class for sankaku extractors""" basecategory = "booru" category = "sankaku" filename_fmt = "{category}_{id}_{md5}.{extension}" cookienames = ("login", "pass_hash") cookiedomain = "chan.sankakucomplex.com" subdomain = "chan" def __init__(self): SharedConfigExtractor.__init__(self) self.root = "https://" + self.cookiedomain self.logged_in = True self.start_page = 1 self.start_post = 0 self.extags = self.config("tags", False) self.wait_min = self.config("wait-min", 3.0) self.wait_max = self.config("wait-max", 6.0) if self.wait_max < self.wait_min: self.wait_max = self.wait_min def items(self): self.login() data = self.get_metadata() yield Message.Version, 1 yield Message.Directory, data for post_id in util.advance(self.get_posts(), self.start_post): self.wait() post = self.get_post_data(post_id) url = post["file_url"] post.update(data) yield Message.Url, url, text.nameext_from_url(url, post) def skip(self, num): self.start_post += num return num def get_metadata(self): """Return general metadata""" return {} def get_posts(self): """Return an iterable containing all relevant post ids""" def get_post_data(self, post_id, extr=text.extract): """Extract metadata of a single post""" url = self.root + "/post/show/" + post_id page = self.request(url, retries=10).text tags , pos = extr(page, "