WIP 1st Script - need guidance
#1
Question 
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:

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

Image
Reply
#2
I think your approach is more complex than it has to be, All you want is the finish time displayed on your skin?

check out http://wiki.xbmc.org/?title=InfoLabels , it's a list of labels already available to xbmc.

All you need is Totaltime = Container(id).Totaltime, mktime (to format Totaltime into an actual datetime object).
and Now = datetime.datetime.now()... then you should be able to just add Totaltime + Now
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#3
nvm.
Reply
#4
(2014-08-25, 16:52)Lunatixz Wrote: I think your approach is more complex than it has to be, All you want is the finish time displayed on your skin?

check out http://wiki.xbmc.org/?title=InfoLabels , it's a list of labels already available to xbmc.

All you need is Totaltime = Container(id).Totaltime, mktime (to format Totaltime into an actual datetime object).
and Now = datetime.datetime.now()... then you should be able to just add Totaltime + Now

Thanks for the help, that is very useful.

A newb question: Is this code intended to be used directly in the skin or in a seperate script ? I'm guessing script.

Container(id).Totaltime --> gives me the total time of all the movies in my library 484:03:17 (484 hrs 03 min. 17 sec)

Is there a way to get just the highlighted movie Totaltime ?

This is the code the skin uses to display current movie time in minutes (as seen in my screenshot above (126 minutes)):
Code:
    <variable name="value_ground16_value">
    <value condition="[Container.Content(movies) | Window.IsVisible(VideoPlaylist) | Container.Content(musicvideos) | Container.Content(sets)] + !SubString(ListItem.Duration,min)">$INFO[ListItem.Duration,, $LOCALIZE[31961]] $INFO[Window(0).Property(Set.Movies.Runtime),, $LOCALIZE[31961]]</value>
    <value condition="[Container.Content(movies) | Window.IsVisible(VideoPlaylist) | Container.Content(musicvideos) | Container.Content(sets)] + SubString(ListItem.Duration,min)">$INFO[ListItem.Duration]$INFO[Window(0).Property(Set.Movies.Runtime)]</value>
    <value condition="Container.Content(tvshows) | Container.Content(seasons) | Container.Content(episodes)">$INFO[Window(0).Property(NextAired.Status)]</value>
    <value condition="Container.Content(artists)">$INFO[ListItem.Property(Artist_Formed)]$INFO[ListItem.Property(Artist_Disbanded), / ]</value><!-- Formado/sem banda -->
    <value condition="Container.Content(albums)">$INFO[ListItem.Property(Album_Label)]</value>
    </variable>

Thanks again for the help.
Reply
#5
My bad... have you tried below labels, might do what you want without the need for extra code.
Code:
ListItem.StartTime    Start time of current selected TV programme in a list or thumb control
ListItem.EndTime    End time of current selected TV programme in a list or thumb control
ListItem.StartDate    Start date of current selected TV programme in a list or thumb control
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#6
Nope unfortunately those show blank for movies (only my TV shows work with it).

ListItem.Duration --> gives me the movie length

However adding it to the current time I think is beyond what a skin can do and will require a script.

Thanks for ideas though, keep them coming.

1) So now that I have a script, where would I call it in the Skin ? I'm guessing on an event like <onright> as I scroll through the movie list or <onload> at the beginning ?
2) What is the code to use in the skin to retrieve/display the string variable this script generates (varFinishTime) in a <label> ?
Reply
#7
Did you get any further with this idea? I'd really like the ability to view the time now/duration/end time of a movie/tv prog while scrolling through a list.
Reply
#8
(2014-09-02, 16:04)evangelion Wrote: Did you get any further with this idea? I'd really like the ability to view the time now/duration/end time of a movie/tv prog while scrolling through a list.

Yeah, the script works fine.

I'm still looking for help with the code needed to integrate it into a skin to call my script and display the information the script generates.
Reply

Logout Mark Read Team Forum Stats Members Help
1st Script - need guidance0