|
| 1 | +# -*- coding: UTF-8 -*- |
| 2 | + |
| 3 | +import xbmc, xbmcaddon, xbmcgui |
| 4 | + |
| 5 | +# Script constants |
| 6 | +__addon__ = xbmcaddon.Addon() |
| 7 | +__addonid__ = __addon__.getAddonInfo('id') |
| 8 | +__version__ = __addon__.getAddonInfo('version') |
| 9 | +__language__ = __addon__.getLocalizedString |
| 10 | +__cwd__ = __addon__.getAddonInfo('path') |
| 11 | + |
| 12 | +def log(txt): |
| 13 | + if isinstance (txt,str): |
| 14 | + txt = txt.decode("utf-8") |
| 15 | + message = u'%s: %s' % (__addonid__, txt) |
| 16 | + xbmc.log(msg=message.encode("utf-8"), level=xbmc.LOGDEBUG) |
| 17 | + |
| 18 | +def get_hours_and_minutes(minutes_string): |
| 19 | + try: |
| 20 | + full_minutes = int(minutes_string) |
| 21 | + minutes = full_minutes % 60 |
| 22 | + hours = full_minutes // 60 |
| 23 | + return str(hours) + 'h' + str(minutes).zfill(2) |
| 24 | + except: |
| 25 | + return '' |
| 26 | + |
| 27 | +def get_hours_only(minutes_string): |
| 28 | + try: |
| 29 | + full_minutes = int(minutes_string) |
| 30 | + hours = full_minutes // 60 |
| 31 | + return str(hours) |
| 32 | + except: |
| 33 | + return '' |
| 34 | + |
| 35 | +def get_minutes_only(minutes_string): |
| 36 | + try: |
| 37 | + full_minutes = int(minutes_string) |
| 38 | + minutes = full_minutes % 60 |
| 39 | + return str(minutes).zfill(2) |
| 40 | + except: |
| 41 | + return '' |
| 42 | + |
| 43 | +class Main: |
| 44 | + def __init__( self ): |
| 45 | + log("version %s started" % __version__) |
| 46 | + self.run_backend() |
| 47 | + |
| 48 | + def run_backend(self): |
| 49 | + self.previousitem = "" |
| 50 | + while 1: |
| 51 | + 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"): |
| 52 | + self.selecteditem = xbmc.getInfoLabel("ListItem.DBID") |
| 53 | + if (self.selecteditem != self.previousitem): |
| 54 | + #xbmc.executebuiltin('Notification(Hello World,test,500)') |
| 55 | + self.previousitem = self.selecteditem |
| 56 | + |
| 57 | + if (xbmc.getInfoLabel("ListItem.DBID") > -1 and not xbmc.getCondVisibility("ListItem.IsFolder")) and xbmc.getInfoLabel("ListItem.Duration") and int(float(xbmc.getInfoLabel("ListItem.Duration"))) > 0: |
| 58 | + self.duration = xbmc.getInfoLabel("ListItem.Duration") |
| 59 | + self.dbid = xbmc.getInfoLabel("ListItem.DBID") |
| 60 | + self.display_duration() |
| 61 | + else: |
| 62 | + my_container_id = xbmc.getInfoLabel("Window(Home).Property(Duration.WidgetContainerId)") |
| 63 | + my_container_window = xbmc.getInfoLabel("Window(Home).Property(Duration.WidgetContainerWindowName)") |
| 64 | + |
| 65 | + 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"): |
| 66 | + #xbmc.executebuiltin('Notification(Hello World,'+my_container_id+' '+my_container_window+',500)') |
| 67 | + self.selecteditem = xbmc.getInfoLabel("Container("+my_container_id+").ListItem.DBID") |
| 68 | + if (self.selecteditem != self.previousitem): |
| 69 | + self.previousitem = self.selecteditem |
| 70 | + if (xbmc.getInfoLabel("Container("+my_container_id+").ListItem.DBID") > -1 and not xbmc.getCondVisibility("Container("+my_container_id+").ListItem.IsFolder")) and xbmc.getInfoLabel("Container("+my_container_id+").ListItem.Duration") and int(float(xbmc.getInfoLabel("Container("+my_container_id+").ListItem.Duration"))) > 0: |
| 71 | + self.duration = xbmc.getInfoLabel("Container("+my_container_id+").ListItem.Duration") |
| 72 | + self.dbid = xbmc.getInfoLabel("Container("+my_container_id+").ListItem.DBID") |
| 73 | + self.display_duration() |
| 74 | + xbmc.sleep(200) |
| 75 | + |
| 76 | + def display_duration(self): |
| 77 | + log('Converts: '+self.duration+' min') |
| 78 | + #xbmc.executebuiltin('Notification(Hello World,'+self.duration+' '+self.dbid+',250)') |
| 79 | + |
| 80 | + # HoursMinutes |
| 81 | + hours_and_minutes = get_hours_and_minutes(self.duration) |
| 82 | + xbmc.executebuiltin('SetProperty(Duration.HoursMinutes,'+hours_and_minutes+',home)') |
| 83 | + # Hours |
| 84 | + hours_only = get_hours_only(self.duration) |
| 85 | + xbmc.executebuiltin('SetProperty(Duration.Hours,'+hours_only+',home)') |
| 86 | + # Minutes |
| 87 | + minutes_only = get_minutes_only(self.duration) |
| 88 | + xbmc.executebuiltin('SetProperty(Duration.Minutes,'+minutes_only+',home)') |
| 89 | + # DBID |
| 90 | + xbmc.executebuiltin('SetProperty(Duration.DBID,'+self.dbid+',home)') |
| 91 | + # InputDurationMinutes |
| 92 | + xbmc.executebuiltin('SetProperty(Duration.InputDurationMinutes,'+self.duration+',home)') |
| 93 | + |
| 94 | +if (__name__ == "__main__"): |
| 95 | + Main() |
| 96 | +log('script finished.') |
0 commit comments