forked from im85288/service.nextup.notification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.py
81 lines (64 loc) · 3.52 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
import xbmcaddon
import xbmc
import xbmcgui
import os
cwd = xbmcaddon.Addon(id='service.nextup.notification').getAddonInfo('path')
BASE_RESOURCE_PATH = xbmc.translatePath(os.path.join(cwd, 'resources', 'lib'))
sys.path.append(BASE_RESOURCE_PATH)
import Utils as utils
from Player import Player
from ClientInformation import ClientInformation
class Service():
clientInfo = ClientInformation()
addonName = clientInfo.getAddonName()
WINDOW = xbmcgui.Window(10000)
def __init__(self, *args):
addonName = self.addonName
self.logMsg("Starting NextUp Service", 0)
self.logMsg("======== START %s ========" % addonName, 0)
self.logMsg("KODI Version: %s" % xbmc.getInfoLabel("System.BuildVersion"), 0)
self.logMsg("%s Version: %s" % (addonName, self.clientInfo.getVersion()), 0)
self.logMsg("Platform: %s" % (self.clientInfo.getPlatform()), 0)
def logMsg(self, msg, lvl=1):
className = self.__class__.__name__
utils.logMsg("%s %s" % (self.addonName, className), str(msg), int(lvl))
def ServiceEntryPoint(self):
player = Player()
monitor = xbmc.Monitor()
lastFile = None
lastUnwatchedFile = None
while not monitor.abortRequested():
# check every 5 sec
if monitor.waitForAbort(5):
# Abort was requested while waiting. We should exit
break
if xbmc.Player().isPlaying():
try:
playTime = xbmc.Player().getTime()
totalTime = xbmc.Player().getTotalTime()
currentFile = xbmc.Player().getPlayingFile()
addonSettings = xbmcaddon.Addon(id='service.nextup.notification')
notificationtime = addonSettings.getSetting("autoPlaySeasonTime")
nextUpDisabled = addonSettings.getSetting("disableNextUp") == "true"
randomunwatchedtime = addonSettings.getSetting("displayRandomUnwatchedTime")
displayrandomunwatched = addonSettings.getSetting("displayRandomUnwatched") == "true"
if xbmcgui.Window(10000).getProperty("PseudoTVRunning") != "True" and not nextUpDisabled:
if (totalTime - playTime <= int(notificationtime) and (
lastFile is None or lastFile != currentFile)) and totalTime != 0:
lastFile = currentFile
self.logMsg("Calling autoplayback totaltime - playtime is %s" % (totalTime - playTime), 2)
player.autoPlayPlayback()
self.logMsg("Netflix style autoplay succeeded.", 2)
self.logMsg("playtime is %s" % (int(playTime)), 2)
self.logMsg("randomunwatchedtime is %s" % (int(randomunwatchedtime)), 2)
if (int(playTime) >= int(randomunwatchedtime)) and displayrandomunwatched and (
lastUnwatchedFile is None or lastUnwatchedFile != currentFile):
self.logMsg("Calling display unwatched playtime is %s" % (playTime), 2)
lastUnwatchedFile = currentFile
player.displayRandomUnwatched()
except Exception as e:
self.logMsg("Exception in Playback Monitor Service: %s" % e)
pass
self.logMsg("======== STOP %s ========" % self.addonName, 0)
# start the service
Service().ServiceEntryPoint()