forked from qijungu/screenshare
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscreen.py
More file actions
executable file
·60 lines (52 loc) · 1.76 KB
/
screen.py
File metadata and controls
executable file
·60 lines (52 loc) · 1.76 KB
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
#Copyright (C) 2021 Qijun Gu
#
#This file is part of Screenshare.
#
#Screenshare is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#Screenshare is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with Screenshare. If not, see <https://www.gnu.org/licenses/>.
import threading, time, base64, sys
ver = sys.version_info.major
if ver==2:
import StringIO as io
elif ver==3:
import io
from PIL import ImageGrab as ig
class Screen():
def __init__(self):
self.FPS = 4
self.screenbuf = ""
self.password = ""
if ver==2:
self.screenfile = io.StringIO()
elif ver==3:
self.screenfile = io.BytesIO()
threading.Thread(target=self.getframes).start()
def __del__(self):
self.screenfile.close()
def getframes(self):
while True:
im = ig.grab()
self.screenfile.seek(0)
self.screenfile.truncate(0)
im_converted = im.convert("RGB")
im_converted.save(self.screenfile, format="jpeg", quality=75, progressive=True)
self.screenbuf = base64.b64encode(self.screenfile.getvalue())
time.sleep(1.0/self.FPS)
def gen(self):
s = ''
if ver==2:
s = self.screenbuf
elif ver==3:
s = self.screenbuf.decode()
return s
screenlive = Screen()