forked from lifansama/plus1s.live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.py
70 lines (54 loc) · 1.7 KB
/
stream.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
61
62
63
64
65
66
67
68
69
70
"""
python version of plus1s
"""
from __future__ import print_function, unicode_literals
import time
try:
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
except ImportError:
from http.server import HTTPServer, BaseHTTPRequestHandler
MAX_FRAMES = 360
frames = []
class Plus1sHTTPRequestHandler(BaseHTTPRequestHandler):
def redirect_to_github(self):
'''
https://github.com/HFO4/plus1s.live
'''
self.send_response(302)
self.send_header('Location', 'https://github.com/HFO4/plus1s.live')
self.end_headers()
def write_frame(self, frame):
self.wfile.write(frame)
self.wfile.write(b'\033[2J\033[H')
time.sleep(0.1)
self.wfile.flush()
def do_GET(self):
useragent = self.headers.get('User-Agent', '')
if 'curl' not in useragent:
self.redirect_to_github()
return
loop = 0
self.send_response(200)
self.send_header('Content-Type', 'text/plain')
self.end_headers()
while True:
for frame in frames:
self.write_frame(frame)
loop += 1
if loop > 20:
self.write_frame(b"You've waste too much time, we have to stop you.")
break
def prepare():
print('Prepare frames...')
for i in range(MAX_FRAMES):
filename = 'pic/{0:03}.txt'.format(i + 1)
with open(filename, 'rb') as fp:
frames.append(fp.read())
print('Frames are ready.')
def main():
prepare()
print('Ready to start server')
server_address = ('', 1926)
server = HTTPServer(server_address, Plus1sHTTPRequestHandler)
server.serve_forever()
main()