| 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://lensdump.com/""" |
| 8 |
|
| 9 |
from .common import GalleryExtractor, Extractor, Message |
| 10 |
from .. import text, util |
| 11 |
|
| 12 |
BASE_PATTERN = r"(?:https?://)?lensdump\.com" |
| 13 |
|
| 14 |
|
| 15 |
class LensdumpBase(): |
| 16 |
"""Base class for lensdump extractors""" |
| 17 |
category = "lensdump" |
| 18 |
root = "https://lensdump.com" |
| 19 |
|
| 20 |
def _pagination(self, page, begin, end): |
| 21 |
while True: |
| 22 |
yield from text.extract_iter(page, begin, end) |
| 23 |
|
| 24 |
next = text.extr(page, ' data-pagination="next"', '>') |
| 25 |
if not next: |
| 26 |
return |
| 27 |
|
| 28 |
url = text.urljoin(self.root, text.extr(next, 'href="', '"')) |
| 29 |
page = self.request(url).text |
| 30 |
|
| 31 |
|
| 32 |
class LensdumpAlbumExtractor(LensdumpBase, GalleryExtractor): |
| 33 |
subcategory = "album" |
| 34 |
pattern = BASE_PATTERN + r"/a/(\w+)(?:/?\?([^#]+))?" |
| 35 |
example = "https://lensdump.com/a/ID" |
| 36 |
|
| 37 |
def __init__(self, match): |
| 38 |
self.gallery_id, query = match.groups() |
| 39 |
if query: |
| 40 |
url = f"{self.root}/a/{self.gallery_id}/?{query}" |
| 41 |
else: |
| 42 |
url = f"{self.root}/a/{self.gallery_id}" |
| 43 |
GalleryExtractor.__init__(self, match, url) |
| 44 |
|
| 45 |
def metadata(self, page): |
| 46 |
return { |
| 47 |
"gallery_id": self.gallery_id, |
| 48 |
"title": text.unescape(text.extr( |
| 49 |
page, 'property="og:title" content="', '"').strip()) |
| 50 |
} |
| 51 |
|
| 52 |
def images(self, page): |
| 53 |
for image in self._pagination(page, ' class="list-item ', '>'): |
| 54 |
|
| 55 |
data = util.json_loads(text.unquote( |
| 56 |
text.extr(image, "data-object='", "'") or |
| 57 |
text.extr(image, 'data-object="', '"'))) |
| 58 |
image_id = data.get("name") |
| 59 |
image_url = data.get("url") |
| 60 |
image_title = data.get("title") |
| 61 |
if image_title is not None: |
| 62 |
image_title = text.unescape(image_title) |
| 63 |
|
| 64 |
yield (image_url, { |
| 65 |
"id" : image_id, |
| 66 |
"url" : image_url, |
| 67 |
"title" : image_title, |
| 68 |
"name" : data.get("filename"), |
| 69 |
"filename" : image_id, |
| 70 |
"extension": data.get("extension"), |
| 71 |
"width" : text.parse_int(data.get("width")), |
| 72 |
"height" : text.parse_int(data.get("height")), |
| 73 |
}) |
| 74 |
|
| 75 |
|
| 76 |
class LensdumpAlbumsExtractor(LensdumpBase, Extractor): |
| 77 |
"""Extractor for album list from lensdump.com""" |
| 78 |
subcategory = "albums" |
| 79 |
pattern = BASE_PATTERN + r"/(?![ai]/)([^/?#]+)(?:/?\?([^#]+))?" |
| 80 |
example = "https://lensdump.com/USER" |
| 81 |
|
| 82 |
def items(self): |
| 83 |
user, query = self.groups |
| 84 |
url = f"{self.root}/{user}/" |
| 85 |
if query: |
| 86 |
params = text.parse_query(query) |
| 87 |
else: |
| 88 |
params = {"sort": "date_asc", "page": "1"} |
| 89 |
page = self.request(url, params=params).text |
| 90 |
|
| 91 |
data = {"_extractor": LensdumpAlbumExtractor} |
| 92 |
for album_path in self._pagination(page, 'data-url-short="', '"'): |
| 93 |
album_url = text.urljoin(self.root, album_path) |
| 94 |
yield Message.Queue, album_url, data |
| 95 |
|
| 96 |
|
| 97 |
class LensdumpImageExtractor(LensdumpBase, Extractor): |
| 98 |
"""Extractor for individual images on lensdump.com""" |
| 99 |
subcategory = "image" |
| 100 |
filename_fmt = "{category}_{id}{title:?_//}.{extension}" |
| 101 |
directory_fmt = ("{category}",) |
| 102 |
archive_fmt = "{id}" |
| 103 |
pattern = (r"(?:https?://)?(?:(?:i\d?\.)?lensdump\.com|\w\.l3n\.co)" |
| 104 |
r"/(?:i/)?(\w+)") |
| 105 |
example = "https://lensdump.com/i/ID" |
| 106 |
|
| 107 |
def items(self): |
| 108 |
key = self.groups[0] |
| 109 |
url = f"{self.root}/i/{key}" |
| 110 |
extr = text.extract_from(self.request(url).text) |
| 111 |
|
| 112 |
data = { |
| 113 |
"id" : key, |
| 114 |
"title" : text.unescape(extr( |
| 115 |
'property="og:title" content="', '"')), |
| 116 |
"url" : extr( |
| 117 |
'property="og:image" content="', '"'), |
| 118 |
"width" : text.parse_int(extr( |
| 119 |
'property="image:width" content="', '"')), |
| 120 |
"height": text.parse_int(extr( |
| 121 |
'property="image:height" content="', '"')), |
| 122 |
"date" : self.parse_datetime_iso(extr('<span title="', '"')), |
| 123 |
} |
| 124 |
|
| 125 |
text.nameext_from_url(data["url"], data) |
| 126 |
yield Message.Directory, "", data |
| 127 |
yield Message.Url, data["url"], data |