2016-08-01 15:36:56 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-09-10 22:20:47 +02:00
|
|
|
# Copyright 2016-2017 Mike Fährmann
|
2016-08-01 15:36:56 +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.
|
|
|
|
|
|
|
|
"""Extract images from https://luscious.net/"""
|
|
|
|
|
2017-08-02 19:58:13 +02:00
|
|
|
from .common import AsynchronousExtractor, Message
|
2017-09-12 15:46:21 +02:00
|
|
|
from .. import text, util, exception
|
2016-08-01 15:36:56 +02:00
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2017-08-02 19:58:13 +02:00
|
|
|
class LusciousAlbumExtractor(AsynchronousExtractor):
|
2016-09-12 10:20:57 +02:00
|
|
|
"""Extractor for image albums from luscious.net"""
|
2016-08-01 15:36:56 +02:00
|
|
|
category = "luscious"
|
2016-09-12 10:20:57 +02:00
|
|
|
subcategory = "album"
|
2017-09-10 22:20:47 +02:00
|
|
|
directory_fmt = ["{category}", "{gallery_id} {title}"]
|
|
|
|
filename_fmt = "{category}_{gallery_id}_{num:>03}.{extension}"
|
2017-01-03 15:03:36 +01:00
|
|
|
pattern = [(r"(?:https?://)?(?:www\.)?luscious\.net/"
|
|
|
|
r"(?:c/[^/]+/)?(?:pictures/album|albums)/([^/]+_(\d+))")]
|
|
|
|
test = [
|
2017-02-01 00:53:19 +01:00
|
|
|
(("https://luscious.net/c/hentai_manga/albums/"
|
|
|
|
"okinami-no-koigokoro_277031/view/"), {
|
2017-01-03 15:03:36 +01:00
|
|
|
"url": "7e4984a271a1072ac6483e4228a045895aff86f3",
|
2017-09-10 22:20:47 +02:00
|
|
|
"keyword": "76e099479b180420fd5cf820f00c52fe07fda884",
|
2017-01-03 15:03:36 +01:00
|
|
|
"content": "b3a747a6464509440bd0ff6d1267e6959f8d6ff3",
|
|
|
|
}),
|
2017-08-02 19:58:13 +02:00
|
|
|
("https://luscious.net/albums/virgin-killer-sweater_282582/", {
|
|
|
|
"url": "01e2d7dd6eecea0152610f2446a6b1d60519c8bd",
|
2017-09-10 22:20:47 +02:00
|
|
|
"keyword": "02624ff1097260e2a3c1b220afc92ea4c6b109b3",
|
2017-01-03 15:03:36 +01:00
|
|
|
}),
|
2017-08-02 19:58:13 +02:00
|
|
|
("https://luscious.net/albums/okinami-no-koigokoro_277031/", None),
|
2017-01-03 15:03:36 +01:00
|
|
|
]
|
2016-08-01 15:36:56 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2017-08-02 19:58:13 +02:00
|
|
|
AsynchronousExtractor.__init__(self)
|
2017-01-03 15:03:36 +01:00
|
|
|
self.gpart, self.gid = match.groups()
|
2016-08-01 15:36:56 +02:00
|
|
|
|
|
|
|
def items(self):
|
2017-08-02 19:58:13 +02:00
|
|
|
url = "https://luscious.net/albums/" + self.gpart + "/"
|
|
|
|
page = self.request(url).text
|
|
|
|
data = self.get_metadata(page)
|
2016-08-01 15:36:56 +02:00
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data
|
2017-08-02 19:58:13 +02:00
|
|
|
for url, image in self.get_images(page):
|
2016-08-01 15:36:56 +02:00
|
|
|
image.update(data)
|
|
|
|
yield Message.Url, url, image
|
|
|
|
|
2017-08-02 19:58:13 +02:00
|
|
|
def get_metadata(self, page):
|
2016-08-01 15:36:56 +02:00
|
|
|
"""Collect metadata for extractor-job"""
|
2017-01-03 15:03:36 +01:00
|
|
|
data = text.extract_all(page, (
|
|
|
|
("tags" , '<meta name="keywords" content="', '"'),
|
2017-09-01 16:29:52 +02:00
|
|
|
("title" , '"og:title" content="', '"'),
|
2016-08-01 15:36:56 +02:00
|
|
|
(None , '<li class="user_info">', ''),
|
|
|
|
("count" , '<p>', ' '),
|
|
|
|
(None , '<p>Section:', ''),
|
|
|
|
("section" , '>', '<'),
|
2017-01-03 15:03:36 +01:00
|
|
|
("language", '<p>Language:', ' '),
|
2017-09-10 22:20:47 +02:00
|
|
|
), values={"gallery_id": self.gid})[0]
|
2017-08-08 19:26:13 +02:00
|
|
|
data["lang"] = util.language_to_code(data["language"])
|
2017-08-04 15:01:10 +02:00
|
|
|
try:
|
2017-08-08 19:26:13 +02:00
|
|
|
data["artist"] = text.extract(data["tags"], "rtist: ", ",")[0]
|
2017-08-04 15:01:10 +02:00
|
|
|
except AttributeError:
|
|
|
|
data["artist"] = None
|
2016-08-01 15:36:56 +02:00
|
|
|
return data
|
|
|
|
|
2017-08-02 19:58:13 +02:00
|
|
|
def get_images(self, page):
|
2017-01-03 15:03:36 +01:00
|
|
|
"""Collect image-urls and -metadata"""
|
2017-08-02 19:58:13 +02:00
|
|
|
extr = text.extract
|
|
|
|
num = 1
|
|
|
|
pos = page.find('<div class="album_cover_item">')
|
|
|
|
url = extr(page, '<a href="', '"', pos)[0]
|
2017-09-12 15:46:21 +02:00
|
|
|
self._check_high_load(page, url)
|
|
|
|
while url and not url.endswith("/more_like_this/"):
|
2017-08-02 19:58:13 +02:00
|
|
|
page = self.request("https://luscious.net" + url).text
|
|
|
|
imgid, pos = extr(url , '/id/', '/')
|
|
|
|
url , pos = extr(page, '<link rel="next" href="', '"')
|
2017-09-12 15:46:21 +02:00
|
|
|
self._check_high_load(page, url)
|
2017-08-02 19:58:13 +02:00
|
|
|
name , pos = extr(page, '<h1 id="picture_title">', '</h1>', pos)
|
|
|
|
_ , pos = extr(page, '<ul class="image_option_icons">', '', pos)
|
|
|
|
iurl , pos = extr(page, '<li><a href="', '"', pos+100)
|
|
|
|
|
|
|
|
yield iurl, {
|
|
|
|
"num": num,
|
|
|
|
"name": name,
|
|
|
|
"extension": iurl.rpartition(".")[2],
|
2017-09-10 22:20:47 +02:00
|
|
|
"image_id": imgid,
|
2017-08-02 19:58:13 +02:00
|
|
|
}
|
|
|
|
num += 1
|
2017-09-12 15:46:21 +02:00
|
|
|
|
|
|
|
def _check_high_load(self, page, url):
|
|
|
|
if not url and "<h1>High Load</h1>" in page:
|
|
|
|
self.log.error('"High Load!" - unable to continue')
|
|
|
|
raise exception.StopExtraction()
|