Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mikf
GitHub Repository: mikf/gallery-dl
Path: blob/master/gallery_dl/extractor/desktopography.py
5399 views
1
# -*- coding: utf-8 -*-
2
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License version 2 as
5
# published by the Free Software Foundation.
6
7
"""Extractors for https://desktopography.net/"""
8
9
from .common import Extractor, Message
10
from .. import text
11
12
BASE_PATTERN = r"(?:https?://)?desktopography\.net"
13
14
15
class DesktopographyExtractor(Extractor):
16
"""Base class for desktopography extractors"""
17
category = "desktopography"
18
archive_fmt = "{filename}"
19
root = "https://desktopography.net"
20
21
22
class DesktopographySiteExtractor(DesktopographyExtractor):
23
"""Extractor for all desktopography exhibitions """
24
subcategory = "site"
25
pattern = BASE_PATTERN + r"/$"
26
example = "https://desktopography.net/"
27
28
def items(self):
29
page = self.request(self.root).text
30
data = {"_extractor": DesktopographyExhibitionExtractor}
31
32
for exhibition_year in text.extract_iter(
33
page,
34
'<a href="https://desktopography.net/exhibition-',
35
'/">'):
36
37
url = self.root + "/exhibition-" + exhibition_year + "/"
38
yield Message.Queue, url, data
39
40
41
class DesktopographyExhibitionExtractor(DesktopographyExtractor):
42
"""Extractor for a yearly desktopography exhibition"""
43
subcategory = "exhibition"
44
pattern = BASE_PATTERN + r"/exhibition-([^/?#]+)/"
45
example = "https://desktopography.net/exhibition-2020/"
46
47
def __init__(self, match):
48
DesktopographyExtractor.__init__(self, match)
49
self.year = match[1]
50
51
def items(self):
52
url = f"{self.root}/exhibition-{self.year}/"
53
base_entry_url = "https://desktopography.net/portfolios/"
54
page = self.request(url).text
55
56
data = {
57
"_extractor": DesktopographyEntryExtractor,
58
"year": self.year,
59
}
60
61
for entry_url in text.extract_iter(
62
page,
63
'<a class="overlay-background" href="' + base_entry_url,
64
'">'):
65
66
url = base_entry_url + entry_url
67
yield Message.Queue, url, data
68
69
70
class DesktopographyEntryExtractor(DesktopographyExtractor):
71
"""Extractor for all resolutions of a desktopography wallpaper"""
72
subcategory = "entry"
73
pattern = BASE_PATTERN + r"/portfolios/([\w-]+)"
74
example = "https://desktopography.net/portfolios/NAME/"
75
76
def __init__(self, match):
77
DesktopographyExtractor.__init__(self, match)
78
self.entry = match[1]
79
80
def items(self):
81
url = f"{self.root}/portfolios/{self.entry}"
82
page = self.request(url).text
83
84
entry_data = {"entry": self.entry}
85
yield Message.Directory, entry_data
86
87
for image_data in text.extract_iter(
88
page,
89
'<a target="_blank" href="https://desktopography.net',
90
'">'):
91
92
path, _, filename = image_data.partition(
93
'" class="wallpaper-button" download="')
94
text.nameext_from_url(filename, entry_data)
95
yield Message.Url, self.root + path, entry_data
96
97