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