2014-08-25, 16:47
Hi, this is my first time writing a script for XBMC (Kodi) with the help of your tutorials and google, and could use a few pointers integrating it into XBMC.
I want to have my skin (mq5) call this script to calculate what time a movie will end at while browsing the library and display it in the skin.
I have the math part of the code working, I just need some direction on the following hurdles:
1) What is the code to use in the skin to run this script ?
2) What is the code to use in the skin to retrieve/display the string variable this script generates (varFinishTime) ?
Thanks for the help !
-Nik
Windows 8.1
Gotham 13.2
Skin: Aeon MQ5
Script:
I want to have my skin (mq5) call this script to calculate what time a movie will end at while browsing the library and display it in the skin.
I have the math part of the code working, I just need some direction on the following hurdles:
1) What is the code to use in the skin to run this script ?
2) What is the code to use in the skin to retrieve/display the string variable this script generates (varFinishTime) ?
Thanks for the help !
-Nik
Windows 8.1
Gotham 13.2
Skin: Aeon MQ5
Script:
Code:
# Generates what time a highlighted movie will end at while browsing your library.
import xbmc
import datetime
now = datetime.datetime.now()
varH = now.hour # Grabs current Hour (i.e. 11pm)
varM = now.minute # Grabs current Minute (i.e. 52 minutes)
varMDuration = xbmc.getInfoLabel(ListItem.Duration) # Retrieve highlighted movie length from library/database (in minutes)
varDuration = (varMDuration/60.) # Grabs length of current highlighted movie and Converts it from minutes to hours (i.e. 156 min. movie / 60 = 2.6 hrs = 2:36)
varWhole = int(varDuration) # get whole hours, remove minutes (no rounding) (i.e. 2.6 = 2)
varM = varM + int((varDuration-varWhole) * 60) # current minutes + movie minutes (i.e. (52 + ((2.6 - 2 = 0.6) * 60) == 52 min + (36 min) = 88 minutes)
if varM >59: # Check to see if minutes are over 59, if so additional code is needed to extract hours
varT = (varM/60.) # Convert minutes to hours (i.e. 88 / 60 = 1.46667)
varN = int(varT) # Get whole hours, remove minutes (no rounding) (i.e. 1.46667 = 1)
varM = int((varT-varN) * 60) # Get left over minutes = Remove hours from minutes (i.e. ((1.4667 - 1 = 0.46667) * 60) == 28 minutes)
varH = varH + varWhole + varN # Current hours + Movie hours + any hours from 60 minutes or more (i.e. "11 + 2 + 1 = 14")
else:
varH = varH + varWhole # Current hour + Movie hour length
if varM < 10: # If minutes is 0-9 add a leading zero (i.e. 2:2pm = 2:02pm)
varM = str(varM).zfill(2)
if varH > 12: # find AM or PM
varAMPM = "pm"
else:
varAMPM = "am"
if varH > 12: # Correct hour for 12hr format
varH = varH - 12
varFinishTime = " (ends at " + str(varH) + ":" + str(varM) + str(varAMPM) + ")" # Final string to be imported into skin