-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.py
54 lines (36 loc) · 1.36 KB
/
service.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
import time
import xbmc
from addon.gmusic_wrapper import GMusic
from addon import ADDON
GMUSIC = GMusic.get(debug_logging=False)
def _get_update_interval():
try:
update_interval = int(ADDON.getSetting('update_interval'))
except Exception:
update_interval = 0
return update_interval * 60 * 60 # We need seconds
def _get_library_last_updated():
try:
library_last_updated = int(ADDON.getSetting('library_last_updated'))
except Exception:
library_last_updated = 0
return library_last_updated
if __name__ == '__main__':
monitor = xbmc.Monitor()
while not monitor.abortRequested():
if monitor.waitForAbort(30):
# Abort was requested while waiting. We should exit
break
update_interval = _get_update_interval()
library_last_updated = _get_library_last_updated()
if update_interval == 0:
continue
if time.time() >= library_last_updated + update_interval:
ADDON.setSetting('library_last_updated', str(int(time.time())))
try:
if GMUSIC.login():
GMUSIC.get_my_library_songs(from_cache=False)
GMUSIC.get_my_library_artists(from_cache=False)
GMUSIC.get_my_library_albums(from_cache=False)
except Exception:
continue