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
|
# -*- coding: utf-8 -*-
# Copyright 2019-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 https://35photo.pro/"""
from .common import Extractor, Message
from .. import text
class _35photoExtractor(Extractor):
category = "35photo"
directory_fmt = ("{category}", "{user}")
filename_fmt = "{id}{title:?_//}_{num:>02}.{extension}"
archive_fmt = "{id}_{num}"
root = "https://35photo.pro"
def items(self):
first = True
data = self.metadata()
for photo_id in self.photos():
for photo in self._photo_data(photo_id):
photo.update(data)
url = photo["url"]
if first:
first = False
yield Message.Directory, photo
yield Message.Url, url, text.nameext_from_url(url, photo)
def metadata(self):
"""Returns general metadata"""
return {}
def photos(self):
"""Returns an iterable containing all relevant photo IDs"""
def _pagination(self, params, extra_ids=None):
url = "https://35photo.pro/show_block.php"
headers = {"Referer": self.root, "X-Requested-With": "XMLHttpRequest"}
params["type"] = "getNextPageData"
if "lastId" not in params:
params["lastId"] = "999999999"
if extra_ids:
yield from extra_ids
while params["lastId"]:
data = self.request_json(url, headers=headers, params=params)
yield from self._photo_ids(data["data"])
params["lastId"] = data["lastId"]
def _photo_data(self, photo_id):
params = {"method": "photo.getData", "photoId": photo_id}
data = self.request_json(
"https://api.35photo.pro/", params=params)["data"][photo_id]
info = {
"url" : data["src"],
"id" : data["photo_id"],
"title" : data["photo_name"],
"description": data["photo_desc"],
"tags" : data["tags"] or [],
"views" : data["photo_see"],
"favorites" : data["photo_fav"],
"score" : data["photo_rating"],
"type" : data["photo_type"],
"date" : data["timeAdd"],
"user" : data["user_login"],
"user_id" : data["user_id"],
"user_name" : data["user_name"],
}
if "series" in data:
for info["num"], photo in enumerate(data["series"], 1):
info["url"] = photo["src"]
info["id_series"] = text.parse_int(photo["id"])
info["title_series"] = photo["title"] or ""
yield info.copy()
else:
info["num"] = 1
yield info
def _photo_ids(self, page):
"""Extract unique photo IDs and return them as sorted list"""
# searching for photo-id="..." doesn't always work (see unit tests)
if not page:
return ()
return sorted(
set(text.extract_iter(page, "/photo_", "/")),
key=text.parse_int,
reverse=True,
)
class _35photoUserExtractor(_35photoExtractor):
"""Extractor for all images of a user on 35photo.pro"""
subcategory = "user"
pattern = (r"(?:https?://)?(?:[a-z]+\.)?35photo\.pro"
r"/(?!photo_|genre_|tags/|rating/)([^/?#]+)")
example = "https://35photo.pro/USER"
def __init__(self, match):
_35photoExtractor.__init__(self, match)
self.user = match[1]
self.user_id = 0
def metadata(self):
url = f"{self.root}/{self.user}/"
page = self.request(url).text
self.user_id = text.parse_int(text.extr(page, "/user_", ".xml"))
return {
"user": self.user,
"user_id": self.user_id,
}
def photos(self):
return self._pagination({
"page": "photoUser",
"user_id": self.user_id,
})
class _35photoTagExtractor(_35photoExtractor):
"""Extractor for all photos from a tag listing"""
subcategory = "tag"
directory_fmt = ("{category}", "Tags", "{search_tag}")
archive_fmt = "t{search_tag}_{id}_{num}"
pattern = r"(?:https?://)?(?:[a-z]+\.)?35photo\.pro/tags/([^/?#]+)"
example = "https://35photo.pro/tags/TAG/"
def __init__(self, match):
_35photoExtractor.__init__(self, match)
self.tag = match[1]
def metadata(self):
return {"search_tag": text.unquote(self.tag).lower()}
def photos(self):
num = 1
while True:
url = f"{self.root}/tags/{self.tag}/list_{num}/"
page = self.request(url).text
prev = None
for photo_id in text.extract_iter(page, "35photo.pro/photo_", "/"):
if photo_id != prev:
prev = photo_id
yield photo_id
if not prev:
return
num += 1
class _35photoGenreExtractor(_35photoExtractor):
"""Extractor for images of a specific genre on 35photo.pro"""
subcategory = "genre"
directory_fmt = ("{category}", "Genre", "{genre}")
archive_fmt = "g{genre_id}_{id}_{num}"
pattern = r"(?:https?://)?(?:[a-z]+\.)?35photo\.pro/genre_(\d+)(/new/)?"
example = "https://35photo.pro/genre_12345/"
def __init__(self, match):
_35photoExtractor.__init__(self, match)
self.genre_id, self.new = match.groups()
self.photo_ids = None
def metadata(self):
url = f"{self.root}/genre_{self.genre_id}{self.new or '/'}"
page = self.request(url).text
self.photo_ids = self._photo_ids(text.extr(
page, ' class="photo', '\n'))
return {
"genre": text.extr(page, " genre - ", ". "),
"genre_id": text.parse_int(self.genre_id),
}
def photos(self):
if not self.photo_ids:
return ()
return self._pagination({
"page": "genre",
"community_id": self.genre_id,
"photo_rating": "0" if self.new else "50",
"lastId": self.photo_ids[-1],
}, self.photo_ids)
class _35photoImageExtractor(_35photoExtractor):
"""Extractor for individual images from 35photo.pro"""
subcategory = "image"
pattern = r"(?:https?://)?(?:[a-z]+\.)?35photo\.pro/photo_(\d+)"
example = "https://35photo.pro/photo_12345/"
def __init__(self, match):
_35photoExtractor.__init__(self, match)
self.photo_id = match[1]
def photos(self):
return (self.photo_id,)
|