-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitchkot.py
executable file
·69 lines (50 loc) · 1.53 KB
/
twitchkot.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
import web
import subprocess
import os
import signal
import threading
render = web.template.render('templates/', base='layout')
nameplayer = "livestreamer"
omxplayer = "\"omxplayer --adev local --win '35 35 1885 1045'\""
#omxplayer = "vlc"
player = None
urls = (
'/', 'Index',
'/index', 'Index',
)
class Index:
def GET(self):
return render.index()
def POST(self):
global player
data = web.input(placeImg={})
method = data.get("method", "malformed")
if 'channel' in data :
channel = data['channel']
if player == None :
player = PlayerThread(channel)
else:
stop_watching()
player.channel = channel
render.index()
return player.run()
class PlayerThread(threading.Thread):
def __init__(self,channel):
threading.Thread.__init__(self)
self.channel = channel
self.running = False
def run(self):
self.running = True
command = "livestreamer -np " + omxplayer + " --twitch-oauth-token 9g056yigicng5hgsonbakyl0ede3fd twitch.tv/"
command = command + self.channel + " best"
os.system(command)
def stop_watching():
if player.running :
player.running = False
pids= map(int, subprocess.check_output(["pidof", omxplayer.split(' ')[0]]).split())
for pid in pids:
os.kill(pid, signal.SIGKILL)
if __name__ == "__main__":
app = web.application(urls, globals())
web.config.debug = False
app.run()