2019-06-22 22:43:09 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2021-01-29 22:20:31 +01:00
|
|
|
# Copyright 2019-2021 Mike Fährmann
|
2019-06-22 22:43:09 +02: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://nsfwalbum.com/"""
|
|
|
|
|
|
|
|
from .common import GalleryExtractor
|
|
|
|
from .. import text
|
|
|
|
|
|
|
|
|
|
|
|
class NsfwalbumAlbumExtractor(GalleryExtractor):
|
|
|
|
"""Extractor for image albums on nsfwalbum.com"""
|
|
|
|
category = "nsfwalbum"
|
|
|
|
subcategory = "album"
|
|
|
|
root = "https://nsfwalbum.com"
|
2019-10-16 18:12:07 +02:00
|
|
|
filename_fmt = "{album_id}_{num:>03}_{id}.{extension}"
|
2019-06-24 18:29:54 +02:00
|
|
|
directory_fmt = ("{category}", "{album_id} {title}")
|
2019-06-22 22:43:09 +02:00
|
|
|
archive_fmt = "{id}"
|
|
|
|
pattern = r"(?:https?://)?(?:www\.)?nsfwalbum\.com(/album/(\d+))"
|
2019-09-28 20:48:15 +02:00
|
|
|
test = ("https://nsfwalbum.com/album/401611", {
|
2019-06-22 22:43:09 +02:00
|
|
|
"range": "1-5",
|
2019-09-28 20:48:15 +02:00
|
|
|
"url": "b0481fc7fad5982da397b6359fbed8421b8ba284",
|
2019-10-16 18:12:07 +02:00
|
|
|
"keyword": "e98f9b0d473c00000831618d0235863b1dd78294",
|
2019-06-22 22:43:09 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
self.album_id = match.group(2)
|
|
|
|
GalleryExtractor.__init__(self, match)
|
|
|
|
|
|
|
|
def metadata(self, page):
|
|
|
|
extr = text.extract_from(page)
|
|
|
|
return {
|
|
|
|
"album_id": text.parse_int(self.album_id),
|
|
|
|
"title" : text.unescape(extr('<h6>', '</h6>')),
|
|
|
|
"models" : text.split_html(extr('"models"> Models:', '</div>')),
|
|
|
|
"studio" : text.remove_html(extr('"models"> Studio:', '</div>')),
|
|
|
|
}
|
|
|
|
|
|
|
|
def images(self, page):
|
|
|
|
iframe = self.root + "/iframe_image.php?id="
|
|
|
|
backend = self.root + "/backend.php"
|
|
|
|
for image_id in text.extract_iter(page, 'data-img-id="', '"'):
|
2021-01-29 22:20:31 +01:00
|
|
|
spirit = self._annihilate(text.extract(self.request(
|
|
|
|
iframe + image_id).text, 'giraffe.annihilate("', '"')[0])
|
|
|
|
params = {"spirit": spirit, "photo": image_id}
|
2019-06-22 22:43:09 +02:00
|
|
|
data = self.request(backend, params=params).json()
|
|
|
|
yield data[0], {
|
|
|
|
"id" : text.parse_int(image_id),
|
|
|
|
"width" : text.parse_int(data[1]),
|
|
|
|
"height": text.parse_int(data[2]),
|
2021-01-29 22:20:31 +01:00
|
|
|
"_http_validate": self._validate_response,
|
|
|
|
"_fallback": ("{}/imageProxy.php?photoId={}&spirit={}".format(
|
|
|
|
self.root, image_id, spirit),),
|
2019-06-22 22:43:09 +02:00
|
|
|
}
|
|
|
|
|
2021-01-29 22:20:31 +01:00
|
|
|
@staticmethod
|
|
|
|
def _validate_response(response):
|
|
|
|
return not response.request.url.endswith("/no_image.jpg")
|
|
|
|
|
2019-06-22 22:43:09 +02:00
|
|
|
@staticmethod
|
|
|
|
def _annihilate(value, base=6):
|
|
|
|
return "".join(
|
|
|
|
chr(ord(char) ^ base)
|
|
|
|
for char in value
|
|
|
|
)
|