-
Notifications
You must be signed in to change notification settings - Fork 0
/
OBS_Monitor.py
69 lines (49 loc) · 2.05 KB
/
OBS_Monitor.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
#! /usr/bin/python3
import asyncio
import urllib.request
import sys
import datetime
from obswsrc import OBSWS
from obswsrc.requests import StartStopStreamingRequest
def logger(logmessage):
f = open("log.txt", "a")
f.write(str(datetime.datetime.now()) + " " + logmessage + "\n")
f.close
async def main():
try:
# set the IP of the OBS computer here
obsws = OBSWS('10.11.0.124', 4444, "password")
# if no response from OBS in 30 seconds EXIT
await asyncio.wait_for(obsws.connect(), timeout=30)
logger("Connection established.")
while True:
event = await obsws.event()
logger(str(format(event.type_name)))
if(format(event.type_name) == "StreamStarting"):
try:
# change the IP to the Screenly OSE computer
# this is the asset_id of the RTMP streaming asset in Screely OSE
HitURLToLoadAsset = urllib.request.urlopen("http://10.11.0.159/api/v1/assets/control/asset&b0983c0918b94856900040d9a9e8bdbf").read()
logger(str(HitURLToLoadAsset))
except:
logger("FAILED TO CONNECT TO SCREENLY OSE")
if(format(event.type_name) == "StreamStopped"):
try:
# change the IP to the Screenly OSE computer
# this is another asset in Screely OSE
HitURLToLoadAsset = urllib.request.urlopen("http://10.11.0.159/api/v1/assets/control/asset&3b2fb67002364b269d0c2674a628533c").read()
logger(str(HitURLToLoadAsset))
except:
logger("FAILED TO CONNECT TO SCREENLY OSE")
except asyncio.TimeoutError:
logger("OBS NOT RUNNING-- TIMEOUT!")
except OSError:
logger("OBS IS NOT RUNNING")
except:
logger(str(sys.exc_info()[1]))
finally:
await obsws.close()
logger("Connection terminated.")
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()