| 1 |
|
| 2 |
|
| 3 |
n |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
"""Extractors for https://nsfwalbum.com/""" |
| 10 |
|
| 11 |
from .common import GalleryExtractor |
| 12 |
from .. import text, util |
| 13 |
|
| 14 |
|
| 15 |
class NsfwalbumExtractor(GalleryExtractor): |
| 16 |
"""Base class for nsfwalbum extractors""" |
| 17 |
category = "nsfwalbum" |
| 18 |
root = "https://nsfwalbum.com" |
| 19 |
archive_fmt = "{id}" |
| 20 |
referer = False |
| 21 |
|
| 22 |
def images(self, page): |
| 23 |
iframe = self.root + "/iframe_image.php?id=" |
| 24 |
backend = self.root + "/backend.php" |
| 25 |
retries = self._retries |
| 26 |
|
| 27 |
for image_id in self.image_ids(page): |
| 28 |
spirit = None |
| 29 |
tries = 0 |
| 30 |
|
| 31 |
while tries <= retries: |
| 32 |
try: |
| 33 |
if not spirit: |
| 34 |
spirit = self._annihilate(text.extract( |
| 35 |
self.request(iframe + image_id).text, |
| 36 |
'giraffe.annihilate("', '"')[0]) |
| 37 |
params = {"spirit": spirit, "photo": image_id} |
| 38 |
data = self.request_json(backend, params=params) |
| 39 |
break |
| 40 |
except Exception: |
| 41 |
tries += 1 |
| 42 |
else: |
| 43 |
self.log.warning("Unable to fetch image %s", image_id) |
| 44 |
continue |
| 45 |
|
| 46 |
yield data[0], { |
| 47 |
"id" : text.parse_int(image_id), |
| 48 |
"width" : text.parse_int(data[1]), |
| 49 |
"height": text.parse_int(data[2]), |
| 50 |
"_http_validate": self._validate_response, |
| 51 |
"_fallback": (f"{self.root}/imageProxy.php" |
| 52 |
f"?photoId={image_id}&spirit={spirit}",), |
| 53 |
} |
| 54 |
|
| 55 |
def _validate_response(self, response): |
| 56 |
return not response.url.endswith( |
| 57 |
("/no_image.jpg", "/placeholder.png", "/error.jpg")) |
| 58 |
|
| 59 |
def _annihilate(self, value, base=6): |
| 60 |
return "".join( |
| 61 |
chr(ord(char) ^ base) |
| 62 |
for char in value |
| 63 |
) |
| 64 |
|
| 65 |
|
| 66 |
class NsfwalbumAlbumExtractor(NsfwalbumExtractor): |
| 67 |
"""Extractor for image albums on nsfwalbum.com""" |
| 68 |
subcategory = "album" |
| 69 |
filename_fmt = "{album_id}_{num:>03}_{id}.{extension}" |
| 70 |
directory_fmt = ("{category}", "{album_id} {title}") |
| 71 |
pattern = r"(?:https?://)?(?:www\.)?nsfwalbum\.com(/album/(\d+))" |
| 72 |
example = "https://nsfwalbum.com/album/12345" |
| 73 |
|
| 74 |
def skip_files(self, num): |
| 75 |
self.start += num |
| 76 |
return num |
| 77 |
|
| 78 |
def metadata(self, page): |
| 79 |
extr = text.extract_from(page) |
| 80 |
return { |
| 81 |
"album_id": text.parse_int(self.groups[1]), |
| 82 |
"title" : text.unescape(extr('<h6>', '</h6>')), |
| 83 |
"models" : text.split_html(extr('"models"> Models:', '</div>')), |
| 84 |
"studio" : text.remove_html(extr('"models"> Studio:', '</div>')), |
| 85 |
} |
| 86 |
|
| 87 |
def image_ids(self, page): |
| 88 |
ids = text.extract_iter(page, 'data-img-id="', '"') |
| 89 |
if self.start > 1: |
| 90 |
util.advance(ids, self.start - 1) |
| 91 |
return ids |
| 92 |
|
| 93 |
|
| 94 |
class NsfwalbumImageExtractor(NsfwalbumExtractor): |
| 95 |
"""Extractor for single nsfwalbum.com images""" |
| 96 |
subcategory = "image" |
| 97 |
filename_fmt = "{id}.{extension}" |
| 98 |
directory_fmt = ("{category}",) |
| 99 |
pattern = r"(?:https?://)?(?:www\.)?nsfwalbum\.com/photo/(\d+)" |
| 100 |
example = "https://nsfwalbum.com/photo/12345" |
| 101 |
|
| 102 |
def metadata(self, _): |
| 103 |
return {} |
| 104 |
|
| 105 |
def image_ids(self, _): |
| 106 |
return (self.groups[0],) |