Skip to content

Commit 69f7c3d

Browse files
author
Roman Miroshnychenko (Work)
committed
Adds a usage example for setArt method; minor code changes
1 parent a433b56 commit 69f7c3d

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

addon.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<addon id="plugin.video.example"
3-
version="1.1.0"
3+
version="1.2.0"
44
name="Example Kodi Video Plugin"
55
provider-name="Roman_V_M">
66
<requires>

main.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import xbmcplugin
1111

1212
# Get the plugin url in plugin:// notation.
13-
__url__ = sys.argv[0]
13+
_url = sys.argv[0]
1414
# Get the plugin handle as an integer number.
15-
__handle__ = int(sys.argv[1])
15+
_handle = int(sys.argv[1])
1616

1717
# Free sample videos are provided by www.vidsplay.com
1818
# Here we use a fixed set of properties simply for demonstrating purposes
@@ -105,19 +105,19 @@ def list_categories():
105105
list_item.setInfo('video', {'title': category, 'genre': category})
106106
# Create a URL for the plugin recursive callback.
107107
# Example: plugin://plugin.video.example/?action=listing&category=Animals
108-
url = '{0}?action=listing&category={1}'.format(__url__, category)
108+
url = '{0}?action=listing&category={1}'.format(_url, category)
109109
# is_folder = True means that this item opens a sub-list of lower level items.
110110
is_folder = True
111111
# Add our item to the listing as a 3-element tuple.
112112
listing.append((url, list_item, is_folder))
113113
# Add our listing to Kodi.
114114
# Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
115115
# instead of adding one by ove via addDirectoryItem.
116-
xbmcplugin.addDirectoryItems(__handle__, listing, len(listing))
116+
xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
117117
# Add a sort method for the virtual folder items (alphabetically, ignore articles)
118-
xbmcplugin.addSortMethod(__handle__, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
118+
xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
119119
# Finish creating a virtual folder.
120-
xbmcplugin.endOfDirectory(__handle__)
120+
xbmcplugin.endOfDirectory(_handle)
121121

122122

123123
def list_videos(category):
@@ -139,12 +139,15 @@ def list_videos(category):
139139
list_item.setProperty('fanart_image', video['thumb'])
140140
# Set additional info for the list item.
141141
list_item.setInfo('video', {'title': video['name'], 'genre': video['genre']})
142+
# Set additional graphics (banner, poster, landscape etc.) for the list item.
143+
# Again, here we use the same image as the thumbnail for simplicity's sake.
144+
list_item.setArt({'landscape': video['thumb']})
142145
# Set 'IsPlayable' property to 'true'.
143146
# This is mandatory for playable items!
144147
list_item.setProperty('IsPlayable', 'true')
145148
# Create a URL for the plugin recursive callback.
146149
# Example: plugin://plugin.video.example/?action=play&video=http://www.vidsplay.com/vids/crab.mp4
147-
url = '{0}?action=play&video={1}'.format(__url__, video['video'])
150+
url = '{0}?action=play&video={1}'.format(_url, video['video'])
148151
# Add the list item to a virtual Kodi folder.
149152
# is_folder = False means that this item won't open any sub-list.
150153
is_folder = False
@@ -153,11 +156,11 @@ def list_videos(category):
153156
# Add our listing to Kodi.
154157
# Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
155158
# instead of adding one by ove via addDirectoryItem.
156-
xbmcplugin.addDirectoryItems(__handle__, listing, len(listing))
159+
xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
157160
# Add a sort method for the virtual folder items (alphabetically, ignore articles)
158-
xbmcplugin.addSortMethod(__handle__, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
161+
xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
159162
# Finish creating a virtual folder.
160-
xbmcplugin.endOfDirectory(__handle__)
163+
xbmcplugin.endOfDirectory(_handle)
161164

162165

163166
def play_video(path):
@@ -169,7 +172,7 @@ def play_video(path):
169172
# Create a playable item with a path to play.
170173
play_item = xbmcgui.ListItem(path=path)
171174
# Pass the item to the Kodi player.
172-
xbmcplugin.setResolvedUrl(__handle__, True, listitem=play_item)
175+
xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)
173176

174177

175178
def router(paramstring):
@@ -181,7 +184,7 @@ def router(paramstring):
181184
"""
182185
# Parse a URL-encoded paramstring to the dictionary of
183186
# {<parameter>: <value>} elements
184-
params = dict(parse_qsl(paramstring[1:]))
187+
params = dict(parse_qsl(paramstring))
185188
# Check the parameters passed to the plugin
186189
if params:
187190
if params['action'] == 'listing':
@@ -198,4 +201,5 @@ def router(paramstring):
198201

199202
if __name__ == '__main__':
200203
# Call the router function and pass the plugin call parameters to it.
201-
router(sys.argv[2])
204+
# We use string slicing to trim the leading '?' from the plugin call paramstring
205+
router(sys.argv[2][1:])

0 commit comments

Comments
 (0)