[hentaicosplays] use GalleryExtractor (#1473)

pull/1484/head
Mike Fährmann 3 years ago
parent d88e34f17e
commit dddda7d0e7
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -4,29 +4,23 @@
# it under the terms of the GNU General Public License version 2 as # it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation. # published by the Free Software Foundation.
""" """Extractors for https://hentai-cosplays.com/
Extractor for https://hentai-cosplays.com/ (also works for hentai-img.com and porn-images-xxx.com)"""
(also works for hentai-img.com and porn-images-xxx.com)
"""
from .common import Extractor, Message from .common import GalleryExtractor
from .. import text from .. import text
class HentaicosplaysGalleryExtractor(Extractor): class HentaicosplaysGalleryExtractor(GalleryExtractor):
""" """Extractor for image galleries from
Extractor for image galleries from hentai-cosplays.com, hentai-img.com, hentai-cosplays.com, hentai-img.com, and porn-images-xxx.com"""
and porn-images-xxx.com
"""
category = "hentaicosplays" category = "hentaicosplays"
subcategory = "gallery"
directory_fmt = ("{site}", "{title}") directory_fmt = ("{site}", "{title}")
filename_fmt = "{filename}.{extension}" filename_fmt = "{filename}.{extension}"
archive_fmt = "{title}_{filename}" archive_fmt = "{title}_{filename}"
root = "https://hentai-cosplays.com" pattern = r"((?:https?://)?(?:\w{2}\.)?" \
pattern = r"(?:https?://)?(?:\w{2}.)?" \ r"(hentai-cosplays|hentai-img|porn-images-xxx)\.com)/" \
r"(hentai-cosplays|hentai-img|porn-images-xxx)\.com/" \ r"(?:image|story)/([\w-]+)"
r"(?:image|story)/([\w-]+)(/\w+/\d+)?"
test = ( test = (
("https://hentai-cosplays.com/image/---devilism--tide-kurihara-/", { ("https://hentai-cosplays.com/image/---devilism--tide-kurihara-/", {
"pattern": r"https://static\d?.hentai-cosplays.com/upload/" "pattern": r"https://static\d?.hentai-cosplays.com/upload/"
@ -58,27 +52,21 @@ class HentaicosplaysGalleryExtractor(Extractor):
) )
def __init__(self, match): def __init__(self, match):
Extractor.__init__(self, match) root, self.site, path = match.groups()
self.site = match.group(1) self.root = text.ensure_http_scheme(root)
self.title = match.group(2) url = "{}/story/{}/".format(self.root, path)
GalleryExtractor.__init__(self, match, url)
def items(self):
url = "https://{}.com/story/{}/".format(
self.site, self.title)
page = self.request(url).text
data = self.metadata(page)
images = text.extract_iter(page,
'<amp-img class="auto-style" src="', '"')
yield Message.Version, 1
yield Message.Directory, data
for image in images:
yield Message.Url, image, text.nameext_from_url(image, data)
def metadata(self, page): def metadata(self, page):
"""Collect metadata for extractor-job"""
title = text.extract(page, "<title>", "</title>")[0] title = text.extract(page, "<title>", "</title>")[0]
title, _, _ = title.rpartition(" Story Viewer - ")
return { return {
"title": title, "title": text.unescape(title.rpartition(" Story Viewer - ")[0]),
"site": self.site, "site" : self.site,
} }
def images(self, page):
return [
(url, None)
for url in text.extract_iter(
page, '<amp-img class="auto-style" src="', '"')
]

Loading…
Cancel
Save