-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.py
More file actions
70 lines (61 loc) · 2.79 KB
/
server.py
File metadata and controls
70 lines (61 loc) · 2.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
66
67
68
69
import xbmcaddon
import xbmc, xbmcgui, xbmcvfs
import requests
import base64
import time, datetime
servicing = False
def Service():
global servicing
if servicing:
return
servicing = True
xbmc.log("SERVICE", xbmc.LOGERROR)
xbmc.executebuiltin('XBMC.RunPlugin(plugin://plugin.program.xmltv.meld/update)')
time.sleep(2)
servicing = False
if __name__ == '__main__':
ADDON = xbmcaddon.Addon('plugin.program.xmltv.meld')
version = ADDON.getAddonInfo('version')
if ADDON.getSetting('version') != version:
ADDON.setSetting('version', version)
try:
if ADDON.getSetting('service') == 'true':
monitor = xbmc.Monitor()
xbmc.log("[plugin.program.xmltv.meld] service started...", xbmc.LOGERROR)
if ADDON.getSetting('service.startup') == 'true':
Service()
ADDON.setSetting('last.update', str(time.time()))
while not monitor.abortRequested():
if ADDON.getSetting('service.type') == '1':
interval = int(ADDON.getSetting('service.interval'))
waitTime = 3600 * interval
ts = ADDON.getSetting('last.update') or "0.0"
lastTime = datetime.datetime.fromtimestamp(float(ts))
now = datetime.datetime.now()
nextTime = lastTime + datetime.timedelta(seconds=waitTime)
td = nextTime - now
timeLeft = td.seconds + (td.days * 24 * 3600)
xbmc.log("[plugin.program.xmltv.meld] Service waiting for interval %s" % waitTime, xbmc.LOGERROR)
elif ADDON.getSetting('service.type') == '2':
next_time = ADDON.getSetting('service.time')
if next_time:
hms = next_time.split(':')
hour = hms[0]
minute = hms[1]
now = datetime.datetime.now()
next_time = now.replace(hour=int(hour),minute=int(minute),second=0,microsecond=0)
if next_time < now:
next_time = next_time + datetime.timedelta(hours=24)
td = next_time - now
timeLeft = td.seconds + (td.days * 24 * 3600)
if timeLeft <= 0:
timeLeft = 1
xbmc.log("[plugin.program.xmltv.meld] Service waiting for %d seconds" % timeLeft, xbmc.LOGERROR)
if timeLeft and monitor.waitForAbort(timeLeft):
break
xbmc.log("[plugin.program.xmltv.meld] Service now triggered...", xbmc.LOGERROR)
Service()
now = time.time()
ADDON.setSetting('last.update', str(now))
except:
pass