Kodi Community Forum
Can't really add/view label2 in listitem [Add-on development] - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: Can't really add/view label2 in listitem [Add-on development] (/showthread.php?tid=377837)



Can't really add/view label2 in listitem [Add-on development] - FrankWierd - 2024-06-06

I created a simple addon to test how to use label2, i want result like this image :

Image

Or something like youtube addon(left is title,and colored likes and views,on the right duration | date):

Image



But real result is this :

Image


And this is my python code :

python:
import sys
import xbmcgui
import xbmcplugin

_url = sys.argv[0]
_handle = int(sys.argv[1])

def get_videos():
    videos_data = [
        ('njn Ford Coppola Teaser Trailer', '01:31', '14/05/2024', '1K likes', '15K views'),
        ('Francis Ford Coppola Teaser Trailer', '02:16', '04/05/2024', '1K likes', '15K views'),
        ('lll Ford Coppola Teaser Trailer', '28:15', '22/02/2022', '1K likes', '15K views'),
    ]
    return videos_data


def list_videos():
    for title, duration, date, likes, views in get_videos():
        list_item = xbmcgui.ListItem(label=title)
        list_item.setLabel2(' | '.join([duration, date]))
        list_item.setInfo('video', {'title': title, 'duration': duration})
        list_item.setProperty('fanart_image', 'fanart.jpg')
        list_item.setProperty('icon', 'icon.png')
        xbmcplugin.addDirectoryItem(_handle, _url, list_item, isFolder=False)
    xbmcplugin.endOfDirectory(_handle)



list_videos()

addon.xml, if needed :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<addon id="plugin.video.myaddon_w" name="My Movie Addon" version="1.0.0" provider-name="Your Name">
    <requires>
        <import addon="xbmc.python" version="3.0.0"/>
    </requires>
    <extension point="xbmc.addon.metadata">
        <summary>My Video Addon</summary>
        <description>This addon fetches videos with titles, views, likes, date and duration</description>
        <fanart>fanart.jpg</fanart>
        <icon>icon.png</icon>
    </extension>
    <extension point="xbmc.python.pluginsource" library="addon.py">
        <description>My Movie Addon</description>
        <provides>video</provides>
    </extension>
    
</addon>

What's wrong with my code?


RE: Can't really add/view label2 in listitem [Add-on development] - DarrenHill - 2024-06-07

Thread moved to addon development


RE: Can't really add/view label2 in listitem [Add-on development] - jbinkley60 - 2024-06-07

(2024-06-06, 20:18)FrankWierd Wrote: What's wrong with my code?

Have you looked at the view mode ?  That determines what is displayed by the skin, along with the sort sequence.   Your result looks like a list view.  Depending upon the skin, content type and such you may new to set the view mode.  If you want to go that route I can should you some code for setting the view mode but typically it is easier just to set from the let panel manually and have Kodi remember it.


Thanks,

Jeff


RE: Can't really add/view label2 in listitem [Add-on development] - Lunatixz - 2024-06-07

Label2 display is heavily depended on the skin you are using and the content type you set your plugin for. I don't recall offhand which content type will show label2 but one of them should. (Try 'Files')?


RE: Can't really add/view label2 in listitem [Add-on development] - MoojMidge - 2024-06-08

(2024-06-06, 20:18)FrankWierd Wrote: Or something like youtube addon(left is title,and colored likes and views,on the right duration | date):

As others have noted, the use of Label2 will vary depending on a number of factors including the skin being used, the selected view.

The YouTube plugin does not use Label2 to achieve this type of display, it uses label masks as part of applying sort methods to the listings.

https://github.com/anxdpanic/plugin.video.youtube/blob/master/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py#L483

https://xbmc.github.io/docs.kodi.tv/master/kodi-base/d1/d32/group__python__xbmcplugin.html#ga85b3bff796fd644fb28f87b136025f40