Debian Codegraph @

gallery_dl/extractor/vanillarock.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://vanilla-rock.com/"""
10
11 from .common import Extractor, Message
12 from .. import text
13
14
15 class VanillarockExtractor(Extractor):
16 """Base class for vanillarock extractors"""
17 category = "vanillarock"
18 root = "https://vanilla-rock.com"
19
20 def __init__(self, match):
21 Extractor.__init__(self, match)
22 self.path = match[1]
23
24
25 class VanillarockPostExtractor(VanillarockExtractor):
26 """Extractor for blogposts on vanilla-rock.com"""
27 subcategory = "post"
28 directory_fmt = ("{category}", "{path}")
29 filename_fmt = "{num:>02}.{extension}"
30 archive_fmt = "{filename}"
31 pattern = (r"(?:https?://)?(?:www\.)?vanilla-rock\.com"
32 r"(/(?!category/|tag/)[^/?#]+)/?$")
33 example = "https://vanilla-rock.com/TITLE"
34
35 def items(self):
36 extr = text.extract_from(self.request(self.root + self.path).text)
37 name = extr('<h1 class="entry-title">', "<")
38
39 imgs = []
40 while True:
41 img = extr('<div class="main-img">', '</div>')
42 if not img:
43 break
44 imgs.append(text.extr(img, 'href="', '"'))
45
46 data = {
47 "count": len(imgs),
48 "title": text.unescape(name),
49 "path" : self.path.strip("/"),
50 "date" : self.parse_datetime_iso(extr(
51 '<div class="date">', '</div>')),
52 "tags" : text.split_html(extr(
53 '<div class="cat-tag">', '</div>'))[::2],
54 }
55
56 yield Message.Directory, "", data
57 for data["num"], url in enumerate(imgs, 1):
58 yield Message.Url, url, text.nameext_from_url(url, data)
59
60
61 class VanillarockTagExtractor(VanillarockExtractor):
62 """Extractor for vanillarock blog posts by tag or category"""
63 subcategory = "tag"
64 pattern = (r"(?:https?://)?(?:www\.)?vanilla-rock\.com"
65 r"(/(?:tag|category)/[^?#]+)")
66 example = "https://vanilla-rock.com/tag/TAG"
67
68 def items(self):
69 url = self.root + self.path
70 data = {"_extractor": VanillarockPostExtractor}
71
72 while url:
73 extr = text.extract_from(self.request(url).text)
74 while True:
75 post = extr('<h2 class="entry-title">', '</h2>')
76 if not post:
77 break
78 yield Message.Queue, text.extr(post, 'href="', '"'), data
79 url = text.unescape(extr('class="next page-numbers" href="', '"'))