def _video_albums(self):
page = int(self.root.params['page'])
oid = self.root.params['oid']
kwargs = {
'page': page,
'extended': 1
}
albums = media_entries('video.getAlbums', self.root.conn, oid, **kwargs)
if page < albums['pages']:
params = {'do': _DO_VIDEO_ALBUMS,'oid': oid,'page': page + 1}
self.root.add_folder(self.root.gui._string(400602), params)
for a in albums['items']:
list_item = xbmcgui.ListItem(a.info['title'])
list_item.setInfo('video', {'title': a.info['title']})
if 'photo_320' in a.info.keys():
list_item.setArt({'thumb': a.info['photo_160'], 'icon': a.info['photo_160'], 'fanart': a.info['photo_320']})
params = {'do': _DO_VIDEO, 'oid': oid, 'album': a.id, 'page': 1}
url = self.root.url(**params)
xbmcplugin.addDirectoryItem(_addon_id, url, list_item, isFolder = True)
if page < albums['pages']:
params = {'do': _DO_VIDEO_ALBUMS,'oid': oid,'page': page + 1}
self.root.add_folder(self.root.gui._string(400602), params)
xbmcplugin.endOfDirectory(_addon_id)
python类ListItem()的实例源码
def _play_video(self):
vid = self.root.params['vid']
src = self.root.params['source']
v = Entry('video.get', vid, self.root.conn)
try:
v.set_info()
except:
self.root.gui.notify(self.root.gui._string(400524), '')
return
if 'files' in v.info.keys():
paths = {}
if src == _VK_VIDEO_SOURCE:
for k in v.info['files'].keys():
paths[int(k.split('_')[1])] = v.info['files'][k]
else:
v_url = v.info['player']
if src == _VK_VIDEO_SOURCE:
paths = self.root.parse_vk_player_html(v_url)
### ????? ?????? ??????? ?????????? ?? ????????
k = max(filter(lambda x: x <= _SETTINGS_MAX_RES, paths.keys()))
path = paths[k]
play_item = xbmcgui.ListItem(path = path)
xbmcplugin.setResolvedUrl(_addon_id, True, listitem = play_item)
def _members(self):
oid = self.root.params['oid']
page = int(self.root.params['page'])
group = Group(oid, self.root.conn)
members = group.members(page = page)
if page < members['pages']:
params = {'do': _DO_MEMBERS, 'oid': oid, 'page': page + 1}
self.root.add_folder(self.root.gui._string(400602), params)
for m in members['items']:
list_item = xbmcgui.ListItem(u'%s %s' % (m.info['last_name'], m.info['first_name']))
p_key = 'photo_%d' % (max(map(lambda x: int(x.split('_')[1]), filter(lambda x: x.startswith('photo_'), m.info.keys()))),)
list_item.setArt({'thumb': m.info[p_key], 'icon': m.info[p_key]})
params = {'do': _DO_HOME, 'oid': m.id}
url = self.root.url(**params)
xbmcplugin.addDirectoryItem(_addon_id, url, list_item, isFolder = True)
if page < members['pages']:
params = {'do': _DO_MEMBERS, 'oid': oid, 'page': page + 1}
self.root.add_folder(self.root.gui._string(400602), params)
xbmcplugin.endOfDirectory(_addon_id)
def __create_user_group_search_page_(self, do_current, do_target, h_file):
page = int(self.root.params['page'])
self.root.add_folder(self.root.gui._string(400516), {'do': do_target, 'q':'none', 'page': 1})
history = get_search_history(h_file)
count = len(history)
pages = int(ceil(count / float(_SETTINGS_PAGE_ITEMS)))
if page < pages:
params = {'do': do_current, 'page': page + 1}
self.root.add_folder(self._string(400602), params)
h_start = _SETTINGS_PAGE_ITEMS * (page -1)
h_end = h_start + _SETTINGS_PAGE_ITEMS
history = history[h_start:h_end]
for h in history:
query_hex = binascii.hexlify(pickle.dumps(h, -1))
list_item = xbmcgui.ListItem(h)
params = {'do': do_target, 'q': query_hex, 'page': 1}
url = self.root.url(**params)
xbmcplugin.addDirectoryItem(_addon_id, url, list_item, isFolder = True)
if page < pages:
params = {'do': do_current, 'page': page + 1}
self.root.add_folder(self.root.gui._string(400602), params)
xbmcplugin.endOfDirectory(_addon_id)
def show_page(obj):
for talk in obj.get_talks():
url = build_url({'mode': 'play', 'folder_name': talk.url})
li = xbmcgui.ListItem("%s - %s [COLOR=lime][%s][/COLOR][COLOR=cyan] Posted: %s[/COLOR]" % (talk.title, talk.speaker, talk.time, talk.posted))
li.setArt({'thumb': talk.thumb, 'icon': talk.thumb, 'fanart': talk.thumb})
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=True)
if obj.next_page:
url = build_url({'mode': 'page', 'folder_name': obj.next_page})
li = xbmcgui.ListItem("[COLOR=yellow]Next Page %s[/COLOR]" % obj.page_number(obj.next_page))
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=True)
if obj.last_page:
url = build_url({'mode': 'page', 'folder_name': obj.last_page})
li = xbmcgui.ListItem("[COLOR=yellow]Last Page %s[/COLOR]" % obj.page_number(obj.last_page))
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=True)
xbmcplugin.endOfDirectory(addon_handle)
def getListItem(self):
li = ListItem(self.getLabel())
if isinstance(self, PlayableMedia) and getattr(self, 'available', True):
li.setProperty('isplayable', 'true')
artwork = {'thumb': _addon_icon, 'fanart': _addon_fanart}
if getattr(self, 'image', None):
artwork['thumb'] = self.image
if getattr(self, 'fanart', None):
artwork['fanart'] = self.fanart
li.setArt(artwork)
# In Favorites View everything as a Favorite
if self._is_logged_in and hasattr(self, '_isFavorite') and '/favorites/' in sys.argv[0]:
self._isFavorite = True
cm = self.getContextMenuItems()
if len(cm) > 0:
li.addContextMenuItems(cm)
return li
def play_track(track_id, album_id):
media_url = session.get_media_url(track_id, album_id=album_id)
log("Playing: %s" % media_url)
disableInputstreamAddon = False
if not media_url.startswith('http://') and not media_url.startswith('https://') and \
not 'app=' in media_url.lower() and not 'playpath=' in media_url.lower():
# Rebuild RTMP URL
if KODI_VERSION >= (17, 0):
media_url = 'rtmp://%s' % media_url
disableInputstreamAddon = True
else:
host, tail = media_url.split('/', 1)
app, playpath = tail.split('/mp4:', 1)
media_url = 'rtmp://%s app=%s playpath=mp4:%s' % (host, app, playpath)
li = ListItem(path=media_url)
if disableInputstreamAddon:
# Krypton can play RTMP Audio Streams without inputstream.rtmp Addon
li.setProperty('inputstreamaddon', '')
mimetype = 'audio/flac' if session._config.quality == Quality.lossless and session.is_logged_in else 'audio/mpeg'
li.setProperty('mimetype', mimetype)
xbmcplugin.setResolvedUrl(plugin.handle, True, li)
def play_track_cut(track_id, cut_id, album_id):
media_url = session.get_media_url(track_id, cut_id=cut_id, album_id=album_id)
log("Playing Cut %s: %s" % (cut_id, media_url))
disableInputstreamAddon = False
if not media_url.startswith('http://') and not media_url.startswith('https://') and \
not 'app=' in media_url.lower() and not 'playpath=' in media_url.lower():
# Rebuild RTMP URL
if KODI_VERSION >= (17, 0):
media_url = 'rtmp://%s' % media_url
disableInputstreamAddon = True
else:
host, tail = media_url.split('/', 1)
app, playpath = tail.split('/mp4:', 1)
media_url = 'rtmp://%s app=%s playpath=mp4:%s' % (host, app, playpath)
li = ListItem(path=media_url)
if disableInputstreamAddon:
# Krypton can play RTMP Audio Streams without inputstream.rtmp Addon
li.setProperty('inputstreamaddon', '')
mimetype = 'audio/flac' if session._config.quality == Quality.lossless and session.is_logged_in else 'audio/mpeg'
li.setProperty('mimetype', mimetype)
xbmcplugin.setResolvedUrl(plugin.handle, True, li)
def addMenuItem(caption, link, icon=None, thumbnail=None, folder=False, fanart=None):
"""
Add a menu item to the xbmc GUI
Parameters:
caption: the caption for the menu item
icon: the icon for the menu item, displayed if the thumbnail is not accessible
thumbail: the thumbnail for the menu item
link: the link for the menu item
folder: True if the menu item is a folder, false if it is a terminal menu item
Returns True if the item is successfully added, False otherwise
"""
#listItem = xbmcgui.ListItem(unicode(caption), iconImage=icon, thumbnailImage=thumbnail)
listItem = xbmcgui.ListItem(str(caption), iconImage=icon, thumbnailImage=thumbnail)
listItem.setInfo(type="Game", infoLabels={ "Title": caption })
listItem.setProperty('fanart_image', fanart)
return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=link, listitem=listItem, isFolder=folder)
def play(self, item=None, listitem=None, windowed=False, statrpos=-1):
"""
Play this item.
:param item: [opt] string - filename, url or playlist.
:param listitem: [opt] listitem - used with setInfo() to set different infolabels.
:param windowed: [opt] bool - true=play video windowed, false=play users preference.(default)
:param startpos: [opt] int - starting position when playing a playlist. Default = -1
.. note:: If item is not given then the Player will try to play the current item
in the current playlist.
You can use the above as keywords for arguments and skip certain optional arguments.
Once you use a keyword, all following arguments require the keyword.
example::
listitem = xbmcgui.ListItem('Ironman')
listitem.setInfo('video', {'Title': 'Ironman', 'Genre': 'Science Fiction'})
xbmc.Player().play(url, listitem, windowed)
xbmc.Player().play(playlist, listitem, windowed, startpos)
"""
pass
def add(self, url, listitem=None, index=-1):
"""Adds a new file to the playlist.
:param url: string or unicode - filename or url to add.
:param listitem: listitem - used with setInfo() to set different infolabels.
:param index: integer - position to add playlist item.
Example::
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
video = 'F:\\movies\\Ironman.mov'
listitem = xbmcgui.ListItem('Ironman', thumbnailImage='F:\\movies\\Ironman.tbn')
listitem.setInfo('video', {'Title': 'Ironman', 'Genre': 'Science Fiction'})
playlist.add(url=video, listitem=listitem, index=7)
"""
pass
def addMenuItem(self, name, iconImage=None, folder=True, menu=True, **kwargs):
"""Add one submenu item to the list. [internal]"""
if not iconImage:
iconImage = 'DefaultAddonsSearch.png'
# general menu item
# liz = xbmcgui.ListItem(title, iconImage="DefaultFolder.png", thumbnailImage=iconImage)
# liz.setInfo(type="Video", infoLabels={"Title": title})
url = self.buildPluginUrl(name=name, **kwargs)
xbmc.log('SEARCH: create menu item %s, query:"%s", url:"%s"' % (name, kwargs.get('query'), url))
li = xbmcgui.ListItem(kwargs.get('title', ''), iconImage="DefaultFolder.png", thumbnailImage=iconImage)
li.addContextMenuItems([
(_('Remove'), 'RunPlugin(%s)' % (url + '&action=remove')),
(_('Rename'), 'RunPlugin(%s)' % (url + '&action=rename')),
(_('Clean'), 'RunPlugin(%s)' % (url + '&action=clean')),
])
xbmcplugin.addDirectoryItem(handle=self._addonHandle, url=url, listitem=li, isFolder=folder)
def add(self, url, listitem=None, index=-1):
"""Adds a new file to the playlist.
:param url: string or unicode - filename or url to add.
:param listitem: listitem - used with setInfo() to set different infolabels.
:param index: integer - position to add playlist item.
Example::
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
video = 'F:\\movies\\Ironman.mov'
listitem = xbmcgui.ListItem('Ironman', thumbnailImage='F:\\movies\\Ironman.tbn')
listitem.setInfo('video', {'Title': 'Ironman', 'Genre': 'Science Fiction'})
playlist.add(url=video, listitem=listitem, index=7)
"""
pass
def onInit(self):
items = list()
order = ADDON.getSetting("cat.order").split('|')
categories = ["All Channels"] + sorted(self.categories, key=lambda x: order.index(x) if x in order else x.lower())
for label in categories:
item = xbmcgui.ListItem(label)
items.append(item)
listControl = self.getControl(self.C_CAT_CATEGORY)
listControl.addItems(items)
if self.selected_category and self.selected_category in categories:
index = categories.index(self.selected_category)
listControl.selectItem(index)
self.setFocus(listControl)
name = remove_formatting(ADDON.getSetting('categories.background.color'))
color = colors.color_name[name]
control = self.getControl(self.C_CAT_BACKGROUND)
control.setColorDiffuse(color)
def append_subtitle(subname, lang_name, language, params, sync=False, h_impaired=False):
"""Add the subtitle to the list of subtitles to show"""
listitem = xbmcgui.ListItem(
# Languange name to display under the lang logo (for example english)
label=lang_name,
# Subtitle name (for example 'Lost 1x01 720p')
label2=subname,
# Languange 2 letter name (for example en)
thumbnailImage=xbmc.convertLanguage(language, xbmc.ISO_639_1))
# Subtitles synced with the video
listitem.setProperty("sync", 'true' if sync else 'false')
# Hearing impaired subs
listitem.setProperty("hearing_imp", 'true' if h_impaired else 'false')
# Create the url to the plugin that will handle the subtitle download
url = "plugin://{url}/?{params}".format(
url=SCRIPT_ID, params=urllib.urlencode(params))
# Add the subtitle to the list
xbmcplugin.addDirectoryItem(
handle=HANDLE, url=url, listitem=listitem, isFolder=False)
def onInit(self):
try:
self.control_list = self.getControl(6)
self.getControl(5).setNavigation(self.control_list, self.control_list, self.control_list, self.control_list)
self.getControl(3).setEnabled(0)
self.getControl(3).setVisible(0)
except:
pass
try:
self.getControl(99).setVisible(False)
except:
pass
self.getControl(1).setLabel("[COLOR orange]"+self.caption+"[/COLOR]")
self.getControl(5).setLabel("[COLOR tomato][B]Cerrar[/B][/COLOR]")
self.items = []
for item in self.itemlist:
item_l = xbmcgui.ListItem(item.title)
item_l.setArt({'thumb': item.thumbnail})
item_l.setProperty('item_copy', item.tourl())
self.items.append(item_l)
self.control_list.reset()
self.control_list.addItems(self.items)
self.setFocus(self.control_list)
def direct_play(url):
_log("direct_play ["+url+"]")
title = ""
try:
xlistitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", path=url)
except:
xlistitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", )
xlistitem.setInfo( "video", { "Title": title } )
playlist = xbmc.PlayList( xbmc.PLAYLIST_VIDEO )
playlist.clear()
playlist.add( url, xlistitem )
player_type = xbmc.PLAYER_CORE_AUTO
xbmcPlayer = xbmc.Player( player_type )
xbmcPlayer.play(playlist)
def list_channels():
"""show channels on the kodi list."""
playlist = utility.read_list(playlists_file)
if not playlist:
ok(ADDON.getLocalizedString(11005), ADDON.getLocalizedString(11006))
return None
for channel in playlist:
url = channel['url'].encode('utf-8')
name = channel['display_name'].encode('utf-8')
action_url = build_url({'mode': 'play', 'url': url, 'name': name})
item = xbmcgui.ListItem(name, iconImage='DefaultVideo.png')
item.setInfo(type='Video', infoLabels={'Title': name})
xbmcplugin.addDirectoryItem(handle=HANDLE, url=action_url, listitem=item)
xbmcplugin.endOfDirectory(HANDLE, cacheToDisc=False)
def router(paramstring):
params = dict(parse_qsl(paramstring[1:]))
if params:
if params['mode'] == 'play':
play_item = xbmcgui.ListItem(path=params['link'])
xbmcplugin.setResolvedUrl(__handle__, True, listitem=play_item)
else:
for stream in streams():
list_item = xbmcgui.ListItem(label=stream['name'], thumbnailImage=stream['thumb'])
list_item.setProperty('fanart_image', stream['thumb'])
list_item.setProperty('IsPlayable', 'true')
url = '{0}?mode=play&link={1}'.format(__url__, stream['link'])
xbmcplugin.addDirectoryItem(__handle__, url, list_item, isFolder=False)
xbmcplugin.endOfDirectory(__handle__)
# --------------------------------------------------------------------------------
# Main
# --------------------------------------------------------------------------------
plugintools.py 文件源码
项目:plugin.video.streamondemand-pureita
作者: orione7
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def direct_play(url):
_log("direct_play ["+url+"]")
title = ""
try:
xlistitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", path=url)
except:
xlistitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", )
xlistitem.setInfo( "video", { "Title": title } )
playlist = xbmc.PlayList( xbmc.PLAYLIST_VIDEO )
playlist.clear()
playlist.add( url, xlistitem )
player_type = xbmc.PLAYER_CORE_AUTO
xbmcPlayer = xbmc.Player( player_type )
xbmcPlayer.play(playlist)