Debian Codegraph @

gallery_dl/extractor/fuskator.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2019-2025 Mike Fährmann
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation.
8
9 """Extractors for https://fuskator.com/"""
10
11 from .common import GalleryExtractor, Extractor, Message
12 from .. import text
13 import time
14
15
16 class FuskatorGalleryExtractor(GalleryExtractor):
17 """Extractor for image galleries on fuskator.com"""
18 category = "fuskator"
19 root = "https://fuskator.com"
20 pattern = r"(?:https?://)?fuskator\.com/(?:thumbs|expanded)/([^/?#]+)"
21 example = "https://fuskator.com/thumbs/ID/"
22
23 def __init__(self, match):
24 self.gallery_hash = match[1]
25 url = f"{self.root}/thumbs/{self.gallery_hash}/index.html"
26 GalleryExtractor.__init__(self, match, url)
27
28 def metadata(self, page):
29 headers = {
30 "Referer" : self.page_url,
31 "X-Requested-With": "XMLHttpRequest",
32 }
33 auth = self.request(
34 self.root + "/ajax/auth.aspx", method="POST", headers=headers,
35 ).text
36
37 params = {
38 "X-Auth": auth,
39 "hash" : self.gallery_hash,
40 "_" : int(time.time()),
41 }
42 self.data = data = self.request_json(
43 self.root + "/ajax/gal.aspx", params=params, headers=headers)
44
45 title = text.extr(page, "<title>", "</title>").strip()
46 title, _, gallery_id = title.rpartition("#")
47
48 return {
49 "gallery_id" : text.parse_int(gallery_id),
50 "gallery_hash": self.gallery_hash,
51 "title" : text.unescape(title[:-15]),
52 "views" : data.get("hits"),
53 "score" : data.get("rating"),
54 "tags" : (data.get("tags") or "").split(","),
55 }
56
57 def images(self, page):
58 return [
59 ("https:" + image["imageUrl"], image)
60 for image in self.data["images"]
61 ]
62
63
64 class FuskatorSearchExtractor(Extractor):
65 """Extractor for search results on fuskator.com"""
66 category = "fuskator"
67 subcategory = "search"
68 root = "https://fuskator.com"
69 pattern = r"(?:https?://)?fuskator\.com(/(?:search|page)/.+)"
70 example = "https://fuskator.com/search/TAG/"
71
72 def __init__(self, match):
73 Extractor.__init__(self, match)
74 self.path = match[1]
75
76 def items(self):
77 url = self.root + self.path
78 data = {"_extractor": FuskatorGalleryExtractor}
79
80 while True:
81 page = self.request(url).text
82 for path in text.extract_iter(
83 page, 'class="pic_pad"><a href="', '"'):
84 yield Message.Queue, self.root + path, data
85
86 pages = text.extr(page, 'class="pages"><span>', '>&gt;&gt;<')
87 if not pages:
88 return
89 url = self.root + text.rextr(pages, 'href="', '"')