forked from denimnani/service.subloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.py
113 lines (84 loc) · 3.29 KB
/
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
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, sys, xbmc, time
from resources.lib.loadsub import loadsub
from resources.lib.exclusions import globalexclusion
from resources.lib.OSserver import OSusersetting, OSuser
from resources.lib.utils import setting, boolsetting, setsetting, localize, debug, debugsetting
#Main Monitor********************************************************************************************************************************************
class SubLoaderMonitor(xbmc.Monitor):
def __init__(self):
xbmc.Monitor.__init__(self)
debug("Initalized main monitor")
self.run = True
def onSettingsChanged(self):
if self.run:
if debugsetting():
self.run = False
debug('Debug settings changed')
setsetting('debugcheck', value=setting('debug'))
global closedebug
closedebug = boolsetting('debug')
debug('Debug initalized')
if not closedebug:
debug('Debug stopped', force = True)
if OSusersetting():
self.run = False
debug('OS User settings changed')
if OSuser():
xbmc.executebuiltin('Notification("SubLoader", "%s", "%s",)' % (localize(32033), 4000))
setsetting('OSusercheck', value=setting('OSuser'))
setsetting('OSpasswordcheck', value=setting('OSpassword'))
debug('OS Login: successful')
else:
xbmc.executebuiltin('Notification("SubLoader", "%s", "%s",)' % (localize(32034), 4000))
setsetting('OSusercheck', value='nouser')
setsetting('OSpasswordcheck', value='nopassword')
debug('OS Login: unsuccessful')
else:
xbmc.sleep(1000)
self.run = True
monitor = SubLoaderMonitor()
#Player monitor******************************************************************************************************************************************
class SubLoaderPlayer(xbmc.Player):
def __init__(self, *args, **kwargs):
xbmc.Player.__init__(self)
debug('Initalized player monitor')
self.run = True
def onPlayBackStopped(self):
debug('Playback stopped')
self.run = True
def onPlayBackEnded(self):
debug('Playback ended')
self.run = True
def onAVStarted(self):
self.run = True
delay = int(setting('delay'))*1000
if self.run:
xbmc.sleep(delay)
if xbmc.Player().isPlayingVideo() and globalexclusion():
self.run = False
if setting('default') == '0':
debug('Default: automatic subtitles')
loadsub()
# xbmc.executebuiltin('XBMC.RunScript(special://home/addons/service.subloader/resources/lib/testes.py)')
elif setting('default') == '1':
debug('Default: opening search dialog')
xbmc.executebuiltin('XBMC.ActivateWindow(SubtitleSearch)')
else:
debug('Default: do nothing...')
else:
self.run = False
player = SubLoaderPlayer()
#Abort request*******************************************************************************************************************************************
closedebug = boolsetting('debug')
while not xbmc.Monitor().abortRequested():
if xbmc.Monitor().waitForAbort(10):
if closedebug:
debug('Shutdown requested', force = True)
debug('Player monitor stopped', force = True)
debug('Main monitor stopped', force = True)
del player
del monitor
break
#********************************************************************************************************************************************************