[tmohentai] inherit from GalleryExtractor. refactor metadata.
This commit is contained in:
@@ -6,14 +6,15 @@
|
|||||||
|
|
||||||
"""Extractors for https://tmohentai.com/"""
|
"""Extractors for https://tmohentai.com/"""
|
||||||
|
|
||||||
from .common import Extractor, Message
|
from .common import GalleryExtractor, Message
|
||||||
from .. import text
|
from .. import text
|
||||||
|
|
||||||
BASE_PATTERN = r'(?:https?://)?tmohentai\.com'
|
BASE_PATTERN = r'(?:https?://)?tmohentai\.com'
|
||||||
|
|
||||||
|
|
||||||
class TmohentaiExtractor(Extractor):
|
class TmohentaiGalleryExtractor(GalleryExtractor):
|
||||||
category = 'tmohentai'
|
category = 'tmohentai'
|
||||||
|
subcategory = 'gallery'
|
||||||
root = 'http://tmohentai.com'
|
root = 'http://tmohentai.com'
|
||||||
directory_fmt = ('{category}', '{title}')
|
directory_fmt = ('{category}', '{title}')
|
||||||
filename_fmt = '{title}_{filename}.{extension}'
|
filename_fmt = '{title}_{filename}.{extension}'
|
||||||
@@ -22,71 +23,51 @@ class TmohentaiExtractor(Extractor):
|
|||||||
example = 'https://tmohentai.com/contents/12345a67b89c0'
|
example = 'https://tmohentai.com/contents/12345a67b89c0'
|
||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
Extractor.__init__(self, match)
|
GalleryExtractor.__init__(self, match)
|
||||||
self.contents = match.group(2)
|
self.contents = match.group(2)
|
||||||
self.reader = match.group(3)
|
self.reader = match.group(3)
|
||||||
self.id_string = match.group(4)
|
self.id_string = match.group(4)
|
||||||
|
|
||||||
def parse_location(self):
|
def parse_location(self):
|
||||||
if self.contents:
|
url = self.url
|
||||||
url = '{}/reader/{}/paginated'.format(self.root, self.id_string)
|
if self.reader:
|
||||||
else:
|
url = '{}/contents/{}'.format(self.root, self.id_string)
|
||||||
url_str = self.url.rpartition('/')
|
|
||||||
if url_str[-1].isdigit():
|
|
||||||
url = url_str[0]
|
|
||||||
else:
|
|
||||||
url = self.url
|
|
||||||
return url
|
return url
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_file_info(page_src):
|
|
||||||
file = text.extr(page_src, 'data-original="', '"')
|
|
||||||
file_loc, _, file_name = file.rpartition('/')
|
|
||||||
start_num, ext = file_name.split('.')
|
|
||||||
return file_loc, start_num, ext
|
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
url = self.parse_location()
|
url = self.parse_location()
|
||||||
page_src = self.request(
|
page = self.request(
|
||||||
text.ensure_http_scheme(url)).text
|
text.ensure_http_scheme(url)).text
|
||||||
|
data = self.metadata(page)
|
||||||
|
|
||||||
data = self.metadata()
|
|
||||||
yield Message.Directory, data
|
yield Message.Directory, data
|
||||||
|
imgs = self.images(page)
|
||||||
|
|
||||||
file_loc, start_num, ext = self.get_file_info(page_src)
|
cdn = 'https://imgrojo.tmohentai.com/contents'
|
||||||
page_nums = text.extract_iter(
|
for num, _ in enumerate(imgs, start=0):
|
||||||
page_src, 'option value="', '"')
|
url = ('{}/{}/{:>03}.webp'.format(cdn, self.id_string, num))
|
||||||
|
img = text.nameext_from_url(url, {
|
||||||
for num, page in enumerate(page_nums, start=int(start_num)):
|
'num' : num + 1,
|
||||||
file = '{}/{:>03}.{}'.format(file_loc, num, ext)
|
|
||||||
img = text.nameext_from_url(file, {
|
|
||||||
'num' : num,
|
|
||||||
'title' : data['title'],
|
'title' : data['title'],
|
||||||
'id_string': self.id_string,
|
'id_string': self.id_string,
|
||||||
})
|
})
|
||||||
yield Message.Url, file, img
|
yield Message.Url, url, img
|
||||||
|
|
||||||
def metadata(self):
|
def images(self, page):
|
||||||
contents = '{}/contents/{}'.format(self.root, self.id_string)
|
pages = text.extract_iter(
|
||||||
contents_src = self.request(text.ensure_http_scheme(contents)).text
|
page, 'class="lanzador', '>')
|
||||||
|
return pages
|
||||||
|
|
||||||
genders_src = text.extr(contents_src, 'Genders</label>', '</ul>')
|
def metadata(self, page):
|
||||||
genders_list = text.extract_iter(genders_src, '">', '</a>')
|
extr = text.extract_from(page, page.index('tag tag-accepted">'))
|
||||||
|
|
||||||
tags_src = text.extr(contents_src, 'Tags</label>', '</ul>')
|
|
||||||
tags_list = text.extract_iter(tags_src, '">', '</a>')
|
|
||||||
|
|
||||||
upload_src = text.extr(contents_src, 'Uploaded By</label>', '/a>')
|
|
||||||
data = {
|
data = {
|
||||||
'title' : text.extr(contents_src, '<h3>', '</h3>').strip(),
|
'title' : text.extr(page, '<h3>', '</h3>').strip(),
|
||||||
'id_string': self.id_string,
|
'id_string': self.id_string,
|
||||||
'artists' : text.remove_html(
|
'artists' : text.remove_html(extr('">', '</a>')),
|
||||||
text.extr(contents_src, 'tag tag-accepted">', '</a>')),
|
'genders' : text.split_html(extr('Genders</label>', '<div')),
|
||||||
'genders' : list(genders_list),
|
'tags' : text.split_html(extr('Tags</label>', '</ul>')),
|
||||||
'tags' : list(tags_list),
|
'uploader' : text.remove_html(extr('Uploaded By</label>', '</a>')),
|
||||||
'uploader' : text.extr(upload_src, '">', '<'),
|
'language' : extr(' ', '\n</a>'),
|
||||||
'language' : text.extr(
|
|
||||||
contents_src, '<a><span class="flag-icon'
|
|
||||||
' flag-icon-es"></span> ', '</a>'),
|
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|||||||
Reference in New Issue
Block a user