-
Notifications
You must be signed in to change notification settings - Fork 1
/
service.py
105 lines (93 loc) · 5.54 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
# -*- coding: UTF-8 -*-
import xbmc, xbmcaddon, xbmcgui
# Script constants
__addon__ = xbmcaddon.Addon()
__addonid__ = __addon__.getAddonInfo('id')
__version__ = __addon__.getAddonInfo('version')
__language__ = __addon__.getLocalizedString
__cwd__ = __addon__.getAddonInfo('path')
def log(txt):
if isinstance (txt,str):
txt = txt.decode("utf-8")
message = u'%s: %s' % (__addonid__, txt)
xbmc.log(msg=message.encode("utf-8"), level=xbmc.LOGDEBUG)
def get_hours_and_minutes(minutes_string):
try:
full_minutes = int(minutes_string)
minutes = full_minutes % 60
hours = full_minutes // 60
return str(hours) + 'h' + str(minutes).zfill(2)
except:
return ''
def get_hours_only(minutes_string):
try:
full_minutes = int(minutes_string)
hours = full_minutes // 60
return str(hours)
except:
return ''
def get_minutes_only(minutes_string):
try:
full_minutes = int(minutes_string)
minutes = full_minutes % 60
return str(minutes).zfill(2)
except:
return ''
class Main:
def __init__( self ):
log("version %s started" % __version__)
self.previousitem = ""
self.monitor = xbmc.Monitor()
self.run_service()
def run_service(self):
while not self.monitor.abortRequested():
if self.monitor.waitForAbort(0.2):
break
if ((xbmc.getCondVisibility("Window.IsActive(Videos)") and xbmc.getCondVisibility("Window.Is(Videos)")) or (xbmc.getCondVisibility("Window.IsActive(MovieInformation)") and xbmc.getCondVisibility("Window.Is(MovieInformation)"))) and not xbmc.getCondVisibility("Container.Scrolling"):
self.selecteditem = xbmc.getInfoLabel("ListItem.DBID")
if (self.selecteditem and self.selecteditem != self.previousitem):
self.previousitem = self.selecteditem
if (xbmc.getInfoLabel("ListItem.DBID") and xbmc.getInfoLabel("ListItem.DBTYPE") and (xbmc.getInfoLabel("ListItem.DBTYPE") == 'movie' or xbmc.getInfoLabel("ListItem.DBTYPE") == 'episode') and not xbmc.getCondVisibility("ListItem.IsFolder")) and xbmc.getInfoLabel("ListItem.Duration"):
try:
tmpval = float(int(xbmc.getInfoLabel("ListItem.Duration")))
if (tmpval > 0) :
self.duration = xbmc.getInfoLabel("ListItem.Duration")
self.dbid = xbmc.getInfoLabel("ListItem.DBID")
self.set_duration_values()
except:
pass
else:
my_container_id = xbmc.getInfoLabel("Window(Home).Property(Durations.WidgetContainerId)")
my_container_window = xbmc.getInfoLabel("Window(Home).Property(Durations.WidgetContainerWindowName)")
if (my_container_id and my_container_window and (xbmc.getCondVisibility("Control.HasFocus("+my_container_id+")") and xbmc.getCondVisibility("Window.IsActive("+my_container_window+")") and xbmc.getCondVisibility("Window.Is("+my_container_window+")")) and not xbmc.getCondVisibility("Window.IsActive(Videos)") and not xbmc.getCondVisibility("Window.IsActive(MovieInformation)")) and not xbmc.getCondVisibility("Container("+my_container_id+").Scrolling"):
self.selecteditem = xbmc.getInfoLabel("Container("+my_container_id+").ListItem.DBID")
if (self.selecteditem and self.selecteditem != self.previousitem):
self.previousitem = self.selecteditem
if (xbmc.getInfoLabel("Container("+my_container_id+").ListItem.DBID") and xbmc.getInfoLabel("Container("+my_container_id+").ListItem.DBTYPE") and (xbmc.getInfoLabel("Container("+my_container_id+").ListItem.DBTYPE") == 'movie' or xbmc.getInfoLabel("Container("+my_container_id+").ListItem.DBTYPE") == 'episode') and not xbmc.getCondVisibility("Container("+my_container_id+").ListItem.IsFolder")) and xbmc.getInfoLabel("Container("+my_container_id+").ListItem.Duration"):
try:
tmpval = float(int(xbmc.getInfoLabel("Container("+my_container_id+").ListItem.Duration")))
if (tmpval > 0) :
self.duration = xbmc.getInfoLabel("Container("+my_container_id+").ListItem.Duration")
self.dbid = xbmc.getInfoLabel("Container("+my_container_id+").ListItem.DBID")
self.set_duration_values()
except:
pass
#run_service end
def set_duration_values(self):
log('Converts: '+self.duration+' min')
# HoursMinutes
hours_and_minutes = get_hours_and_minutes(self.duration)
xbmc.executebuiltin('SetProperty(Durations.HoursMinutes,"'+hours_and_minutes+'",home)')
# Hours
hours_only = get_hours_only(self.duration)
xbmc.executebuiltin('SetProperty(Durations.Hours,"'+hours_only+'",home)')
# Minutes
minutes_only = get_minutes_only(self.duration)
xbmc.executebuiltin('SetProperty(Durations.Minutes,"'+minutes_only+'",home)')
# DBID
xbmc.executebuiltin('SetProperty(Durations.DBID,"'+self.dbid+'",home)')
# InputDurationMinutes
xbmc.executebuiltin('SetProperty(Durations.InputDurationMinutes,"'+self.duration+'",home)')
if (__name__ == "__main__"):
Main()
log('script finished.')