def list_streams(streams):
stream_list = []
# iterate over the contents of the dictionary songs to build the list
for stream in streams:
# create a list item using the stream's name for the label
li = xbmcgui.ListItem(label=stream['name'])
# set the thumbnail image
li.setArt({'thumb': stream['logo']})
# set the list item to playable
li.setProperty('IsPlayable', 'true')
# build the plugin url for Kodi
url = build_url({'mode': 'stream', 'url': stream['url'], 'title': stream['name']})
# add the current list item to a list
stream_list.append((url, li, False))
# add list to Kodi per Martijn
# http://forum.kodi.tv/showthread.php?tid=209948&pid=2094170#pid2094170
xbmcplugin.addDirectoryItems(addon_handle, stream_list, len(stream_list))
# set the content of the directory
xbmcplugin.setContent(addon_handle, 'songs')
xbmcplugin.endOfDirectory(addon_handle)
python类addDirectoryItems()的实例源码
def list_podcast_radios(radios):
radio_list = []
# iterate over the contents of the list of radios
for radio in sorted(radios, key=operator.itemgetter('name')):
url = build_url({'mode': 'podcasts-radio', 'foldername': radio['name'], 'url': radio['url'], 'name': radio['name']})
li = xbmcgui.ListItem(radio['name'], iconImage='DefaultFolder.png')
radio_list.append((url, li, True))
# add list to Kodi per Martijn
# http://forum.kodi.tv/showthread.php?tid=209948&pid=2094170#pid2094170
xbmcplugin.addDirectoryItems(addon_handle, radio_list, len(radio_list))
# set the content of the directory
xbmcplugin.setContent(addon_handle, 'songs')
xbmcplugin.endOfDirectory(addon_handle)
def list_podcast_programs(programs):
program_list = []
# iterate over the contents of the list of programs
for program in programs:
url = build_url({'mode': 'podcasts-radio-program', 'foldername': urllib.quote(program['name'].encode('utf8')), 'url': program['url'], 'name': urllib.quote(program['name'].encode('utf8')), 'radio': program['radio']})
li = xbmcgui.ListItem(program['name'], iconImage='DefaultFolder.png')
program_list.append((url, li, True))
# add list to Kodi per Martijn
# http://forum.kodi.tv/showthread.php?tid=209948&pid=2094170#pid2094170
xbmcplugin.addDirectoryItems(addon_handle, program_list, len(program_list))
# set the content of the directory
xbmcplugin.setContent(addon_handle, 'songs')
xbmcplugin.endOfDirectory(addon_handle)
def show_listing(self, list_items, sort=None):
listing = []
for title_item in list_items:
list_item = xbmcgui.ListItem(label=title_item.title)
url = self._url + '?' + urlencode(title_item.url_dictionary)
list_item.setProperty('IsPlayable', str(title_item.is_playable))
if title_item.thumbnail is not None:
list_item.setArt({'thumb': title_item.thumbnail})
list_item.setInfo('video', title_item.video_dictionary)
listing.append((url, list_item, not title_item.is_playable))
xbmcplugin.addDirectoryItems(self._handle, listing, len(listing))
if sort is not None:
kodi_sorts = {sortmethod.ALPHABET: xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE}
kodi_sortmethod = kodi_sorts.get(sort)
xbmcplugin.addSortMethod(self._handle, kodi_sortmethod)
xbmcplugin.endOfDirectory(self._handle)
def router(paramstring):
"""Decides what to do based on script parameters"""
check_settings()
params = dict(parse_qsl(paramstring))
# Nothing to do yet with those
if not params:
# Demo channel list
channels = map_channels(filter_channels(get_tv_channels()))
xbmcplugin.addDirectoryItems(plugin_handle, channels, len(channels))
xbmcplugin.addSortMethod(
plugin_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
xbmcplugin.endOfDirectory(plugin_handle)
elif params['action'] == 'play':
play_channel(params['channel'])
elif params['action'] == 'get_user_id':
get_user_id()
def list_categories():
listing=[]
list_item = xbmcgui.ListItem(label='??', thumbnailImage='')
url='{0}?action=game_list'.format(_url)
is_folder=True
listing.append((url, list_item, is_folder))
list_item = xbmcgui.ListItem(label='Lyingman', thumbnailImage='')
url='{0}?action=lyingman'.format(_url)
is_folder=True
listing.append((url, list_item, is_folder))
xbmcplugin.addDirectoryItems(_handle,listing,len(listing))
#xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)
def game_list():
f = urllib2.urlopen('http://www.zhanqi.tv/api/static/game.lists/100-1.json?rand={ts}'.format(ts=time.time()))
obj = json.loads(f.read())
listing=[]
for game in obj['data']['games']:
list_item = xbmcgui.ListItem(label=game['name'], thumbnailImage=game['bpic'])
list_item.setProperty('fanart_image', game['bpic'])
url='{0}?action=room_list&game_id={1}'.format(_url, game['id'])
#xbmc.log(url, 1)
is_folder=True
listing.append((url, list_item, is_folder))
xbmcplugin.addDirectoryItems(_handle,listing,len(listing))
#xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)
def room_list(game_id):
f = urllib2.urlopen('http://www.zhanqi.tv/api/static/game.lives/{game_id}/100-1.json?rand={ts}'.format(game_id=game_id, ts=time.time()))
obj = json.loads(f.read())
listing=[]
for room in obj['data']['rooms']:
list_item = xbmcgui.ListItem(label=room['title'], thumbnailImage=room['bpic'])
list_item.setProperty('fanart_image', room['bpic'])
url='{0}?action=play&room_id={1}'.format(_url, room['id'])
is_folder=False
listing.append((url, list_item, is_folder))
xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
#xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)
def list_podcast_audios(audios):
audio_list = []
# iterate over the audios to build the list
for audio in audios:
# create a list item using the audio's title for the label
li = xbmcgui.ListItem(audio['date'] + " - " + audio['title'])
if 'image' in audio:
# set the thumbnail image
li.setArt({'thumb': audio['image']})
# set the list item to playable
li.setProperty('IsPlayable', 'true')
# build the plugin url for Kodi
url = build_url({'mode': 'stream', 'url': audio['url'].encode('utf8'), 'title': audio['date'] + " - " + urllib.quote(audio['title'].encode('utf8'))})
# add the current list item to a list
audio_list.append((url, li, False))
# add list to Kodi per Martijn
# http://forum.kodi.tv/showthread.php?tid=209948&pid=2094170#pid2094170
xbmcplugin.addDirectoryItems(addon_handle, audio_list, len(audio_list))
# set the content of the directory
xbmcplugin.setContent(addon_handle, 'songs')
xbmcplugin.endOfDirectory(addon_handle)
def list_categories(offset):
#f=urllib2.urlopen('http://www.douyutv.com/directory')
#rr=BeautifulSoup(f.read())
rr=BeautifulSoup(requests.get('http://www.douyutv.com/directory',headers=headers).text)
catel=rr.findAll('a',{'class':'thumb'},limit=offset+PAGE_LIMIT+1)
rrr=[(x['href'], x.p.text,x.img['data-original']) for x in catel]
offset=int(offset)
if offset+PAGE_LIMIT<len(rrr):
rrr=rrr[offset:offset+PAGE_LIMIT]
nextpageflag=True
else:
rrr=rrr[offset:]
nextpageflag=False
listing=[]
for classname,textinfo,img in rrr:
list_item=xbmcgui.ListItem(label=textinfo,thumbnailImage=img)
#list_item.setProperty('fanart_image',img)
url=u'{0}?action=listing&category={1}&offset=0'.format(_url,classname)
is_folder=True
listing.append((url,list_item,is_folder))
if nextpageflag==True:
list_item=xbmcgui.ListItem(label=NEXT_PAGE)
url=u'{0}?offset={1}'.format(_url,str(offset+PAGE_LIMIT))
is_folder=True
listing.append((url,list_item,is_folder))
xbmcplugin.addDirectoryItems(_handle,listing,len(listing))
#xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)
def list_videos(category,offset=0):
#request=urllib2.Request('http://www.douyu.com'+category,headers=headers)
#f=urllib2.urlopen(request)
#f=urllib2.urlopen('http://www.douyu.com'+category)
#r=f.read()
#rr=BeautifulSoup(r)
rr=BeautifulSoup(requests.get('http://www.douyu.com'+category,headers=headers).text)
videol=rr.findAll('a',{'class':'list'},limit=offset+PAGE_LIMIT+1)
listing=[]
#with open('rooml.dat','w') as f:
# f.writelines([str(x) for x in videol])
if offset+PAGE_LIMIT<len(videol):
videol=videol[offset:offset+PAGE_LIMIT]
nextpageflag=True
else:
videol=videol[offset:]
nextpageflag=False
for x in videol:
roomid=x['href'][1:]
img=x.img['data-original']
title=x['title']
nickname=x.find('span',{'class':'nnt'}).text
view=x.find('span',{'class':'view'}).text
liveinfo=u'{0}:{1}:{2}'.format(nickname,title,view)
list_item=xbmcgui.ListItem(label=liveinfo,thumbnailImage=img)
#list_item.setProperty('fanart_image',img)
url='{0}?action=play&video={1}'.format(_url,roomid)
is_folder=False
listing.append((url,list_item,is_folder))
if nextpageflag==True:
list_item=xbmcgui.ListItem(label=NEXT_PAGE)
url='{0}?action=listing&category={1}&offset={2}'.format(_url,category,offset+PAGE_LIMIT)
is_folder=True
listing.append((url,list_item,is_folder))
xbmcplugin.addDirectoryItems(_handle,listing,len(listing))
#xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)
def add_list_items(self, items, content=None, end=True, withNextPage=False):
if content:
xbmcplugin.setContent(plugin.handle, content)
list_items = []
for item in items:
if isinstance(item, Category):
category_items = item.getListItems()
for url, li, isFolder in category_items:
if url and li:
list_items.append((url, li, isFolder))
elif isinstance(item, BrowsableMedia):
url, li, isFolder = item.getListItem()
if url and li:
list_items.append((url, li, isFolder))
if withNextPage and len(items) > 0:
# Add folder for next page
try:
totalNumberOfItems = items[0]._totalNumberOfItems
nextOffset = items[0]._offset + self._config.pageSize
if nextOffset < totalNumberOfItems and len(items) >= self._config.pageSize:
path = urlsplit(sys.argv[0]).path or '/'
path = path.split('/')[:-1]
path.append(str(nextOffset))
url = '/'.join(path)
self.add_directory_item(_T(30244).format(pos1=nextOffset, pos2=min(nextOffset+self._config.pageSize, totalNumberOfItems)), plugin.url_for_path(url))
except:
log('Next Page for URL %s not set' % sys.argv[0], xbmc.LOGERROR)
if len(list_items) > 0:
xbmcplugin.addDirectoryItems(plugin.handle, list_items)
if end:
xbmcplugin.endOfDirectory(plugin.handle)
def display_generic_playable_items(items):
xbmcplugin.addDirectoryItems(handle=addon_handle, items=items, totalItems=len(items))
xbmcplugin.endOfDirectory(addon_handle, True)
def list_categories(base_category):
"""
Create the list of the categories in the Kodi interface.
:param base_category: the parent category to require from all categories
:return: None
"""
listing = list_sub_categories(base_category)
# Add our listing to Kodi.
# Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
# instead of adding one by ove via addDirectoryItem.
xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
# Add a sort method for the virtual folder items (alphabetically, ignore articles)
xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)
def list_streams(listing, streams, offset_url, item_limit=25):
"""
Create the list of playable streams in the Kodi interface.
:param listing: list for the streams. Can include some fixed elements
:param streams: json of streams to list
:param offset_url: url that opens next page of streams
:param item_limit: maximum number of items per page
:return: None
"""
# Iterate through the streams.
for stream in streams:
list_item = create_list_item_from_stream(stream)
if list_item is None:
continue
# Create a URL for the plugin recursive callback.
# Example: plugin://plugin.video.example/?action=play&video=http://www.vidsplay.com/vids/crab.mp4
url = '{0}?action=play&stream={1}'.format(_url, stream['id'])
# Add the list item to a virtual Kodi folder.
# is_folder = False means that this item won't open any sub-list.
is_folder = False
# Add our item to the listing as a 3-element tuple.
listing.append((url, list_item, is_folder))
if len(listing) >= item_limit:
list_item = xbmcgui.ListItem(label='[COLOR {0}]{1}[/COLOR]'.format(
get_color('menuItemColor'), get_translation(32008)))
listing.append((offset_url, list_item, True))
# Add our listing to Kodi.
# Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
# instead of adding one by ove via addDirectoryItem.
xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
# Add a sort method for the virtual folder items (alphabetically, ignore articles)
# xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)
xbmcplugin.setContent(_handle, 'movies')
def live_tv_channels(path=None):
if not path:
listing = []
yle_1 = xbmcgui.ListItem(label='[COLOR {0}]{1}[/COLOR]'.format(get_color('menuItemColor'), 'YLE TV1'))
yle_1_url = '{0}?action=live&path={1}'.format(_url, _yle_tv1_live_url)
yle_1.setProperty('IsPlayable', 'true')
listing.append((yle_1_url, yle_1, False))
yle_2 = xbmcgui.ListItem(label='[COLOR {0}]{1}[/COLOR]'.format(get_color('menuItemColor'), 'YLE TV2'))
yle_2_url = '{0}?action=live&path={1}'.format(_url, _yle_tv2_live_url)
yle_2.setProperty('IsPlayable', 'true')
listing.append((yle_2_url, yle_2, False))
for service in _tv_services:
service_name = service.replace('-', ' ').title()
data = get_areena_api_json_data('programs/schedules', 'now.json', ['service=' + service])
for item in data:
content = item['content']
for language_code in get_language_codes():
if language_code in content['title']:
content['title'][language_code] = \
service_name + ': ' + content['title'][language_code]
list_item = create_list_item_from_stream(content)
if list_item:
url = '{0}?action=play&stream={1}'.format(_url, content['id'])
listing.append((url, list_item, False))
else:
title = ''
for language_code in get_language_codes():
if language_code in content['title']:
title = ' - ' + content['title'][language_code]
break
not_available_item = xbmcgui.ListItem(label='[COLOR {0}]{1}[/COLOR]'.format(
get_color('menuItemColor'), get_translation(32072) + title))
not_available_item.setProperty('IsPlayable', 'false')
listing.append((None, not_available_item, False))
xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
xbmcplugin.endOfDirectory(_handle)
else:
xbmcplugin.setResolvedUrl(
_handle, True, listitem=xbmcgui.ListItem(path=get_resolution_specific_url_for_live_tv(path)))
def show_menu():
if get_app_id() == '' or get_app_key() == '' or get_secret_key() == '':
return show_credentials_needed_menu()
listing = []
tv_list_item = xbmcgui.ListItem(label='[COLOR {0}]{1}[/COLOR]'.format(
get_color('menuItemColor'), get_translation(32031)))
tv_url = '{0}?action=categories&base=5-130'.format(_url)
listing.append((tv_url, tv_list_item, True))
live_tv_list_item = xbmcgui.ListItem(label='[COLOR {0}]{1}[/COLOR]'.format(
get_color('menuItemColor'), get_translation(32067)))
live_tv_url = '{0}?action=live'.format(_url)
listing.append((live_tv_url, live_tv_list_item, True))
radio_list_item = xbmcgui.ListItem(label='[COLOR {0}]{1}[/COLOR]'.format(
get_color('menuItemColor'), get_translation(32032)))
radio_url = '{0}?action=categories&base=5-200'.format(_url)
listing.append((radio_url, radio_list_item, True))
search_list_item = xbmcgui.ListItem(label='[COLOR {0}]{1}[/COLOR]'.format(
get_color('menuItemColor'), get_translation(32007)))
search_url = '{0}?action=search'.format(_url)
listing.append((search_url, search_list_item, True))
favourites_list_item = xbmcgui.ListItem(label='[COLOR {0}]{1}[/COLOR]'.format(
get_color('menuItemColor'), get_translation(32025)))
favourites_url = '{0}?action=favourites'.format(_url)
listing.append((favourites_url, favourites_list_item, True))
open_settings_list_item = xbmcgui.ListItem(label='[COLOR {0}]{1}[/COLOR]'.format(
get_color('menuItemColor'), get_translation(32040)))
open_settings_url = '{0}?action=settings'.format(_url)
listing.append((open_settings_url, open_settings_list_item, True))
# Add our listing to Kodi.
xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
# Add a sort method for the virtual folder items (alphabetically, ignore articles)
xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_NONE)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)
def show_credentials_needed_menu():
listing = []
missing_credentials_list_item = xbmcgui.ListItem(label=get_translation(32038))
missing_credentials_url = '{0}'.format(_url)
listing.append((missing_credentials_url, missing_credentials_list_item, True))
open_settings_list_item = xbmcgui.ListItem(label=get_translation(32039))
open_settings_url = '{0}?action=settings'.format(_url)
listing.append((open_settings_url, open_settings_list_item, True))
# Add our listing to Kodi.
xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
# Add a sort method for the virtual folder items (alphabetically, ignore articles)
xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_NONE)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)
def pass_list_to_skin(data=[], handle=None, limit=False):
if data and limit and int(limit) < len(data):
data = data[:int(limit)]
if not handle:
return None
if data:
items = create_listitems(data)
xbmcplugin.addDirectoryItems(handle=handle,
items=[(i.getProperty("path"), i, False) for i in items],
totalItems=len(items))
xbmcplugin.endOfDirectory(handle)
def listingAction(self, func):
def inner(*args):
items = func(*args)
if items is None:
print args
else:
xbmcplugin.addDirectoryItems(self.handle, items)
xbmcplugin.endOfDirectory(self.handle)
return inner
def list_videos(category):
"""
Create the list of playable videos in the Kodi interface.
:param category: str
"""
# Get the list of videos in the category.
videos = get_videos(category)
# Create a list for our items.
listing = []
# create playlists button to link to youtube playlist functionality
listing.append(createButton(action=('channelPlaylists&channel='+category),\
title='Playlists',thumb=(_resdir+'/media/playlist.png'),icon='',fanart=''))
# show related channels button
listing.append(createButton(action=('relatedChannels&value='+category),\
title='Related Channels',thumb=(_basedir+'/icon.png'),icon='',fanart=''))
# Iterate through videos.
for video in videos:
# Create a list item with a text label and a thumbnail image.
list_item = xbmcgui.ListItem(label=video['name'])
# Set additional info for the list item.
list_item.setInfo('video', {'title': video['name'], 'genre': video['genre']})
# Set graphics (thumbnail, fanart, banner, poster, landscape etc.) for the list item.
# Here we use the same image for all items for simplicity's sake.
# In a real-life plugin you need to set each image accordingly.
list_item.setArt({'thumb': video['thumb'], 'icon': video['thumb'], 'fanart': video['thumb']})
# Set 'IsPlayable' property to 'true'.
# This is mandatory for playable items!
list_item.setProperty('IsPlayable', 'true')
# Create a URL for the plugin recursive callback.
# Example: plugin://plugin.video.example/?action=play&video=http://www.vidsplay.com/vids/crab.mp4
url = '{0}?action=play&video={1}'.format(_url, video['video'])
# Add the list item to a virtual Kodi folder.
# is_folder = False means that this item won't open any sub-list.
is_folder = False
# Add our item to the listing as a 3-element tuple.
listing.append((url, list_item, is_folder))
# Add our listing to Kodi.
# Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
# instead of adding one by ove via addDirectoryItem.
xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
# Add a sort method for the virtual folder items (alphabetically, ignore articles)
#xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
# change the default view to thumbnails
xbmc.executebuiltin('Container.SetViewMode(%d)' % 500)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)
def add_track_listitems(self, tracks, append_artist_to_label=False):
list_items = []
for count, track in enumerate(tracks):
if append_artist_to_label:
label = "%s - %s" % (track["artist"], track['name'])
else:
label = track['name']
duration = track["duration_ms"] / 1000
if KODI_VERSION > 17:
li = xbmcgui.ListItem(label, offscreen=True)
else:
li = xbmcgui.ListItem(label)
if self.local_playback and self.connect_id:
# local playback by using proxy on a remote machine
url = "http://%s:%s/track/%s/%s" % (self.connect_id, PROXY_PORT, track['id'], duration)
li.setProperty("isPlayable", "true")
elif self.local_playback:
# local playback by using proxy on this machine
url = "http://localhost:%s/track/%s/%s" % (PROXY_PORT, track['id'], duration)
li.setProperty("isPlayable", "true")
else:
# connect controlled playback
li.setProperty("isPlayable", "false")
if self.playlistid:
url = "plugin://plugin.audio.spotify/?action=connect_playback&trackid=%s&playlistid=%s&ownerid=%s&offset=%s" % (
track['id'], self.playlistid, self.ownerid, count)
elif self.albumid:
url = "plugin://plugin.audio.spotify/?action=connect_playback&trackid=%s&albumid=%s&offset=%s" % (track[
'id'], self.albumid, count)
else:
url = "plugin://plugin.audio.spotify/?action=connect_playback&trackid=%s" % (track['id'])
if self.append_artist_to_title:
title = label
else:
title = track['name']
li.setInfo('music', {
"title": title,
"genre": track["genre"],
"year": track["year"],
"tracknumber": track["track_number"],
"album": track['album']["name"],
"artist": track["artist"],
"rating": track["rating"],
"duration": duration
})
li.setArt({"thumb": track['thumb']})
li.setProperty("spotifytrackid", track['id'])
li.setContentLookup(False)
li.addContextMenuItems(track["contextitems"], True)
li.setProperty('do_not_analyze', 'true')
li.setMimeType("audio/wave")
list_items.append((url, li, False))
xbmcplugin.addDirectoryItems(self.addon_handle, list_items, totalItems=len(list_items))
def list_categories():
"""
Create the list of video categories in the Kodi interface.
"""
# Get video categories
categories = get_categories()
# Create a list for our items.
listing = []
# Iterate through categories
for category in categories:
category_name = category['name']
category_url = category['url']
# Create a list item with a text label and a thumbnail image.
list_item = xbmcgui.ListItem(label=category_name, thumbnailImage=THUMBNAIL)
# Set graphics (thumbnail, fanart, banner, poster, landscape etc.) for the list item.
# Here we use the same image for all items for simplicity's sake.
# In a real-life plugin you need to set each image accordingly.
list_item.setArt({'thumb': THUMBNAIL,
'icon': THUMBNAIL,
'fanart': THUMBNAIL})
# Set additional info for the list item.
# Here we use a category name for both properties for for simplicity's sake.
# setInfo allows to set various information for an item.
# For available properties see the following link:
# http://mirrors.xbmc.org/docs/python-docs/15.x-isengard/xbmcgui.html#ListItem-setInfo
list_item.setInfo('video', {'title': category_name, 'genre': category_name})
# Create a URL for the plugin recursive callback.
# Example: plugin://plugin.video.example/?action=listing&category=Animals
url = '{0}?action=list&category_name={1}&category_url={2}'.format(_url, category_name, category_url)
# is_folder = True means that this item opens a sub-list of lower level items.
is_folder = True
# Add our item to the listing as a 3-element tuple.
listing.append((url, list_item, is_folder))
# Add our listing to Kodi.
# Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
# instead of adding one by ove via addDirectoryItem.
xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
# Add a sort method for the virtual folder items (alphabetically, ignore articles)
#xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_NONE)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)
def list_matches(videos):
"""
Create the list of matches in the Kodi interface.
"""
print("=====list_matches()")
# Create a list for our items.
listing = []
# Iterate through videos.
for video in videos:
# Create a list item with a text label and a thumbnail image.
list_item = xbmcgui.ListItem(label=video['name'])
if video['video'] == None:
# Non-video item: next page
url = video['url']
list_item.setProperty('IsPlayable', 'false')
# Add the list item to a virtual Kodi folder.
is_folder = True
else:
# Set additional info for the list item.
list_item.setInfo('video', {'title': video['name'], 'genre': video['genre']})
# Set graphics (thumbnail, fanart, banner, poster, landscape etc.) for the list item.
# Here we use the same image for all items for simplicity's sake.
# In a real-life plugin you need to set each image accordingly.
list_item.setArt({'thumb': video['thumb'], 'icon': video['thumb'], 'fanart': video['thumb']})
# Create a URL for the plugin recursive callback.
url = u'{0}?action=view&match={1}'.format(_url, video['video'])
# Set 'IsPlayable' property to 'true'.
# This is mandatory for playable items!
list_item.setProperty('IsPlayable', 'true')
# Add the list item to a virtual Kodi folder.
# is_folder = False means that this item won't open any sub-list.
is_folder = False
# Add our item to the listing as a 3-element tuple.
listing.append((url, list_item, is_folder))
# Add our listing to Kodi.
# Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
# instead of adding one by ove via addDirectoryItem.
xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
# Add a sort method for the virtual folder items (alphabetically, ignore articles)
#xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_NONE)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)
def lyingman():
f = urllib2.urlopen('http://www.zhanqi.tv/topic/lyingman')
html = f.read()
html = html.replace("\n", '')
review = re.compile('<div class="review-area">.*').findall(html)
review = review[0];
li_list = review.split('<li class="js-carousel-item">')
listing=[]
for li in li_list:
title = re.compile('<span class="name">([^"]*)</span>').findall(li)
if len(title) > 0:
title = title[0]
img = re.compile('<img src="([^"]*)"[^>]*>').findall(li)
if len(img) > 0:
img = img[0]
else:
img = ''
link = re.compile('<a href="/videos/([^"]*)"[^>]*>').findall(li)
if len(link) > 0:
link = link[0]
link = link.split('/')
link = link[len(link) - 1]
link = link.split('.')
link = link[0]
during = re.compile('<p><i class="dv iconClock png"></i><span class="dv">([^"]*)</span></p>').findall(li)
if len(during) > 0:
during = during[0]
else:
during = 'unknow'
list_item = xbmcgui.ListItem(label=title + '[' + during + ']', thumbnailImage=img)
list_item.setProperty('fanart_image', img)
url='{0}?action=playvod&video_id={1}'.format(_url, link)
is_folder=False
listing.append((url, list_item, is_folder))
xbmcplugin.addDirectoryItems(_handle, listing, len(listing))
#xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)