forked from latts9923/script.tvtunes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.py
60 lines (46 loc) · 1.77 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
# -*- coding: utf-8 -*-
import os
import sys
import xbmc
import xbmcaddon
if sys.version_info >= (2, 7):
import json
else:
import simplejson as json
# Import the common settings
from resources.lib.settings import log
from resources.lib.settings import Settings
from resources.lib.backend import TunesBackend
ADDON = xbmcaddon.Addon(id='script.tvtunes')
CWD = ADDON.getAddonInfo('path').decode("utf-8")
LIB_DIR = xbmc.translatePath(os.path.join(CWD, 'resources', 'lib').encode("utf-8")).decode("utf-8")
# Class to detect when something in the system has changed
class TvTunesMonitor(xbmc.Monitor):
def onSettingsChanged(self):
log("TvTunesMonitor: Notification of settings change received")
Settings.reloadSettings()
##################################
# Main of the TvTunes Service
##################################
if __name__ == '__main__':
log("Starting TvTunes Service %s" % ADDON.getAddonInfo('version'))
# Check if the settings mean we want to reset the volume on startup
startupVol = Settings.getStartupVolume()
if startupVol < 0:
log("TvTunesService: No Volume Change Required")
else:
log("TvTunesService: Setting volume to %s" % startupVol)
xbmc.executebuiltin('SetVolume(%d)' % startupVol, True)
# Make sure the user wants to play themes
if Settings.isThemePlayingEnabled():
log("TvTunesService: Theme playing enabled")
# Create a monitor so we can reload the settings if they change
systemMonitor = TvTunesMonitor()
# Start looping to perform the TvTune theme operations
main = TunesBackend()
# Start the themes running
main.runAsAService()
del main
del systemMonitor
else:
log("TvTunesService: Theme playing disabled")