| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# Copyright 2023-2026 Mike Fährmann |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License version 2 as |
| 7 |
# published by the Free Software Foundation. |
| 8 |
|
| 9 |
"""Extractors for Chevereto galleries""" |
| 10 |
|
| 11 |
from .common import BaseExtractor, Message |
| 12 |
from .. import text, util |
| 13 |
|
| 14 |
|
| 15 |
class CheveretoExtractor(BaseExtractor): |
| 16 |
"""Base class for chevereto extractors""" |
| 17 |
basecategory = "chevereto" |
| 18 |
directory_fmt = ("{category}", "{user}", "{album}") |
| 19 |
archive_fmt = "{id}" |
| 20 |
parent = True |
| 21 |
|
| 22 |
def _init(self): |
| 23 |
self.path = self.groups[-1] |
| 24 |
|
| 25 |
def _pagination(self, url, callback=None): |
| 26 |
page = self.request(url).text |
| 27 |
|
| 28 |
if len(page) < 45_000 and "assword required" in page and ( |
| 29 |
form := text.extr(page, "<form ", "</form")): |
| 30 |
page = self._password_submit(url, form) or page |
| 31 |
|
| 32 |
if callback is not None: |
| 33 |
callback(page) |
| 34 |
|
| 35 |
while True: |
| 36 |
for item in text.extract_iter( |
| 37 |
page, '<div class="list-item-image ', 'image-container'): |
| 38 |
yield text.urljoin(self.root, text.extr( |
| 39 |
item, '<a href="', '"')) |
| 40 |
|
| 41 |
url = text.extr(page, 'data-pagination="next" href="', '"') |
| 42 |
if not url: |
| 43 |
return |
| 44 |
url = text.unescape(url).replace("+", " ") |
| 45 |
if url[0] == "/": |
| 46 |
url = self.root + url |
| 47 |
page = self.request(url).text |
| 48 |
|
| 49 |
def _password_submit(self, url, form): |
| 50 |
sources = getattr(self, "_password_sources", None) |
| 51 |
if sources is None: |
| 52 |
sources = self._password_sources = [] |
| 53 |
if pw := getattr(self, "_password_last", None): |
| 54 |
sources.append(pw) |
| 55 |
if pw := self.config("password"): |
| 56 |
if isinstance(pw, str): |
| 57 |
pw = pw.split(",") |
| 58 |
sources.extend(pw) |
| 59 |
sources.reverse() |
| 60 |
sources = sources.copy() |
| 61 |
|
| 62 |
page = None |
| 63 |
tried = set() |
| 64 |
while True: |
| 65 |
pw = sources.pop() if sources else self.input("Password: ") |
| 66 |
if not pw: |
| 67 |
break |
| 68 |
if pw in tried: |
| 69 |
continue |
| 70 |
self.log.debug("Submitting password '%s'", pw) |
| 71 |
data = { |
| 72 |
"auth_token": text.unescape(text.extr( |
| 73 |
form, 'name="auth_token" value="', '"')), |
| 74 |
"content-password": pw, |
| 75 |
} |
| 76 |
page = self.request(url, method="POST", data=data).text |
| 77 |
form = text.extr(page, "<form ", "</form") |
| 78 |
if not form: |
| 79 |
CheveretoExtractor._password_last = pw |
| 80 |
break |
| 81 |
tried.add(pw) |
| 82 |
return page |
| 83 |
|
| 84 |
|
| 85 |
BASE_PATTERN = CheveretoExtractor.update({ |
| 86 |
"jpgfish": { |
| 87 |
"root": "https://jpg7.cr", |
| 88 |
"pattern": r"(?:www\.)?jpe?g\d?\.(?:cr|su|pet|fish(?:ing)?|church)", |
| 89 |
}, |
| 90 |
"imglike": { |
| 91 |
"root": "https://imglike.com", |
| 92 |
"pattern": r"(?:www\.)?imglike\.com", |
| 93 |
}, |
| 94 |
"putmega": { |
| 95 |
"root": "https://putmega.com", |
| 96 |
"pattern": r"(?:www\.)?putme(?:ga\.com|\.ga)", |
| 97 |
}, |
| 98 |
|
| 99 |
}) |
| 100 |
|
| 101 |
|
| 102 |
class CheveretoFileExtractor(CheveretoExtractor): |
| 103 |
"""Extractor for chevereto files""" |
| 104 |
subcategory = "file" |
| 105 |
pattern = BASE_PATTERN + r"(/(?:im(?:g|age)|video|i)/[^/?#]+)" |
| 106 |
example = "https://jpg7.cr/img/TITLE.ID" |
| 107 |
|
| 108 |
def items(self): |
| 109 |
url = self.root + self.path |
| 110 |
page = self.request(url).text |
| 111 |
extr = text.extract_from(page) |
| 112 |
|
| 113 |
type = text.extr(page, 'property="og:type" content="', '"') |
| 114 |
title = extr('property="og:title" content="', '"') |
| 115 |
|
| 116 |
if type == "video": |
| 117 |
file = { |
| 118 |
"id" : self.path.rpartition(".")[2], |
| 119 |
"type" : "video", |
| 120 |
"title" : text.unescape(extr( |
| 121 |
'property="og:title" content="', '"')), |
| 122 |
"thumbnail": extr( |
| 123 |
'property="og:image" content="', '"'), |
| 124 |
"url" : extr( |
| 125 |
'property="og:video" content="', '"'), |
| 126 |
"width" : text.parse_int(extr( |
| 127 |
'property="video:width" content="', '"')), |
| 128 |
"height" : text.parse_int(extr( |
| 129 |
'property="video:height" content="', '"')), |
| 130 |
"duration" : extr( |
| 131 |
'class="far fa-clock"></i>', "—"), |
| 132 |
"album" : extr( |
| 133 |
"Added to <a", "</a>"), |
| 134 |
"date" : self.parse_datetime_iso(extr( |
| 135 |
'<span title="', '"')), |
| 136 |
"user" : extr('username: "', '"'), |
| 137 |
} |
| 138 |
|
| 139 |
album_url, _, album_name = file["album"].rpartition(">") |
| 140 |
file["album"] = text.remove_html(album_name) |
| 141 |
file["album_slug"], _, file["album_id"] = text.rextr( |
| 142 |
album_url, "/", '"').rpartition(".") |
| 143 |
|
| 144 |
try: |
| 145 |
min, _, sec = file["duration"].partition(":") |
| 146 |
file["duration"] = int(min) * 60 + int(sec) |
| 147 |
except Exception: |
| 148 |
pass |
| 149 |
else: |
| 150 |
url = (extr('<meta property="og:image" content="', '"') or |
| 151 |
extr('url: "', '"')) |
| 152 |
if not url or url.endswith("/loading.svg"): |
| 153 |
pos = page.find(" download=") |
| 154 |
url = text.rextr(page, 'href="', '"', pos) |
| 155 |
if not url.startswith("https://"): |
| 156 |
url = util.decrypt_xor( |
| 157 |
url, b"seltilovessimpcity@simpcityhatesscrapers", |
| 158 |
fromhex=True) |
| 159 |
|
| 160 |
album_url, _, album_name = extr( |
| 161 |
"Added to <a", "</a>").rpartition(">") |
| 162 |
file = { |
| 163 |
"id" : self.path.rpartition("/")[2].rpartition(".")[2], |
| 164 |
"url" : url, |
| 165 |
"type" : type, |
| 166 |
"title": text.unescape(title), |
| 167 |
"album": text.remove_html(album_name), |
| 168 |
"date" : self.parse_datetime_iso(extr('<span title="', '"')), |
| 169 |
"user" : extr('username: "', '"'), |
| 170 |
} |
| 171 |
|
| 172 |
file["album_slug"], _, file["album_id"] = text.rextr( |
| 173 |
album_url, "/", '"').rpartition(".") |
| 174 |
|
| 175 |
text.nameext_from_url(file["url"], file) |
| 176 |
yield Message.Directory, "", file |
| 177 |
yield Message.Url, file["url"], file |
| 178 |
|
| 179 |
|
| 180 |
class CheveretoAlbumExtractor(CheveretoExtractor): |
| 181 |
"""Extractor for chevereto albums""" |
| 182 |
subcategory = "album" |
| 183 |
pattern = BASE_PATTERN + r"(/a(?:lbum)?/[^/?#]+(?:/sub)?)" |
| 184 |
example = "https://jpg7.cr/album/TITLE.ID" |
| 185 |
|
| 186 |
def items(self): |
| 187 |
url = self.root + self.path |
| 188 |
data = {"_extractor": CheveretoFileExtractor} |
| 189 |
|
| 190 |
if self.path.endswith("/sub"): |
| 191 |
albums = self._pagination(url) |
| 192 |
else: |
| 193 |
albums = (url,) |
| 194 |
|
| 195 |
for album in albums: |
| 196 |
for self.kwdict["num"], item_url in enumerate(self._pagination( |
| 197 |
album, self._extract_metadata_album), 1): |
| 198 |
yield Message.Queue, item_url, data |
| 199 |
|
| 200 |
def _extract_metadata_album(self, page): |
| 201 |
url, pos = text.extract( |
| 202 |
page, 'property="og:url" content="', '"') |
| 203 |
title, pos = text.extract( |
| 204 |
page, 'property="og:title" content="', '"', pos) |
| 205 |
|
| 206 |
kwdict = self.kwdict |
| 207 |
kwdict["album_slug"], _, kwdict["album_id"] = \ |
| 208 |
url[url.rfind("/")+1:].rpartition(".") |
| 209 |
kwdict["album"] = text.unescape(title) |
| 210 |
kwdict["count"] = text.parse_int(text.extract( |
| 211 |
page, 'data-text="image-count">', "<", pos)[0]) |
| 212 |
|
| 213 |
|
| 214 |
class CheveretoCategoryExtractor(CheveretoExtractor): |
| 215 |
"""Extractor for chevereto galleries""" |
| 216 |
subcategory = "category" |
| 217 |
pattern = BASE_PATTERN + r"(/category/[^/?#]+)" |
| 218 |
example = "https://imglike.com/category/TITLE" |
| 219 |
|
| 220 |
def items(self): |
| 221 |
data = {"_extractor": CheveretoFileExtractor} |
| 222 |
for image in self._pagination(self.root + self.path): |
| 223 |
yield Message.Queue, image, data |
| 224 |
|
| 225 |
|
| 226 |
class CheveretoUserExtractor(CheveretoExtractor): |
| 227 |
"""Extractor for chevereto users""" |
| 228 |
subcategory = "user" |
| 229 |
pattern = BASE_PATTERN + r"(/[^/?#]+(?:/albums)?)" |
| 230 |
example = "https://jpg7.cr/USER" |
| 231 |
|
| 232 |
def items(self): |
| 233 |
data_file = {"_extractor": CheveretoFileExtractor} |
| 234 |
data_album = {"_extractor": CheveretoAlbumExtractor} |
| 235 |
for url in self._pagination(self.root + self.path): |
| 236 |
data = (data_album if "/album/" in url or "/a/" in url else |
| 237 |
data_file) |
| 238 |
yield Message.Queue, url, data |