-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathservice.py
132 lines (110 loc) · 5.31 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from xbmc import Monitor
from resources.lib.addon.plugin import get_setting, get_condvisibility
from resources.lib.addon.window import get_property, wait_for_property
from resources.lib.monitor.cronjob import CronJobMonitor
from resources.lib.monitor.listitem import ListItemMonitor
from resources.lib.monitor.player import PlayerMonitor
from threading import Thread
def restart_service_monitor():
if get_property('ServiceStarted') == 'True':
wait_for_property('ServiceStop', value='True', set_property=True) # Stop service
wait_for_property('ServiceStop', value=None) # Wait until Service clears property
Thread(target=ServiceMonitor().run).start()
class ServiceMonitor(object):
def __init__(self):
self.exit = False
self.listitem = None
self.cron_job = CronJobMonitor(get_setting('library_autoupdate_hour', 'int'))
self.cron_job.setName('Cron Thread')
self.player_monitor = None
self.listitem_monitor = ListItemMonitor()
self.xbmc_monitor = Monitor()
def _on_listitem(self):
self.listitem_monitor.get_listitem()
self.xbmc_monitor.waitForAbort(0.2)
def _on_scroll(self):
self.listitem_monitor.clear_on_scroll()
self.xbmc_monitor.waitForAbort(0.2)
def _on_fullscreen(self):
if self.player_monitor.isPlayingVideo():
self.player_monitor.current_time = self.player_monitor.getTime()
self.xbmc_monitor.waitForAbort(1)
def _on_idle(self):
self.xbmc_monitor.waitForAbort(30)
def _on_modal(self):
self.xbmc_monitor.waitForAbort(1)
def _on_context(self):
self.listitem_monitor.get_context_listitem()
self.xbmc_monitor.waitForAbort(1)
def _on_clear(self):
"""
IF we've got properties to clear lets clear them and then jump back in the loop
Otherwise we should sit for a second so we aren't constantly polling
"""
if self.listitem_monitor.properties or self.listitem_monitor.index_properties:
return self.listitem_monitor.clear_properties()
self.listitem_monitor.blur_fallback()
self.xbmc_monitor.waitForAbort(1)
def _on_exit(self):
if not self.xbmc_monitor.abortRequested():
self.listitem_monitor.clear_properties()
get_property('ServiceStarted', clear_property=True)
get_property('ServiceStop', clear_property=True)
del self.player_monitor
del self.listitem_monitor
del self.xbmc_monitor
def poller(self):
while not self.xbmc_monitor.abortRequested() and not self.exit:
if get_property('ServiceStop'):
self.cron_job.exit = True
self.exit = True
# If we're in fullscreen video then we should update the playermonitor time
elif get_condvisibility("Window.IsVisible(fullscreenvideo)"):
self._on_fullscreen()
# Sit idle in a holding pattern if the skin doesn't need the service monitor yet
elif get_condvisibility(
"System.ScreenSaverActive | "
"[!Skin.HasSetting(TMDbHelper.Service) + "
"!Skin.HasSetting(TMDbHelper.EnableBlur) + "
"!Skin.HasSetting(TMDbHelper.EnableDesaturate) + "
"!Skin.HasSetting(TMDbHelper.EnableColors)]"):
self._on_idle()
# skip when modal or busy dialogs are opened (e.g. select / progress / busy etc.)
elif get_condvisibility(
"Window.IsActive(DialogSelect.xml) | "
"Window.IsActive(progressdialog) | "
"Window.IsActive(busydialog) | "
"Window.IsActive(shutdownmenu) | "
"!String.IsEmpty(Window.Property(TMDbHelper.ServicePause))"):
self._on_modal()
# manage context menu separately from other modals to pass info through
elif get_condvisibility(
"Window.IsActive(contextmenu) | "
"!String.IsEmpty(Window.Property(TMDbHelper.ContextMenu))"):
self._on_context()
# skip when container scrolling
elif get_condvisibility("Container.Scrolling"):
self._on_scroll()
# media window is opened or widgetcontainer set - start listitem monitoring!
elif get_condvisibility(
"Window.IsMedia | "
"!String.IsEmpty(Window(Home).Property(TMDbHelper.WidgetContainer)) | "
"!String.IsEmpty(Window.Property(TMDbHelper.WidgetContainer)) | "
"Window.IsVisible(movieinformation) | "
"Window.IsVisible(musicinformation) | "
"Window.IsVisible(songinformation) | "
"Window.IsVisible(addoninformation) | "
"Window.IsVisible(pvrguideinfo) | "
"Window.IsVisible(tvchannels) | "
"Window.IsVisible(tvguide)"):
self._on_listitem()
# Otherwise just sit here and wait
else:
self._on_clear()
# Some clean-up once service exits
self._on_exit()
def run(self):
get_property('ServiceStarted', 'True')
self.cron_job.start()
self.player_monitor = PlayerMonitor()
self.poller()