| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# Copyright 2021 David Hoppenbrouwers |
| 4 |
# Copyright 2023-2025 Mike Fährmann |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License version 2 as |
| 8 |
# published by the Free Software Foundation. |
| 9 |
|
| 10 |
"""Extractors for https://wallpapercave.com/""" |
| 11 |
|
| 12 |
from .common import Extractor, Message |
| 13 |
from .. import text |
| 14 |
|
| 15 |
|
| 16 |
class WallpapercaveImageExtractor(Extractor): |
| 17 |
"""Extractor for images on wallpapercave.com""" |
| 18 |
category = "wallpapercave" |
| 19 |
subcategory = "image" |
| 20 |
root = "https://wallpapercave.com" |
| 21 |
pattern = r"(?:https?://)?(?:www\.)?wallpapercave\.com/" |
| 22 |
example = "https://wallpapercave.com/w/wp12345" |
| 23 |
|
| 24 |
def items(self): |
| 25 |
page = self.request(text.ensure_http_scheme(self.url)).text |
| 26 |
|
| 27 |
path = None |
| 28 |
for path in text.extract_iter(page, 'class="download" href="', '"'): |
| 29 |
image = text.nameext_from_url(path) |
| 30 |
yield Message.Directory, "", image |
| 31 |
yield Message.Url, self.root + path, image |
| 32 |
|
| 33 |
if path is None: |
| 34 |
try: |
| 35 |
path = text.rextr( |
| 36 |
page, 'href="', '"', page.index('id="tdownload"'), None) |
| 37 |
except Exception: |
| 38 |
pass |
| 39 |
else: |
| 40 |
image = text.nameext_from_url(path) |
| 41 |
yield Message.Directory, "", image |
| 42 |
yield Message.Url, self.root + path, image |
| 43 |
|
| 44 |
if path is None: |
| 45 |
for wp in text.extract_iter( |
| 46 |
page, 'class="wallpaper" id="wp', '</picture>'): |
| 47 |
if path := text.rextr(wp, ' src="', '"'): |
| 48 |
image = text.nameext_from_url(path) |
| 49 |
yield Message.Directory, "", image |
| 50 |
yield Message.Url, self.root + path, image |