| 1 |
|
| 2 |
|
| 3 |
n |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
"""Extractors for https://lefty.pictures/""" |
| 10 |
|
| 11 |
from . import booru |
| 12 |
from .. import text |
| 13 |
|
| 14 |
BASE_PATTERN = r"(?:https?://)?lefty\.pictures" |
| 15 |
|
| 16 |
|
| 17 |
class LeftybooruExtractor(booru.BooruExtractor): |
| 18 |
"""Base class for leftybooru extractors""" |
| 19 |
category = "leftybooru" |
| 20 |
basecategory = "shimmie2" |
| 21 |
root = "https://lefty.pictures" |
| 22 |
archive_fmt = "{id}" |
| 23 |
page_start = 1 |
| 24 |
per_page = 24 |
| 25 |
|
| 26 |
def _prepare(self, post): |
| 27 |
post["id"] = text.parse_int(post["id"]) |
| 28 |
post["width"] = text.parse_int(post["width"]) |
| 29 |
post["height"] = text.parse_int(post["height"]) |
| 30 |
|
| 31 |
|
| 32 |
class LeftybooruPostExtractor(LeftybooruExtractor): |
| 33 |
subcategory = "post" |
| 34 |
pattern = BASE_PATTERN + r"/post/view/(\d+)" |
| 35 |
example = "https://lefty.pictures/post/view/12345" |
| 36 |
|
| 37 |
def posts(self): |
| 38 |
post_id = self.groups[0] |
| 39 |
url = f"{self.root}/post/view/{post_id}" |
| 40 |
extr = text.extract_from(self.request(url).text) |
| 41 |
|
| 42 |
post = { |
| 43 |
"id" : post_id, |
| 44 |
"tags" : text.unescape(extr( |
| 45 |
"name='keywords' content='", "'")).split(", "), |
| 46 |
"file_url": extr("property='og:image' content='", "'"), |
| 47 |
"width" : extr("property='og:image:width' content='", "'"), |
| 48 |
"height" : extr("property='og:image:height' content='", "'"), |
| 49 |
"md5" : extr("/_images/", "/"), |
| 50 |
"uploader": extr(">Uploader: <a href='/user/", "'"), |
| 51 |
"date" : self.parse_datetime_iso(extr("datetime='", "'")), |
| 52 |
"size" : text.parse_bytes(extr(">Size: ", "B")), |
| 53 |
"type" : extr(">Type: ", "<"), |
| 54 |
"duration": extr(">Length: ", "<"), |
| 55 |
"rating" : extr(">Rating: ", "</")[34:35].lower(), |
| 56 |
"score" : extr(">Post Score: ", "<"), |
| 57 |
"source" : text.remove_html(extr( |
| 58 |
">Source</a></th><td><span class='view'><div>", "</")), |
| 59 |
"parent_id": extr( |
| 60 |
">Parent</th><td><span class='view'>", "<"), |
| 61 |
} |
| 62 |
|
| 63 |
if post["source"] == "Unknown": |
| 64 |
post["source"] = None |
| 65 |
if post["parent_id"] == "None": |
| 66 |
post["parent_id"] = None |
| 67 |
|
| 68 |
return (post,) |
| 69 |
|
| 70 |
|
| 71 |
class LeftybooruTagExtractor(LeftybooruExtractor): |
| 72 |
subcategory = "tag" |
| 73 |
directory_fmt = ("{category}", "{search_tags}") |
| 74 |
pattern = BASE_PATTERN + r"/post/list/(?:([^/?#]+)/)?(\d+)" |
| 75 |
example = "https://lefty.pictures/post/list/TAG/1" |
| 76 |
|
| 77 |
def posts(self): |
| 78 |
tags, pnum = self.groups |
| 79 |
pnum = text.parse_int(pnum, 1) + self.page_start - 1 |
| 80 |
if tags is None: |
| 81 |
tags = "" |
| 82 |
self.kwdict["search_tags"] = text.unquote(tags) |
| 83 |
|
| 84 |
base = self.root + "/_images/" |
| 85 |
while True: |
| 86 |
page = self.request(f"{self.root}/post/list/{tags}/{pnum}").text |
| 87 |
extr = text.extract_from(page) |
| 88 |
|
| 89 |
while True: |
| 90 |
pid = extr("<a href='/post/view/", "'") |
| 91 |
if not pid: |
| 92 |
break |
| 93 |
|
| 94 |
post = { |
| 95 |
"id" : pid, |
| 96 |
"tags" : text.unescape(extr("data-tags='", "'")), |
| 97 |
"type" : extr("data-mime='", "'"), |
| 98 |
"rating": extr("data-rating='", "'"), |
| 99 |
"width" : extr(" // ", "x"), |
| 100 |
"height": extr("", " "), |
| 101 |
"size" : text.parse_bytes(extr("// ", "B")), |
| 102 |
"md5" : extr("/_thumbs/", "/"), |
| 103 |
} |
| 104 |
|
| 105 |
post["file_url"] = ( |
| 106 |
f"{base}{post['md5']}/{pid} - {post['tags']}." |
| 107 |
f"{post['type'].rpartition('/')[2]}") |
| 108 |
post["tags"] = post["tags"].split(" ") |
| 109 |
|
| 110 |
yield post |
| 111 |
|
| 112 |
if "id='nextlink'" not in page: |
| 113 |
break |
| 114 |
pnum += 1 |