2022-02-11 23:44:51 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2021 David Hoppenbrouwers
|
2023-11-24 21:54:21 +01:00
|
|
|
# Copyright 2023 Mike Fährmann
|
2022-02-11 23:44:51 +01:00
|
|
|
#
|
|
|
|
# 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"
|
2024-08-02 15:39:11 +02:00
|
|
|
pattern = r"(?:https?://)?(?:www\.)?wallpapercave\.com/"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://wallpapercave.com/w/wp12345"
|
2022-02-11 23:44:51 +01:00
|
|
|
|
|
|
|
def items(self):
|
|
|
|
page = self.request(text.ensure_http_scheme(self.url)).text
|
2023-11-24 21:54:21 +01:00
|
|
|
|
|
|
|
path = None
|
2022-02-11 23:44:51 +01:00
|
|
|
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
|
2023-11-24 21:54:21 +01:00
|
|
|
|
|
|
|
if path is None:
|
|
|
|
try:
|
|
|
|
path = text.rextract(
|
|
|
|
page, 'href="', '"', page.index('id="tdownload"'))[0]
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
image = text.nameext_from_url(path)
|
|
|
|
yield Message.Directory, image
|
|
|
|
yield Message.Url, self.root + path, image
|
2024-08-02 15:39:11 +02:00
|
|
|
|
|
|
|
if path is None:
|
|
|
|
for wp in text.extract_iter(
|
|
|
|
page, 'class="wallpaper" id="wp', '</picture>'):
|
|
|
|
path = text.rextract(wp, ' src="', '"')[0]
|
|
|
|
if path:
|
|
|
|
image = text.nameext_from_url(path)
|
|
|
|
yield Message.Directory, image
|
|
|
|
yield Message.Url, self.root + path, image
|