Jarvis-Brain 0.1.11.11__tar.gz → 0.1.11.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jarvis_brain-0.1.11.11 → jarvis_brain-0.1.11.12}/PKG-INFO +1 -1
- {jarvis_brain-0.1.11.11 → jarvis_brain-0.1.11.12}/mcp_tools/dp_tools.py +3 -3
- {jarvis_brain-0.1.11.11 → jarvis_brain-0.1.11.12}/pyproject.toml +1 -1
- {jarvis_brain-0.1.11.11 → jarvis_brain-0.1.11.12}/tools/tools.py +27 -67
- {jarvis_brain-0.1.11.11 → jarvis_brain-0.1.11.12}/.gitignore +0 -0
- {jarvis_brain-0.1.11.11 → jarvis_brain-0.1.11.12}/README.md +0 -0
- {jarvis_brain-0.1.11.11 → jarvis_brain-0.1.11.12}/mcp_tools/__init__.py +0 -0
- {jarvis_brain-0.1.11.11 → jarvis_brain-0.1.11.12}/mcp_tools/main.py +0 -0
- {jarvis_brain-0.1.11.11 → jarvis_brain-0.1.11.12}/tools/__init__.py +0 -0
- {jarvis_brain-0.1.11.11 → jarvis_brain-0.1.11.12}/tools/browser_manager.py +0 -0
- {jarvis_brain-0.1.11.11 → jarvis_brain-0.1.11.12}/tools/browser_proxy.py +0 -0
- {jarvis_brain-0.1.11.11 → jarvis_brain-0.1.11.12}/uv.lock +0 -0
|
@@ -325,9 +325,9 @@ def register_get_screenshot(mcp: FastMCP, browser_manager):
|
|
|
325
325
|
os.makedirs(html_source_code_local_save_path)
|
|
326
326
|
timestamp = int(time.time() * 1000)
|
|
327
327
|
# time.sleep(1)
|
|
328
|
-
origin_png = target_tab.get_screenshot(as_bytes="
|
|
329
|
-
compress_png = compress_image_bytes(origin_png
|
|
330
|
-
image_path = os.path.join(html_source_code_local_save_path, f"{browser_port}_{tab_id}_{timestamp}.
|
|
328
|
+
origin_png = target_tab.get_screenshot(as_bytes="png")
|
|
329
|
+
compress_png = compress_image_bytes(origin_png)
|
|
330
|
+
image_path = os.path.join(html_source_code_local_save_path, f"{browser_port}_{tab_id}_{timestamp}.png")
|
|
331
331
|
with open(image_path, "wb") as f:
|
|
332
332
|
f.write(compress_png)
|
|
333
333
|
return dp_mcp_message_pack(
|
|
@@ -212,102 +212,62 @@ def btyes2Base64Img(target_byte):
|
|
|
212
212
|
return "data:image/png;base64," + base64.b64encode(target_byte).decode()
|
|
213
213
|
|
|
214
214
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
#
|
|
219
|
-
# 参数:
|
|
220
|
-
# input_bytes: 输入图片的字节数据
|
|
221
|
-
# target_size_mb: 目标大小(MB),默认1MB
|
|
222
|
-
#
|
|
223
|
-
# 返回:
|
|
224
|
-
# 压缩后的图片字节数据
|
|
225
|
-
# """
|
|
226
|
-
# target_size = target_size_mb * 1024 * 1024 # 转换为字节
|
|
227
|
-
#
|
|
228
|
-
# # 从字节数据打开图片
|
|
229
|
-
# img = Image.open(io.BytesIO(input_bytes))
|
|
230
|
-
#
|
|
231
|
-
# # 如果是PNG或其他格式,转换为RGB
|
|
232
|
-
# if img.mode in ('RGBA', 'LA', 'P'):
|
|
233
|
-
# img = img.convert('RGB')
|
|
234
|
-
#
|
|
235
|
-
# # 初始质量设置
|
|
236
|
-
# quality = 95
|
|
237
|
-
#
|
|
238
|
-
# # 先尝试压缩
|
|
239
|
-
# output_buffer = io.BytesIO()
|
|
240
|
-
# img.save(output_buffer, 'JPEG', quality=quality, optimize=True)
|
|
241
|
-
# output_bytes = output_buffer.getvalue()
|
|
242
|
-
#
|
|
243
|
-
# # 如果文件仍然太大,逐步降低质量
|
|
244
|
-
# while len(output_bytes) > target_size and quality > 10:
|
|
245
|
-
# quality -= 5
|
|
246
|
-
# output_buffer = io.BytesIO()
|
|
247
|
-
# img.save(output_buffer, 'JPEG', quality=quality, optimize=True)
|
|
248
|
-
# output_bytes = output_buffer.getvalue()
|
|
249
|
-
#
|
|
250
|
-
# # 如果降低质量还不够,尝试缩小尺寸
|
|
251
|
-
# if len(output_bytes) > target_size:
|
|
252
|
-
# width, height = img.size
|
|
253
|
-
#
|
|
254
|
-
# while len(output_bytes) > target_size and quality > 10:
|
|
255
|
-
# # 缩小10%
|
|
256
|
-
# width = int(width * 0.9)
|
|
257
|
-
# height = int(height * 0.9)
|
|
258
|
-
# img_resized = img.resize((width, height), Image.Resampling.LANCZOS)
|
|
259
|
-
# output_buffer = io.BytesIO()
|
|
260
|
-
# img_resized.save(output_buffer, 'JPEG', quality=quality, optimize=True)
|
|
261
|
-
# output_bytes = output_buffer.getvalue()
|
|
262
|
-
#
|
|
263
|
-
# final_size = len(output_bytes) / (1024 * 1024)
|
|
264
|
-
# # print(f"压缩完成!")
|
|
265
|
-
# # print(f"原始大小: {len(input_bytes) / (1024 * 1024):.2f}MB")
|
|
266
|
-
# # print(f"压缩后大小: {final_size:.2f}MB")
|
|
267
|
-
# # print(f"最终质量: {quality}")
|
|
268
|
-
#
|
|
269
|
-
# return output_bytes
|
|
270
|
-
#
|
|
271
|
-
|
|
215
|
+
def compress_image_bytes(input_bytes, target_size_mb=1):
|
|
216
|
+
"""
|
|
217
|
+
压缩图片字节数据到目标大小
|
|
272
218
|
|
|
219
|
+
参数:
|
|
220
|
+
input_bytes: 输入图片的字节数据
|
|
221
|
+
target_size_mb: 目标大小(MB),默认1MB
|
|
273
222
|
|
|
274
|
-
|
|
275
|
-
|
|
223
|
+
返回:
|
|
224
|
+
压缩后的图片字节数据
|
|
225
|
+
"""
|
|
226
|
+
target_size = target_size_mb * 1024 * 1024 # 转换为字节
|
|
276
227
|
|
|
228
|
+
# 从字节数据打开图片
|
|
277
229
|
img = Image.open(io.BytesIO(input_bytes))
|
|
230
|
+
|
|
231
|
+
# 如果是PNG或其他格式,转换为RGB
|
|
278
232
|
if img.mode in ('RGBA', 'LA', 'P'):
|
|
279
233
|
img = img.convert('RGB')
|
|
280
234
|
|
|
235
|
+
# 初始质量设置
|
|
281
236
|
quality = 95
|
|
237
|
+
|
|
238
|
+
# 先尝试压缩
|
|
282
239
|
output_buffer = io.BytesIO()
|
|
283
240
|
img.save(output_buffer, 'JPEG', quality=quality, optimize=True)
|
|
284
241
|
output_bytes = output_buffer.getvalue()
|
|
285
242
|
|
|
286
|
-
#
|
|
243
|
+
# 如果文件仍然太大,逐步降低质量
|
|
287
244
|
while len(output_bytes) > target_size and quality > 10:
|
|
288
245
|
quality -= 5
|
|
289
246
|
output_buffer = io.BytesIO()
|
|
290
247
|
img.save(output_buffer, 'JPEG', quality=quality, optimize=True)
|
|
291
248
|
output_bytes = output_buffer.getvalue()
|
|
292
249
|
|
|
293
|
-
#
|
|
250
|
+
# 如果降低质量还不够,尝试缩小尺寸
|
|
294
251
|
if len(output_bytes) > target_size:
|
|
295
252
|
width, height = img.size
|
|
296
253
|
|
|
297
|
-
|
|
298
|
-
|
|
254
|
+
while len(output_bytes) > target_size and quality > 10:
|
|
255
|
+
# 缩小10%
|
|
299
256
|
width = int(width * 0.9)
|
|
300
257
|
height = int(height * 0.9)
|
|
301
|
-
|
|
302
|
-
# 重新调整尺寸
|
|
303
258
|
img_resized = img.resize((width, height), Image.Resampling.LANCZOS)
|
|
304
|
-
|
|
305
259
|
output_buffer = io.BytesIO()
|
|
306
|
-
# 注意:这里继续使用当前的最低质量(10)进行保存,或者你可以适当回调一点质量
|
|
307
260
|
img_resized.save(output_buffer, 'JPEG', quality=quality, optimize=True)
|
|
308
261
|
output_bytes = output_buffer.getvalue()
|
|
309
262
|
|
|
263
|
+
final_size = len(output_bytes) / (1024 * 1024)
|
|
264
|
+
# print(f"压缩完成!")
|
|
265
|
+
# print(f"原始大小: {len(input_bytes) / (1024 * 1024):.2f}MB")
|
|
266
|
+
# print(f"压缩后大小: {final_size:.2f}MB")
|
|
267
|
+
# print(f"最终质量: {quality}")
|
|
268
|
+
|
|
310
269
|
return output_bytes
|
|
270
|
+
|
|
311
271
|
# todo: 大致盘一下各种判定的逻辑【以下的所有压缩比之间的差距均取“绝对值”】
|
|
312
272
|
# 1. 如果requests、无头、有头获取到的压缩比之间从差距都在15%以内,则认定该页面是静态页面,此时优先使用requests请求
|
|
313
273
|
# 2. 如果requests的status_code为特定的412,或者521,则判定是瑞数和jsl。[此时还有一个特点:requests的压缩比会与其他两种方式获取到的压缩比差距非常大(一两千的那种)]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|