Debian Codegraph @

gallery_dl/extractor/architizer.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2021-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://architizer.com/"""
10
11 from .common import GalleryExtractor, Extractor, Message
12 from .. import text
13
14
15 class ArchitizerProjectExtractor(GalleryExtractor):
16 """Extractor for project pages on architizer.com"""
17 category = "architizer"
18 subcategory = "project"
19 root = "https://architizer.com"
20 directory_fmt = ("{category}", "{firm}", "{title}")
21 filename_fmt = "{filename}.{extension}"
22 archive_fmt = "{gid}_{num}"
23 pattern = r"(?:https?://)?architizer\.com/projects/([^/?#]+)"
24 example = "https://architizer.com/projects/NAME/"
25
26 def __init__(self, match):
27 url = f"{self.root}/projects/{match[1]}/"
28 GalleryExtractor.__init__(self, match, url)
29
30 def metadata(self, page):
31 extr = text.extract_from(page)
32 extr('id="Pages"', "")
33
34 return {
35 "title" : extr("data-name='", "'"),
36 "slug" : extr("data-slug='", "'"),
37 "gid" : extr("data-gid='", "'").rpartition(".")[2],
38 "firm" : extr("data-firm-leaders-str='", "'"),
39 "location" : extr("<h2>", "<").strip(),
40 "type" : text.unescape(text.remove_html(extr(
41 '<div class="title">Type</div>', '<br'))),
42 "status" : text.remove_html(extr(
43 '<div class="title">STATUS</div>', '</')),
44 "year" : text.remove_html(extr(
45 '<div class="title">YEAR</div>', '</')),
46 "size" : text.remove_html(extr(
47 '<div class="title">SIZE</div>', '</')),
48 "description": text.unescape(extr(
49 '<span class="copy js-copy">', '</span></div>')
50 .replace("<br />", "\n")),
51 }
52
53 def images(self, page):
54 return [
55 (url, None)
56 for url in text.extract_iter(
57 page, 'property="og:image:secure_url" content="', "?")
58 ]
59
60
61 class ArchitizerFirmExtractor(Extractor):
62 """Extractor for all projects of a firm"""
63 category = "architizer"
64 subcategory = "firm"
65 root = "https://architizer.com"
66 pattern = r"(?:https?://)?architizer\.com/firms/([^/?#]+)"
67 example = "https://architizer.com/firms/NAME/"
68
69 def __init__(self, match):
70 Extractor.__init__(self, match)
71 self.firm = match[1]
72
73 def items(self):
74 url = url = f"{self.root}/firms/{self.firm}/?requesting_merlin=pages"
75 page = self.request(url).text
76 data = {"_extractor": ArchitizerProjectExtractor}
77
78 for project in text.extract_iter(page, '<a href="/projects/', '"'):
79 if not project.startswith("q/"):
80 url = f"{self.root}/projects/{project}"
81 yield Message.Queue, url, data