Show video information dialog based on new Listitem
#1
Hello guys,

Let's say my addon lists some streams and I focused one stream like in the following picture

Image

My aim is now if I press the 'i' button to show video information of this item, to not show the video info of the selected item but instead
create a new listitem and show the video info of this listitem.

The reason for this is that the API only allows video details for one fixed video id at time so on the first run I list all items but without much info
and than if I want to display movie information the addon should list the info of the new listitem which now holds all good information.

My code to achieve this behaviour (from now by clicking on context menu) is as follows:

Code:
from resources.lib.api import get_json_data

def list_epg_item(id, SESSION):
    url = 'apiurl...'
    json_data = get_json_data(url, SESSION)
    import xbmcgui, xbmc
    item = xbmcgui.ListItem('Test title')
    print('SELECT 1:', item.isSelected()) # prints False
    item.select(True)
    print('SELECT 2:', item.isSelected()) # prints True
    xbmc.executebuiltin('Action(Info)')

The problem is that the video information which is displayed is still from the old listitem, although I selected it 'True'.

Basically the algo would be:
If movie information button is clicked:
- get URI of this Listitem
- get param 'id' from URI
- download info based on 'id'
- create new list item which has more information
- show this listitem instead
Reply
#2
What's the question Smile
Reply
#3
The question is how to achieve this behaviour, or in other words how to get the following algo working:

If movie information button is clicked:
- get URI of this Listitem
- get param 'id' from URI
- download info based on 'id'
- create new list item which has more information
- show this listitem instead
Reply
#4
I am not 100% here...as I dont know how to change items in an existing list I work around that:

Id make a script to run. When tou run it pass the uri from the listiem. Do the parsing and information download.. pass the info back to the skin in a variable. Have thw skin use that/those vars for the info.
Reply
#5
@Torben
Thank you very much for your answer. For now each listitem has a contextmenu 'Load EPG data' this has the id data and if I click it the function for downloading info runs.
The only part which is missing is what you said "pass the info back to the skin in a variable. Have thw skin use that/those vars for the info. "
I would really appreciate it if could write a short example code because I'm not skilled with passing information to skin or window at all.

Here is the contextmenu code:

Code:
item.addContextMenuItems(
    [('Load EPG data', 'xbmc.RunPlugin(plugin://plugin.video.name/?mode=epg&id=%s)' % channel['now']['id'])]
)
Reply
#6
Will do in about 4 hours. Unless someone beats me to it :-)
Reply
#7
Awesome, thank you so much. That would greatly improve the functionality of my tv streaming addons!
Reply
#8
So.. Here's what I do myself, on occasion. If there is another/better way, I'd like to know ofcourse.

I show you how to set a property from script to a value in Kodi, and it updates to reflect whatever you set it to. This can be pretty much whatever you desire, colors, formatted text, images, plugin paths or parts thereof.

I also show that you can set a value directly to a control. I know of no reason to use one over another, and not a lot is possible to set directly and requires the step with the property anyways.

In Python:
Code:
# Needed "library" or whatever it is called:
import xbmcgui

# Get the current active window in a Kodi skin. Probably best when setting values directly to controls:
ACTIVEWINDOW = xbmcgui.Window(xbmcgui.getCurrentWindowId())

# Or you could settle for simply using the "Home" window (I do that for setting properties):
HOMEWINDOW = xbmcgui.Window( 10000 )

# You can ofcourse include all the formatting you like in the information you want to pass. It is probably a good idea to unicode, but do experiment, as that is sort of a mystery to me when to do what.. Depends on your source I guess. (For the actual string shown here it is not necessary)
myInfo = unicode('[COLOR Red][B]Information[/B] I would [I]like[/I] to show..')

# Set a property in Kodi:
ACTIVEWINDOW.setProperty( 'informationFromMyScript' , myInfo) # or use HOMEWINDOW..

# Or set a text directly in a label:
ACTIVEWINDOW.getControl(12345).setLabel(myInfo)

# There is also a getLabel(), and a getProperty() if you need to get something back one day.

You can see many more things to set in: http://mirrors.kodi.tv/docs/python-docs/...mcgui.html

In the skin XML:
Code:
<!-- If you set the label directly and not through a property, you only need the id of the label to be set-->
<control type="label" id="12345">
...
<!-- If you use the activewindow -->
<label>$INFO[Window(NAME_OR_NUMBER_OF_WINDOW_HERE).Property(informationFromMyScript)]</label>

<!-- If you use the Home window -->
<label>$INFO[Window(Home).Property(informationFromMyScript)]</label>
...
<!-- or you could use the "info" tag actually -->
<info>Window(Home).Property(informationFromMyScript)</info>

</control>



HTH and Good luck,
Reply
#9
Thanks for your help, but as I told I'm new to skinning and don't understand where to put xml and how to than retrieve the data to show it back in the VideoInfo Window.

Here is my function that is called from contextmenu:

Code:
def list_epg_item(pid, SESSION):
    url = 'http://...' % pid
    json_data = get_json_data(url, SESSION)
    program_info = json.loads(json_data)['program']
    channel_name = program_info['channel_name']
    cid = program_info['cid']
    countries = program_info['country'].replace('|',', ')
    genres = ', '.join(program_info['genres'])
    categories = ', '.join(program_info['categories'])
    cast = [(c['person'], '') for c in program_info['credits']]
    #director = cast[0][0] if len(cast) == 1 else ''
    desc = program_info['description'].encode('utf-8')
    subtitle = program_info['episode_title']
    thumb = program_info['image_url']
    title = program_info['title']
    if subtitle:
        title = '%s: %s' % (title, subtitle)
    year = program_info['year']
    #item = xbmcgui.ListItem(id)
    #print('SELECT 1:', item.isSelected())
    #item.select(True)
    #print('SELECT 2:', item.isSelected())
    #print(item.getLabel())
    #xbmc.executebuiltin('Action(Info)')

    ACTIVEWINDOW = xbmcgui.Window(xbmcgui.getCurrentWindowId())
    # Set a property in Kodi:
    ACTIVEWINDOW.setProperty( 'informationFromMyScript' , title) # or use HOMEWINDOW..

    # Or set a text directly in a label:
    #ACTIVEWINDOW.getControl(12345).setLabel(title)
    
    item = xbmcgui.ListItem('[B][COLOR red]%s[/COLOR][/B] %s' % (channel_name, title), thumbnailImage=thumb)
    item.setProperty('IsPlayable', 'true')
    item.select(True)
    #xbmcplugin.addDirectoryItem(handle=ADDON_HANDLE, url='%s?mode=watch&id=%s' % (URI, cid), listitem=item)
    #xbmcplugin.endOfDirectory(ADDON_HANDLE)
    #xbmc.executebuiltin('Action(Highlight)')
    xbmc.executebuiltin('Action(Info)')

Thanks in advance!
Reply
#10
Reading your posts a bit more detailed, I am not really sure you want to do it "my way"..

Seeing as you already have a list showing in a skin, and a way of trapping the "info-button" you could probably just as easily get the list from Kodi and modify that on the fly and return it. (In that I am assuming that the information window in Kodi is relying on the info being in said list.

Either way, you - probably - need to know the ID of the control with the list, within the skin XML. I have no idea where your/an addon displays its list.. But my guess is the ID you need is 50. In myvidenav.xml probably. But as I said, I am not really sure about this!

Sorry if I am adding to the confusion here. I hope someone else will step up and clear it up a bit! Smile
Reply
#11
Ok no problem, thanks for your help anyway!
Reply
#12
For others who are interested in this, too:
It's not possible to modify an existing listitem, but you can draw a new window using PyXBMCt (I think this is basically what Torben did).
I added all my listitems a contextmenu entry with ID and if the case of contextmenu is selected the data will be downloaded and than displayed in the window instead of the listitem.
Not ideal but no other solution possible...
Reply
#13
for anyone else looking, I found the answer here: https://forum.kodi.tv/showthread.php?tid=347155

basically, for the OP, he would do

Code:
def list_epg_item(id, SESSION):
    url = 'apiurl...'
    json_data = get_json_data(url, SESSION)
    import xbmcgui, xbmc
    item = xbmcgui.ListItem('Test title')
    #add all the data to the list item
    dialog = xbmcgui.Dialog()
    dialog.info(item)

only problem is setting a path to plugin:// to play causes kodi to lock up..
if you set directly to the end media - it's ok
Reply
#14
(2021-04-01, 05:35)matthuisman Wrote: only problem is setting a path to plugin:// to play causes kodi to lock up..
if you set directly to the end media - it's ok

Has any solution or workaround to this been found, I need to resolve the URLS after showing the info screen, but yeah sending it a plugin url as the path makes Kodi Crash.
Reply
#15
The above is now fixed in 19.4
Not sure what PR fixed it, it may have been fixed by another bug being fixed.
Reply

Logout Mark Read Team Forum Stats Members Help
Show video information dialog based on new Listitem0