Skip to content

Commit

Permalink
rework add_directory()/add_item() so infolabels can be used with add_…
Browse files Browse the repository at this point in the history
…directory()
  • Loading branch information
t0mm0 committed Oct 30, 2011
1 parent bbe01e7 commit ae33681
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 77 deletions.
18 changes: 9 additions & 9 deletions plugin.video.letmewatchthis/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

mode = addon.queries['mode']
play = addon.queries.get('play', None)

print play
if play:
url = addon.queries.get('url', None)
try:
Expand Down Expand Up @@ -110,7 +110,7 @@
if section == 'tv':
addon.add_directory({'mode': 'series',
'url': base_url + url},
title,
{'title': title},
img=thumb,
total_items=total)
else:
Expand All @@ -123,22 +123,22 @@
addon.add_directory({'mode': 'browse',
'section': section,
'genre': genre,
'letter': 'All'}, 'All')
'letter': 'All'}, {'title': 'All'})
addon.add_directory({'mode': 'browse',
'section': section,
'genre': genre,
'letter': '123'}, '#')
'letter': '123'}, {'title': '#'})
for l in string.uppercase:
addon.add_directory({'mode': 'browse',
'section': section,
'genre': genre,
'letter': l}, l)
'letter': l}, {'title': l})

else:
for genre in genres:
addon.add_directory({'mode': 'browse',
'section': section,
'genre': genre}, genre)
'genre': genre}, {'title': genre})


elif mode == 'series':
Expand Down Expand Up @@ -190,9 +190,9 @@


elif mode == 'main':
addon.add_directory({'mode': 'browse', 'section': 'tv'}, 'TV')
addon.add_directory({'mode': 'browse', 'section': ''}, 'Movies')
addon.add_directory({'mode': 'resolver_settings'}, 'Resolver Settings',
addon.add_directory({'mode': 'browse', 'section': 'tv'}, {'title': 'TV'})
addon.add_directory({'mode': 'browse', 'section': ''}, {'title': 'Movies'})
addon.add_directory({'mode': 'resolver_settings'}, {'title': 'Resolver Settings'},
is_folder=False)

elif mode == 'resolver_settings':
Expand Down
19 changes: 9 additions & 10 deletions plugin.video.t0mm0.test/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,20 @@
thumb, url, title, plot = s.groups()
addon.add_directory({'mode': 'series',
'url': base_url + url},
title,
{'title': title},
img=base_url+thumb)

else:
addon.add_directory({'mode': 'tv',
'browse': 'alpha',
'letter': '-'}, '#')
'letter': '-'}, {'title': '#'})
for l in string.uppercase:
addon.add_directory({'mode': 'tv',
'browse': 'alpha',
'letter': l}, l)
'letter': l}, {'title': l})

else:
addon.add_directory({'mode': 'tv', 'browse': 'alpha'}, 'A-Z')
addon.add_directory({'mode': 'tv', 'browse': 'alpha'}, {'title': 'A-Z'})

elif mode == 'series':
url = addon.queries['url']
Expand All @@ -142,19 +142,18 @@
for episode in episodes:
params = episode.split('_')
if len(params) == 5:
ep_url = '%s/player/%s/' % (base_url,
params[2])
ep_url = '%s/player/%s/' % (base_url, params[2])
title = 'S%sE%s - %s (%s)' % (params[0], params[1],
params[3], params[4])
addon.add_video_item(ep_url, {'title': title})
addon.add_video_item({'url': ep_url}, {'title': title})


elif mode == 'main':
addon.show_small_popup('t0mm0 test addon', 'Is now loaded enjoy', 6000,
logo)
addon.add_directory({'mode': 'test'}, '*test links*')
addon.add_directory({'mode': 'tv'}, 'tubeplus.me tv')
addon.add_directory({'mode': 'resolver_settings'}, 'resolver settings',
addon.add_directory({'mode': 'test'}, {'title': '*test links*'})
addon.add_directory({'mode': 'tv'}, {'title': 'tubeplus.me tv'})
addon.add_directory({'mode': 'resolver_settings'}, {'title': 'resolver settings'},
is_folder=False)


Expand Down
91 changes: 33 additions & 58 deletions script.module.t0mm0.common/lib/t0mm0/common/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,27 +464,32 @@ def get_video_playlist(self, new=False):
self.get_playlist(xbmc.PLAYLIST_VIDEO, new)


def add_item(self, play, infolabels, img='', fanart='', resolved=False,
total_items=0, playlist=False, item_type='video'):
def add_item(self, queries, infolabels, img='', fanart='', resolved=False,
total_items=0, playlist=False, item_type='video',
is_folder=False):
'''
Adds an item to the list of entries to be displayed in XBMC or to a
playlist.
Use this method when you want users to be able to select this item to
start playback of a media file. You can either pass the direct URL to
the media file (in which case you must also set ``resolved=True``) or
some other string that will be passed as the 'play' query and can be
used by the addon to resolve to a real media URL.
start playback of a media file. ``queries`` is a dict that will be sent
back to the addon when this item is selected::
add_item({'host': 'youtube.com', 'media_id': 'ABC123XYZ'},
{'title': 'A youtube vid'})
will add a link to::
plugin://your.plugin.id/?host=youtube.com&media_id=ABC123XYZ
.. seealso::
:meth:`add_music_item`, :meth:`add_video_item`,
:meth:`add_directory`
Args:
play (str): The string to be sent to the plugin when the user
plays this entry, or (if ``resolved=True``) a URL to the media to be
played.
queries (dict): A set of keys/values to be sent to the addon when
the user selects this item.
infolabels (dict): A dictionary of information about this media
(see the `XBMC Wiki InfoLabels entry
Expand All @@ -496,9 +501,8 @@ def add_item(self, play, infolabels, img='', fanart='', resolved=False,
fanart (str): A URL to a fanart image for this entry.
resolved (bool): If ``False`` (default), `play` will be sent as a
query to the addon when the item is played. If ``False``, `play`
will be treated as a URL to the media item.
resolved (str): If not empty, ``queries`` will be ignored and
instead the added item will be the exact contentes of ``resolved``.
total_items (int): Total number of items to be added in this list.
If supplied it enables XBMC to show a progress bar as the list of
Expand All @@ -514,10 +518,11 @@ def add_item(self, play, infolabels, img='', fanart='', resolved=False,
'''
infolabels = self.unescape_dict(infolabels)
if not resolved:
play['play'] = 'True'
play = self.build_plugin_url(play)
if not is_folder:
queries['play'] = 'True'
play = self.build_plugin_url(queries)
else:
play = play['url']
play = resolved
listitem = xbmcgui.ListItem(infolabels['title'], iconImage=img,
thumbnailImage=img)
listitem.setInfo(item_type, infolabels)
Expand All @@ -530,75 +535,45 @@ def add_item(self, play, infolabels, img='', fanart='', resolved=False,
else:
self.log_debug('adding item: %s - %s' % (infolabels['title'], play))
xbmcplugin.addDirectoryItem(self.handle, play, listitem,
isFolder=False, totalItems=total_items)
isFolder=is_folder,
totalItems=total_items)


def add_video_item(self, play, infolabels, img='', fanart='',
def add_video_item(self, queries, infolabels, img='', fanart='',
resolved=False, total_items=0, playlist=False):
'''
Convenience method to add a video item to the directory list or a
playlist.
See :meth:`add_item` for full infomation
'''
self.add_item(play, infolabels, img, fanart, resolved, total_items,
self.add_item(queries, infolabels, img, fanart, resolved, total_items,
playlist, item_type='video')


def add_music_item(self, play, infolabels, img='', fanart='',
def add_music_item(self, queries, infolabels, img='', fanart='',
resolved=False, total_items=0, playlist=False):
'''
Convenience method to add a music item to the directory list or a
playlist.
See :meth:`add_item` for full infomation
'''
self.add_item(play, infolabels, img, fanart, resolved, total_items,
self.add_item(queries, infolabels, img, fanart, resolved, total_items,
playlist, item_type='music')


def add_directory(self, queries, title, img='', fanart='',
def add_directory(self, queries, infolabels, img='', fanart='',
total_items=0, is_folder=True):
'''
Add a directory to the list of items to be displayed by XBMC.
When selected by the user, directory will call the addon with the
query values contained in `queries`.
Args:
queries (dict): A set of keys/values to be sent to the addon when
the user selects this item.
title (str): The name to be displayed for this entry.
Kwargs:
img (str): A URL to an image file to be used as an icon for this
entry.
fanart (str): A URL to a fanart image for this entry.
total_items (int): Total number of items to be added in this list.
If supplied it enables XBMC to show a progress bar as the list of
items is being built.
is_folder (bool): if ``True`` (default), when the user selects this
item XBMC will expect the plugin to add another set of items to
display. If ``False``, the 'Loading Directory' message will not be
displayed by XBMC (useful if you want a directory item to do
something like pop up a dialog).
Convenience method to add a directory to the display list or a
playlist.
See :meth:`add_item` for full infomation
'''
title = self.unescape(title)
url = self.build_plugin_url(queries)
self.log_debug(u'adding dir: %s - %s' % (title, url))
listitem = xbmcgui.ListItem(title, iconImage=img,
thumbnailImage=img)
if not fanart:
fanart = self.get_fanart()
listitem.setProperty('fanart_image', fanart)
xbmcplugin.addDirectoryItem(self.handle, url, listitem,
isFolder=is_folder, totalItems=total_items)

self.add_item(queries, infolabels, img, fanart, total_items=total_items,
resolved=self.build_plugin_url(queries),
is_folder=is_folder)

def end_of_directory(self):
'''Tell XBMC that we have finished adding items to this directory.'''
Expand Down

0 comments on commit ae33681

Please sign in to comment.