mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 10:42:34 +01:00
[whentai] add single image extractor
This commit is contained in:
parent
a0f56b2c54
commit
46a3f666df
@ -64,3 +64,41 @@ class WhentaiUserExtractor(Extractor):
|
||||
"title": title,
|
||||
}
|
||||
data["from"] = imageid
|
||||
|
||||
|
||||
class WhentaiImageExtractor(Extractor):
|
||||
"""Extractor for single images from whentai.com"""
|
||||
category = "whentai"
|
||||
subcategory = "image"
|
||||
directory_fmt = ["{category}", "{user}"]
|
||||
filename_fmt = "{category}_{image-id:>05}_{title}.{extension}"
|
||||
pattern = [r"(?:https?://)?(?:www\.)?whentai\.com/view/(\d+)"]
|
||||
|
||||
def __init__(self, match):
|
||||
Extractor.__init__(self)
|
||||
self.imageid = match.group(1)
|
||||
self.url = "http://whentai.com/view/" + self.imageid
|
||||
self.session.headers["Referer"] = self.url
|
||||
|
||||
def items(self):
|
||||
data = self.get_image_metadata()
|
||||
url = self.get_image_url(data["user"])
|
||||
yield Message.Version, 1
|
||||
yield Message.Directory, data
|
||||
yield Message.Url, url, data
|
||||
|
||||
def get_image_url(self, user):
|
||||
data = {"type": "image", "cnt": "1", "paid": "0", "post": "1",
|
||||
"from": str(int(self.imageid) + 1), "author": user.replace("_", " ")}
|
||||
page = self.request("http://whentai.com/ajax/getuploadslist",
|
||||
method="POST", data=data).text
|
||||
return text.extract(page, 'src="', '"')[0].replace("/t2", "/")
|
||||
|
||||
def get_image_metadata(self):
|
||||
"""Collect url and metadata for image"""
|
||||
page = self.request(self.url).text
|
||||
return text.extract_all(page, (
|
||||
("title" , '<li class="box1">\n', ' </li>'),
|
||||
("user-id", '/users/', '/'),
|
||||
("user" , '', '"'),
|
||||
), values={"image-id": self.imageid})[0]
|
||||
|
Loading…
Reference in New Issue
Block a user