streamembed 0.3.3__tar.gz → 0.3.4__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.
- {streamembed-0.3.3 → streamembed-0.3.4}/PKG-INFO +5 -4
- {streamembed-0.3.3 → streamembed-0.3.4}/PYPI.md +1 -1
- {streamembed-0.3.3 → streamembed-0.3.4}/README.md +1 -1
- {streamembed-0.3.3 → streamembed-0.3.4}/docs/reference.md +2 -2
- {streamembed-0.3.3 → streamembed-0.3.4}/pyproject.toml +6 -4
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/__init__.py +1 -1
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/capture.py +12 -1
- streamembed-0.3.4/src/streamembed/sckgrab.py +160 -0
- streamembed-0.3.4/tests/test_sckgrab.py +58 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/.gitignore +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/.hgignore +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/LICENSE +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/NOTICE +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/examples/main.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/__main__.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/ann.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/api.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/cli.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/config.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/defaults.toml +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/encoder.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/engine/__init__.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/engine/config.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/engine/engine.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/engine/llm.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/engine/macs.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/engine/model.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/engine/pause.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/engine/qwen_embedder.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/engine/spatial.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/engine/temporal.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/engine/vit.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/gate.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/index.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/models.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/queryserver.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/service.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/static/results.html +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/visualize.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/src/streamembed/webui.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/tests/conftest.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/tests/test_api.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/tests/test_config.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/tests/test_defer.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/tests/test_encoder_order.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/tests/test_front.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/tests/test_idle.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/tests/test_models.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/tests/test_pause.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/tests/test_prune.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/tests/test_screen_permission.py +0 -0
- {streamembed-0.3.3 → streamembed-0.3.4}/tests/test_search_wait.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: streamembed
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: Search your own screen history by describing what you saw, from screenshots, on your machine
|
|
5
5
|
Project-URL: Repository, https://github.com/StarTrail-org/StreamEmbed
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -18,10 +18,11 @@ Requires-Dist: mss<11,>=9
|
|
|
18
18
|
Requires-Dist: numpy>=2.2
|
|
19
19
|
Requires-Dist: pillow>=11
|
|
20
20
|
Requires-Dist: pyobjc-framework-quartz>=10; sys_platform == 'darwin'
|
|
21
|
+
Requires-Dist: pyobjc-framework-screencapturekit>=10.1; sys_platform == 'darwin'
|
|
21
22
|
Requires-Dist: qwen-vl-utils==0.0.14
|
|
22
23
|
Requires-Dist: safetensors>=0.4
|
|
23
|
-
Requires-Dist: torch==2.
|
|
24
|
-
Requires-Dist: torchvision==0.
|
|
24
|
+
Requires-Dist: torch==2.14.1
|
|
25
|
+
Requires-Dist: torchvision==0.29.2
|
|
25
26
|
Requires-Dist: transformers==5.17.0
|
|
26
27
|
Provides-Extra: dev
|
|
27
28
|
Requires-Dist: pytest>=8; extra == 'dev'
|
|
@@ -90,7 +91,7 @@ capture.stop()
|
|
|
90
91
|
|
|
91
92
|
## Requirements
|
|
92
93
|
|
|
93
|
-
Tested on macOS 15 (Apple silicon), Ubuntu 24.04 under X11 and Windows Server 2025; Wayland is not supported. Encoding needs about 8 GB of memory. StreamEmbed pins torch 2.
|
|
94
|
+
Tested on macOS 15 (Apple silicon), Ubuntu 24.04 under X11 and Windows Server 2025; Wayland is not supported. Encoding needs about 8 GB of memory. StreamEmbed pins torch 2.14.1 and transformers 5.17.0, so install it in an environment of its own if your project needs other versions.
|
|
94
95
|
|
|
95
96
|
## License
|
|
96
97
|
|
|
@@ -59,7 +59,7 @@ capture.stop()
|
|
|
59
59
|
|
|
60
60
|
## Requirements
|
|
61
61
|
|
|
62
|
-
Tested on macOS 15 (Apple silicon), Ubuntu 24.04 under X11 and Windows Server 2025; Wayland is not supported. Encoding needs about 8 GB of memory. StreamEmbed pins torch 2.
|
|
62
|
+
Tested on macOS 15 (Apple silicon), Ubuntu 24.04 under X11 and Windows Server 2025; Wayland is not supported. Encoding needs about 8 GB of memory. StreamEmbed pins torch 2.14.1 and transformers 5.17.0, so install it in an environment of its own if your project needs other versions.
|
|
63
63
|
|
|
64
64
|
## License
|
|
65
65
|
|
|
@@ -59,7 +59,7 @@ capture.stop()
|
|
|
59
59
|
|
|
60
60
|
## Requirements
|
|
61
61
|
|
|
62
|
-
Tested on macOS 15 (Apple silicon), Ubuntu 24.04 under X11 and Windows Server 2025; Wayland is not supported. Encoding needs about 8 GB of memory. StreamEmbed pins torch 2.
|
|
62
|
+
Tested on macOS 15 (Apple silicon), Ubuntu 24.04 under X11 and Windows Server 2025; Wayland is not supported. Encoding needs about 8 GB of memory. StreamEmbed pins torch 2.14.1 and transformers 5.17.0, so install it in an environment of its own if your project needs other versions.
|
|
63
63
|
|
|
64
64
|
## Reference
|
|
65
65
|
|
|
@@ -4,9 +4,9 @@ Everything the README leaves out: every command and function, all settings, the
|
|
|
4
4
|
|
|
5
5
|
## Requirements
|
|
6
6
|
|
|
7
|
-
Python 3.12 or later. Tested on macOS 15 (Apple silicon, GPU), Ubuntu 24.04 under X11 (Xvfb; CPU) and Windows Server 2025 (CPU): installing, indexing a folder, searching, capturing, and the background service (start, pause, resume, stop, restart after a reboot). Not tested: Wayland (not supported), Windows with several monitors, CUDA GPUs. On macOS, capturing the screen needs the Screen & System Audio Recording permission (Screen Recording before macOS 15; no audio is recorded) for the app that runs Python: the terminal app, or for the background service the Python itself. No command can grant it: `build_index_from_now` opens that pane in System Settings and raises `PermissionError` saying what to turn on, until it is granted. On Windows, capture needs a logged-in desktop session: while the screen is locked, captures fail and are retried. Indexing `~/Desktop` on macOS needs access to it for the terminal (or, for `streamembed start --folder`, the service's Python): allow it in System Settings > Privacy & Security > Files and Folders; without it, indexing stops with a permission error.
|
|
7
|
+
Python 3.12 or later. Tested on macOS 15 (Apple silicon, GPU), Ubuntu 24.04 under X11 (Xvfb; CPU) and Windows Server 2025 (CPU): installing, indexing a folder, searching, capturing, and the background service (start, pause, resume, stop, restart after a reboot). Not tested: Wayland (not supported), Windows with several monitors, CUDA GPUs. On macOS, capturing the screen needs the Screen & System Audio Recording permission (Screen Recording before macOS 15; no audio is recorded) for the app that runs Python: the terminal app, or for the background service the Python itself. No command can grant it: `build_index_from_now` opens that pane in System Settings and raises `PermissionError` saying what to turn on, until it is granted. On macOS 14 and later the screen is grabbed with ScreenCaptureKit; mss grabs it on macOS 13, Linux and Windows, and also takes over any grab ScreenCaptureKit cannot make. On Windows, capture needs a logged-in desktop session: while the screen is locked, captures fail and are retried. Indexing `~/Desktop` on macOS needs access to it for the terminal (or, for `streamembed start --folder`, the service's Python): allow it in System Settings > Privacy & Security > Files and Folders; without it, indexing stops with a permission error.
|
|
8
8
|
|
|
9
|
-
Dependencies are pinned to torch 2.
|
|
9
|
+
Dependencies are pinned to torch 2.14.1 and transformers 5.17.0: the stream encoder re-implements parts of the Qwen3-VL forward pass against transformers internals, and its outputs were checked for equality with these versions. Install StreamEmbed in its own environment (for example `uv tool`, `pipx`, or a venv) if your project needs other versions.
|
|
10
10
|
|
|
11
11
|
The `hnsw` index type needs the `hnsw` extra (`pip install "streamembed[hnsw]"`), which installs chroma-hnswlib 0.7.6: hnswlib with prebuilt wheels (the `hnswlib` package itself is a source package that needs a C++ compiler). Its wheels cover Python 3.12; on later Python versions it is built from source. It does not use OpenMP and runs in one process with torch (checked on macOS with torch 2.8.0 on MPS). The other types need only numpy. On Windows, the `hnsw` extra needs the Microsoft C++ Build Tools: it has no prebuilt wheel there. The index type is a setting, not an install choice: `streamembed config set index_type pq` switches an existing index without indexing again.
|
|
12
12
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "streamembed"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.4"
|
|
4
4
|
description = "Search your own screen history by describing what you saw, from screenshots, on your machine"
|
|
5
5
|
readme = "PYPI.md"
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -15,10 +15,11 @@ classifiers = [
|
|
|
15
15
|
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
16
16
|
]
|
|
17
17
|
# The engine re-implements parts of the Qwen3-VL forward against transformers internals, so torch and transformers stay pinned
|
|
18
|
-
# to the versions its outputs were checked for equality with.
|
|
18
|
+
# to the versions its outputs were checked for equality with. torch 2.13 and later free the MPS graph cache in torch.mps.empty_cache();
|
|
19
|
+
# with 2.8 the capture process grew by about 5 MB per encoded frame on Apple silicon (issue #1).
|
|
19
20
|
dependencies = [
|
|
20
|
-
"torch==2.
|
|
21
|
-
"torchvision==0.
|
|
21
|
+
"torch==2.14.1",
|
|
22
|
+
"torchvision==0.29.2",
|
|
22
23
|
"transformers==5.17.0",
|
|
23
24
|
"qwen-vl-utils==0.0.14",
|
|
24
25
|
"huggingface-hub>=0.30",
|
|
@@ -27,6 +28,7 @@ dependencies = [
|
|
|
27
28
|
"pillow>=11",
|
|
28
29
|
"mss>=9,<11", # mss.MSS from 10.2, mss.mss before (capture._grabber)
|
|
29
30
|
"pyobjc-framework-Quartz>=10; sys_platform == 'darwin'",
|
|
31
|
+
"pyobjc-framework-ScreenCaptureKit>=10.1; sys_platform == 'darwin'", # screen grabs on macOS 14+ (sckgrab); mss elsewhere
|
|
30
32
|
]
|
|
31
33
|
|
|
32
34
|
[project.urls]
|
|
@@ -4,7 +4,7 @@ from .api import (Capture, Result, Results, available_index_types, available_mod
|
|
|
4
4
|
from .config import get_config, reset_config, set_config
|
|
5
5
|
from .service import install_service, service_status, uninstall_service
|
|
6
6
|
|
|
7
|
-
__version__ = "0.3.
|
|
7
|
+
__version__ = "0.3.4"
|
|
8
8
|
__all__ = ["Capture", "Result", "Results", "available_index_types", "available_models", "build_index_from_directory", "build_index_from_now", "configure", "query_index",
|
|
9
9
|
"visualize_results", "install_service", "service_status", "uninstall_service", "pause", "resume", "is_paused",
|
|
10
10
|
"get_config", "set_config", "reset_config"]
|
|
@@ -271,8 +271,19 @@ def private(app: str | None, title: str | None) -> bool:
|
|
|
271
271
|
return any(x.casefold() in a for x in lists[0]) or any(x.casefold() in t for x in lists[1])
|
|
272
272
|
|
|
273
273
|
|
|
274
|
+
_SCK: list = [] # sckgrab.available(), checked once
|
|
275
|
+
|
|
276
|
+
|
|
274
277
|
def _grabber():
|
|
275
|
-
"""mss.MSS (mss 10.2 and later; mss.mss
|
|
278
|
+
"""macOS 14 and later: ScreenCaptureKit (sckgrab.Grab, mss for a grab it cannot make). Elsewhere mss.MSS (mss 10.2 and later; mss.mss
|
|
279
|
+
is deprecated there), else mss.mss."""
|
|
280
|
+
if MACOS:
|
|
281
|
+
if not _SCK:
|
|
282
|
+
from . import sckgrab
|
|
283
|
+
_SCK.append(sckgrab.available())
|
|
284
|
+
if _SCK[0]:
|
|
285
|
+
from .sckgrab import Grab
|
|
286
|
+
return Grab
|
|
276
287
|
import mss
|
|
277
288
|
return getattr(mss, "MSS", None) or mss.mss
|
|
278
289
|
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""macOS 14 and later: screen grabs with ScreenCaptureKit, behind the part of the mss interface that capture.screen_frames uses.
|
|
2
|
+
|
|
3
|
+
mss grabs with CGWindowListCreateImage, which Apple deprecated in macOS 14 and obsoleted in the macOS 15 SDK; on macOS 26 a capture-only
|
|
4
|
+
process using it was seen to grow over a day (issue #1). This grabs each display with SCScreenshotManager instead:
|
|
5
|
+
with Grab() as sct:
|
|
6
|
+
sct.monitors # as mss: [all displays, display 1 (main), display 2, ...], left/top/width/height in points
|
|
7
|
+
shot = sct.grab(sct.monitors[1])
|
|
8
|
+
shot.size, shot.rgb # as mss.ScreenShot: (width, height) and packed RGB bytes, at point resolution like mss
|
|
9
|
+
Displays are listed as mss lists them (CGGetActiveDisplayList order, CGDisplayBounds), so display numbers and stream keys do not
|
|
10
|
+
change. A grab that ScreenCaptureKit cannot make is made with mss instead (reported once per process).
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import sys
|
|
15
|
+
import threading
|
|
16
|
+
import time
|
|
17
|
+
from dataclasses import dataclass
|
|
18
|
+
|
|
19
|
+
TIMEOUT_S = 45.0 # below the capture's 60 s "has not returned" watchdog, so the mss fallback still has a chance
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class Shot:
|
|
24
|
+
size: tuple[int, int]
|
|
25
|
+
rgb: bytes
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def available() -> bool:
|
|
29
|
+
"""macOS 14 or later with the ScreenCaptureKit bindings (pyobjc-framework-ScreenCaptureKit) installed."""
|
|
30
|
+
if sys.platform != "darwin":
|
|
31
|
+
return False
|
|
32
|
+
import platform
|
|
33
|
+
try:
|
|
34
|
+
if int(platform.mac_ver()[0].split(".")[0]) < 14:
|
|
35
|
+
return False
|
|
36
|
+
import ScreenCaptureKit
|
|
37
|
+
return hasattr(ScreenCaptureKit, "SCScreenshotManager")
|
|
38
|
+
except (ImportError, ValueError):
|
|
39
|
+
return False
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _wait(start):
|
|
43
|
+
"""start(handler), then the arguments the completion handler was called with. On the main thread the run loop turns while
|
|
44
|
+
waiting, since a handler may be delivered on the main queue."""
|
|
45
|
+
done, out = threading.Event(), []
|
|
46
|
+
|
|
47
|
+
def handler(*args):
|
|
48
|
+
out.append(args)
|
|
49
|
+
done.set()
|
|
50
|
+
|
|
51
|
+
start(handler)
|
|
52
|
+
if threading.current_thread() is threading.main_thread():
|
|
53
|
+
import CoreFoundation as CF
|
|
54
|
+
end = time.monotonic() + TIMEOUT_S
|
|
55
|
+
while not done.is_set() and time.monotonic() < end:
|
|
56
|
+
CF.CFRunLoopRunInMode(CF.kCFRunLoopDefaultMode, 0.01, False)
|
|
57
|
+
else:
|
|
58
|
+
done.wait(TIMEOUT_S)
|
|
59
|
+
if not done.is_set():
|
|
60
|
+
raise TimeoutError(f"ScreenCaptureKit did not answer in {TIMEOUT_S:.0f} s")
|
|
61
|
+
return out[0]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _active_displays() -> list[int]:
|
|
65
|
+
import Quartz
|
|
66
|
+
_, ids, n = Quartz.CGGetActiveDisplayList(32, None, None)
|
|
67
|
+
return list(ids[:n])
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class Grab:
|
|
71
|
+
_content = None # SCShareableContent, kept while the set of displays stays the same
|
|
72
|
+
_content_ids: tuple = ()
|
|
73
|
+
_fallback_said = False
|
|
74
|
+
|
|
75
|
+
def __init__(self):
|
|
76
|
+
self._monitors = None
|
|
77
|
+
self._mss = None
|
|
78
|
+
|
|
79
|
+
def __enter__(self):
|
|
80
|
+
return self
|
|
81
|
+
|
|
82
|
+
def __exit__(self, *exc):
|
|
83
|
+
self.close()
|
|
84
|
+
return False
|
|
85
|
+
|
|
86
|
+
def close(self) -> None:
|
|
87
|
+
if self._mss is not None:
|
|
88
|
+
self._mss.close()
|
|
89
|
+
self._mss = None
|
|
90
|
+
|
|
91
|
+
@property
|
|
92
|
+
def monitors(self) -> list[dict]:
|
|
93
|
+
"""Listed once per Grab (screen_frames makes a new one for every capture)."""
|
|
94
|
+
if self._monitors is None:
|
|
95
|
+
import Quartz
|
|
96
|
+
out = []
|
|
97
|
+
for did in _active_displays():
|
|
98
|
+
r = Quartz.CGRectStandardize(Quartz.CGDisplayBounds(did))
|
|
99
|
+
w, h = r.size.width, r.size.height
|
|
100
|
+
if Quartz.CGDisplayRotation(did) in (90.0, -90.0):
|
|
101
|
+
w, h = h, w
|
|
102
|
+
out.append({"left": int(r.origin.x), "top": int(r.origin.y), "width": int(w), "height": int(h), "id": int(did)})
|
|
103
|
+
if out:
|
|
104
|
+
left, top = min(m["left"] for m in out), min(m["top"] for m in out)
|
|
105
|
+
right, bottom = max(m["left"] + m["width"] for m in out), max(m["top"] + m["height"] for m in out)
|
|
106
|
+
whole = {"left": left, "top": top, "width": right - left, "height": bottom - top}
|
|
107
|
+
else:
|
|
108
|
+
whole = {"left": 0, "top": 0, "width": 0, "height": 0}
|
|
109
|
+
self._monitors = [whole] + out
|
|
110
|
+
return self._monitors
|
|
111
|
+
|
|
112
|
+
def grab(self, monitor: dict):
|
|
113
|
+
try:
|
|
114
|
+
return self._grab(monitor)
|
|
115
|
+
except Exception as e:
|
|
116
|
+
if not Grab._fallback_said:
|
|
117
|
+
Grab._fallback_said = True
|
|
118
|
+
print(f"streamembed: ScreenCaptureKit could not grab the screen ({type(e).__name__}: {e}); using mss when it fails",
|
|
119
|
+
file=sys.stderr, flush=True)
|
|
120
|
+
if self._mss is None:
|
|
121
|
+
import mss
|
|
122
|
+
self._mss = (getattr(mss, "MSS", None) or mss.mss)()
|
|
123
|
+
return self._mss.grab({k: monitor[k] for k in ("left", "top", "width", "height")})
|
|
124
|
+
|
|
125
|
+
@classmethod
|
|
126
|
+
def _display(cls, did: int):
|
|
127
|
+
import ScreenCaptureKit as SCK
|
|
128
|
+
ids = tuple(_active_displays())
|
|
129
|
+
if cls._content is None or ids != cls._content_ids:
|
|
130
|
+
content, err = _wait(SCK.SCShareableContent.getShareableContentWithCompletionHandler_)
|
|
131
|
+
if content is None:
|
|
132
|
+
raise PermissionError(f"ScreenCaptureKit cannot list the displays: {err}")
|
|
133
|
+
cls._content, cls._content_ids = content, ids
|
|
134
|
+
for d in cls._content.displays():
|
|
135
|
+
if d.displayID() == did:
|
|
136
|
+
return d
|
|
137
|
+
cls._content = None
|
|
138
|
+
raise LookupError(f"display {did} is not available to ScreenCaptureKit")
|
|
139
|
+
|
|
140
|
+
def _grab(self, monitor: dict) -> Shot:
|
|
141
|
+
import objc
|
|
142
|
+
import Quartz
|
|
143
|
+
import ScreenCaptureKit as SCK
|
|
144
|
+
from PIL import Image
|
|
145
|
+
did = monitor.get("id") or next(m["id"] for m in self.monitors[1:]
|
|
146
|
+
if all(m[k] == monitor[k] for k in ("left", "top", "width", "height")))
|
|
147
|
+
with objc.autorelease_pool():
|
|
148
|
+
display = self._display(did)
|
|
149
|
+
filt = SCK.SCContentFilter.alloc().initWithDisplay_excludingWindows_(display, [])
|
|
150
|
+
cfg = SCK.SCStreamConfiguration.alloc().init()
|
|
151
|
+
cfg.setWidth_(monitor["width"]) # points, as mss (kCGWindowImageNominalResolution)
|
|
152
|
+
cfg.setHeight_(monitor["height"])
|
|
153
|
+
cfg.setShowsCursor_(False) # mss has no cursor either
|
|
154
|
+
image, err = _wait(lambda h: SCK.SCScreenshotManager.captureImageWithFilter_configuration_completionHandler_(filt, cfg, h))
|
|
155
|
+
if image is None:
|
|
156
|
+
raise RuntimeError(f"ScreenCaptureKit capture failed: {err}")
|
|
157
|
+
w, h = Quartz.CGImageGetWidth(image), Quartz.CGImageGetHeight(image)
|
|
158
|
+
data = Quartz.CGDataProviderCopyData(Quartz.CGImageGetDataProvider(image))
|
|
159
|
+
img = Image.frombuffer("RGB", (w, h), bytes(data), "raw", "BGRX", Quartz.CGImageGetBytesPerRow(image), 1)
|
|
160
|
+
return Shot((w, h), img.tobytes())
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Screen grabs on macOS 14+ go through ScreenCaptureKit (sckgrab.Grab); mss elsewhere, and for a grab ScreenCaptureKit cannot make."""
|
|
2
|
+
import sys
|
|
3
|
+
import types
|
|
4
|
+
|
|
5
|
+
from streamembed import capture, sckgrab
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_grabber_choice(monkeypatch):
|
|
9
|
+
import mss
|
|
10
|
+
stock = getattr(mss, "MSS", None) or mss.mss
|
|
11
|
+
monkeypatch.setattr(capture, "MACOS", True)
|
|
12
|
+
monkeypatch.setattr(capture, "_SCK", [True])
|
|
13
|
+
assert capture._grabber() is sckgrab.Grab
|
|
14
|
+
monkeypatch.setattr(capture, "_SCK", [False]) # macOS 13 or no bindings
|
|
15
|
+
assert capture._grabber() is stock
|
|
16
|
+
monkeypatch.setattr(capture, "MACOS", False)
|
|
17
|
+
monkeypatch.setattr(capture, "_SCK", [True])
|
|
18
|
+
assert capture._grabber() is stock
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_available_needs_macos_14_and_the_bindings(monkeypatch):
|
|
22
|
+
import platform
|
|
23
|
+
monkeypatch.setattr(sys, "platform", "darwin")
|
|
24
|
+
monkeypatch.setitem(sys.modules, "ScreenCaptureKit", types.SimpleNamespace(SCScreenshotManager=object))
|
|
25
|
+
monkeypatch.setattr(platform, "mac_ver", lambda: ("13.6.1", ("", "", ""), ""))
|
|
26
|
+
assert not sckgrab.available()
|
|
27
|
+
monkeypatch.setattr(platform, "mac_ver", lambda: ("26.6", ("", "", ""), ""))
|
|
28
|
+
assert sckgrab.available()
|
|
29
|
+
monkeypatch.setitem(sys.modules, "ScreenCaptureKit", None) # not installed: import fails
|
|
30
|
+
assert not sckgrab.available()
|
|
31
|
+
monkeypatch.setattr(sys, "platform", "linux")
|
|
32
|
+
assert not sckgrab.available()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_a_failed_grab_uses_mss_and_is_reported_once(monkeypatch, capsys):
|
|
36
|
+
import mss
|
|
37
|
+
grabbed = []
|
|
38
|
+
|
|
39
|
+
class FakeMSS:
|
|
40
|
+
def grab(self, m):
|
|
41
|
+
grabbed.append(m)
|
|
42
|
+
return types.SimpleNamespace(size=(m["width"], m["height"]), rgb=b"\0" * 3 * m["width"] * m["height"])
|
|
43
|
+
|
|
44
|
+
def close(self):
|
|
45
|
+
grabbed.append("closed")
|
|
46
|
+
|
|
47
|
+
def fail(self, monitor):
|
|
48
|
+
raise TimeoutError("ScreenCaptureKit did not answer in 45 s")
|
|
49
|
+
|
|
50
|
+
monkeypatch.setattr(mss, "MSS", FakeMSS, raising=False)
|
|
51
|
+
monkeypatch.setattr(sckgrab.Grab, "_grab", fail)
|
|
52
|
+
monkeypatch.setattr(sckgrab.Grab, "_fallback_said", False)
|
|
53
|
+
m = {"left": 0, "top": 0, "width": 4, "height": 2, "id": 1}
|
|
54
|
+
with sckgrab.Grab() as g:
|
|
55
|
+
assert g.grab(m).size == (4, 2)
|
|
56
|
+
assert g.grab(m).size == (4, 2)
|
|
57
|
+
assert grabbed == [{"left": 0, "top": 0, "width": 4, "height": 2}] * 2 + ["closed"]
|
|
58
|
+
assert capsys.readouterr().err.count("ScreenCaptureKit could not grab the screen") == 1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|