-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
65 lines (44 loc) · 1.79 KB
/
script.py
File metadata and controls
65 lines (44 loc) · 1.79 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
61
62
63
64
65
import os
import sys
import urllib
import urlparse
import xbmcaddon
import xbmcgui
import xbmcplugin
import requests
from threading import Thread
import time
def main():
monitor = xbmc.Monitor()
isPlaying = False;
while not monitor.abortRequested():
# Sleep/wait for abort for 10 seconds
if monitor.waitForAbort(10):
# Abort was requested while waiting. We should exit
break
try:
info = requests.get(status)
isPlaying = info.json()['playing']
connectedToOSMC = info.json()['active']
except requests.exceptions.RequestException as e:
xbmc.sleep(10)
else:
xbmc.sleep(10)
try:
started = xbmcgui.Window(10000).getProperty("spotify-showing") == u'true'
closedByUser = xbmcgui.Window(10000).getProperty("spotify-closed-by-user") == u'true'
except ValueError as e:
started = False
if (isPlaying) and (not started) and (not closedByUser) and connectedToOSMC:
xbmc.executebuiltin('RunAddon("plugin.audio.swcc")')
#wakeup from screensaver by simulating a button activity
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Input.ContextMenu", "id": 1}')
if not isPlaying:
xbmcgui.Window(10000).setProperty("spotify-closed-by-user","false")
xbmc.sleep(2)
#xbmc.log("spotify: isplaying: " + str(isPlaying)+" started: "+str(started)+" closedByUser: "+str(closedByUser)+" connectedToOSMC: "+str(connectedToOSMC))
if __name__ == '__main__':
xbmc.log("spotify connect checker started")
page = 'http://127.0.0.1:4000'
status = page+'/api/info/status'
main()