1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# -*- coding: utf-8 -*-
# Copyright 2021 David Hoppenbrouwers
# Copyright 2023-2025 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.
"""Extractors for https://wallpapercave.com/"""
from .common import Extractor, Message
from .. import text
class WallpapercaveImageExtractor(Extractor):
"""Extractor for images on wallpapercave.com"""
category = "wallpapercave"
subcategory = "image"
root = "https://wallpapercave.com"
pattern = r"(?:https?://)?(?:www\.)?wallpapercave\.com/"
example = "https://wallpapercave.com/w/wp12345"
def items(self):
page = self.request(text.ensure_http_scheme(self.url)).text
path = None
for path in text.extract_iter(page, 'class="download" href="', '"'):
image = text.nameext_from_url(path)
yield Message.Directory, image
yield Message.Url, self.root + path, image
if path is None:
try:
path = text.rextr(
page, 'href="', '"', page.index('id="tdownload"'), None)
except Exception:
pass
else:
image = text.nameext_from_url(path)
yield Message.Directory, image
yield Message.Url, self.root + path, image
if path is None:
for wp in text.extract_iter(
page, 'class="wallpaper" id="wp', '</picture>'):
if path := text.rextr(wp, ' src="', '"'):
image = text.nameext_from_url(path)
yield Message.Directory, image
yield Message.Url, self.root + path, image
|