[pururin] fix extraction
Missing metadata information would lead to unnecessary exceptions.
This commit is contained in:
@@ -17,29 +17,34 @@ class PururinGalleryExtractor(GalleryExtractor):
|
|||||||
"""Extractor for image galleries on pururin.io"""
|
"""Extractor for image galleries on pururin.io"""
|
||||||
category = "pururin"
|
category = "pururin"
|
||||||
pattern = r"(?:https?://)?(?:www\.)?pururin\.io/(?:gallery|read)/(\d+)"
|
pattern = r"(?:https?://)?(?:www\.)?pururin\.io/(?:gallery|read)/(\d+)"
|
||||||
test = ("https://pururin.io/gallery/38661/iowant-2", {
|
test = (
|
||||||
"pattern": r"https://cdn.pururin.io/assets/images/data/38661/\d+\.jpg",
|
("https://pururin.io/gallery/38661/iowant-2", {
|
||||||
"keyword": {
|
"pattern": r"https://cdn.pururin.io/\w+/images/data/\d+/\d+\.jpg",
|
||||||
"title" : "Iowant 2!!",
|
"keyword": {
|
||||||
"title_en" : "Iowant 2!!",
|
"title" : "Iowant 2!!",
|
||||||
"title_jp" : "",
|
"title_en" : "Iowant 2!!",
|
||||||
"gallery_id": 38661,
|
"title_jp" : "",
|
||||||
"count" : 19,
|
"gallery_id": 38661,
|
||||||
"artist" : ["Shoda Norihiro"],
|
"count" : 19,
|
||||||
"group" : ["Obsidian Order"],
|
"artist" : ["Shoda Norihiro"],
|
||||||
"parody" : ["Kantai Collection"],
|
"group" : ["Obsidian Order"],
|
||||||
"characters": ["Iowa", "Teitoku"],
|
"parody" : ["Kantai Collection"],
|
||||||
"tags" : list,
|
"characters": ["Iowa", "Teitoku"],
|
||||||
"type" : "Doujinshi",
|
"tags" : list,
|
||||||
"collection": "",
|
"type" : "Doujinshi",
|
||||||
"convention": "C92",
|
"collection": "",
|
||||||
"rating" : float,
|
"convention": "C92",
|
||||||
"uploader" : "demo",
|
"rating" : float,
|
||||||
"scanlator" : "",
|
"uploader" : "demo",
|
||||||
"lang" : "en",
|
"scanlator" : "",
|
||||||
"language" : "English",
|
"lang" : "en",
|
||||||
}
|
"language" : "English",
|
||||||
})
|
}
|
||||||
|
}),
|
||||||
|
("https://pururin.io/gallery/7661/unisis-team-vanilla", {
|
||||||
|
"count": 17,
|
||||||
|
}),
|
||||||
|
)
|
||||||
root = "https://pururin.io"
|
root = "https://pururin.io"
|
||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
@@ -51,45 +56,43 @@ class PururinGalleryExtractor(GalleryExtractor):
|
|||||||
self._cnt = 0
|
self._cnt = 0
|
||||||
|
|
||||||
def metadata(self, page):
|
def metadata(self, page):
|
||||||
data = text.extract_all(page, (
|
extr = text.extract_from(page)
|
||||||
("artist" , "<td>Artist</td>" , "</td>"),
|
|
||||||
("group" , "<td>Circle</td>" , "</td>"),
|
def _lst(key, e=extr):
|
||||||
("parody" , "<td>Parody</td>" , "</td>"),
|
return [
|
||||||
("tags" , "<td>Contents</td>" , "</td>"),
|
text.unescape(item)
|
||||||
("type" , "<td>Category</td>" , "</td>"),
|
for item in text.extract_iter(e(key, "</td>"), 'title="', '"')
|
||||||
("characters", "<td>Character</td>" , "</td>"),
|
]
|
||||||
("collection", "<td>Collection</td>", "</td>"),
|
|
||||||
("language" , "<td>Language</td>" , "</td>"),
|
def _str(key, e=extr):
|
||||||
("scanlator" , "<td>Scanlator</td>" , "</td>"),
|
return text.unescape(text.extract(
|
||||||
("convention", "<td>Convention</td>", "</td>"),
|
e(key, "</td>"), 'title="', '"')[0] or "")
|
||||||
("uploader" , "<td>Uploader</td>" , "</td>"),
|
|
||||||
("rating" , " :rating='" , "'"),
|
|
||||||
))[0]
|
|
||||||
|
|
||||||
url = "{}/read/{}/01/x".format(self.root, self.gallery_id)
|
url = "{}/read/{}/01/x".format(self.root, self.gallery_id)
|
||||||
page = self.request(url).text
|
page = self.request(url).text
|
||||||
info = json.loads(text.unescape(text.extract(
|
info = json.loads(text.unescape(text.extract(
|
||||||
page, ':gallery="', '"')[0]))
|
page, ':gallery="', '"')[0]))
|
||||||
|
|
||||||
self._ext = info["image_extension"]
|
self._ext = info["image_extension"]
|
||||||
self._cnt = info["total_pages"]
|
self._cnt = info["total_pages"]
|
||||||
|
|
||||||
for key in ("artist", "group", "parody", "tags", "characters"):
|
data = {
|
||||||
data[key] = [
|
"gallery_id": text.parse_int(self.gallery_id),
|
||||||
text.unescape(item)
|
"title" : info["title"] or info.get("j_title") or "",
|
||||||
for item in text.extract_iter(data[key], 'title="', '"')
|
"title_en" : info["title"],
|
||||||
]
|
"title_jp" : info.get("j_title") or "",
|
||||||
for key in ("type", "collection", "language", "scanlator",
|
"artist" : _lst("<td>Artist</td>"),
|
||||||
"convention"):
|
"group" : _lst("<td>Circle</td>"),
|
||||||
data[key] = text.unescape(text.extract(
|
"parody" : _lst("<td>Parody</td>"),
|
||||||
data[key], 'title="', '"')[0] or "")
|
"tags" : _lst("<td>Contents</td>"),
|
||||||
|
"type" : _str("<td>Category</td>"),
|
||||||
data["gallery_id"] = text.parse_int(self.gallery_id)
|
"characters": _lst("<td>Character</td>"),
|
||||||
data["title"] = info["title"] or info.get("j_title") or ""
|
"collection": _str("<td>Collection</td>"),
|
||||||
data["title_en"] = info["title"]
|
"language" : _str("<td>Language</td>"),
|
||||||
data["title_jp"] = info.get("j_title") or ""
|
"scanlator" : _str("<td>Scanlator</td>"),
|
||||||
data["uploader"] = text.remove_html(data["uploader"])
|
"convention": _str("<td>Convention</td>"),
|
||||||
data["rating"] = text.parse_float(data["rating"])
|
"uploader" : text.remove_html(extr("<td>Uploader</td>", "</td>")),
|
||||||
|
"rating" : text.parse_float(extr(" :rating='" , "'")),
|
||||||
|
}
|
||||||
data["lang"] = util.language_to_code(data["language"])
|
data["lang"] = util.language_to_code(data["language"])
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user