-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreengrabber.py
60 lines (48 loc) · 1.54 KB
/
screengrabber.py
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
import os
import time
from PIL import Image as im
import mss
import numpy as np
if __name__ == "__main__":
with mss.mss() as sct:
image_format = ".gif"
picture_counter = 0
max_pictures = 5
sleep_time_secs = 2
# information of monitor
monitor_number = 1
mon = sct.monitors[monitor_number]
# screen part to capture
width = 1920
height = 1080
# this setting takes a centered screenshot
# (if captured resolution < screen resolution)
monitor = {
"top": mon["top"] + int((mon["height"] - height) / 2),
"left": mon["left"] + int((mon["width"] - width) / 2),
"width": width,
"height": height,
"mon": monitor_number,
}
while True:
sct_img = sct.grab(monitor)
image_resized = im.frombytes(
"RGB", sct_img.size, sct_img.bgra, "raw", "BGRX"
)
image_resized.save(
"\\\mfs\mfs\kodi-sync\infoscreens\screen"
+ str(picture_counter)
+ image_format
)
try:
os.remove(
"\\\mfs\mfs\kodi-sync\infoscreens\screen"
+ str(5 - picture_counter)
+ image_format
)
except:
pass
picture_counter = picture_counter + 1
if picture_counter > max_pictures:
picture_counter = 0
time.sleep(sleep_time_secs)