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类setContent()的实例源码
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 browse_topartists(self):
xbmcplugin.setContent(self.addon_handle, "artists")
result = self.sp.current_user_top_artists(limit=20, offset=0)
cachestr = "spotify.topartists.%s" % self.userid
checksum = self.cache_checksum(result["total"])
items = self.cache.get(cachestr, checksum=checksum)
if not items:
count = len(result["items"])
while result["total"] > count:
result["items"] += self.sp.current_user_top_artists(limit=20, offset=count)["items"]
count += 50
items = self.prepare_artist_listitems(result["items"])
self.cache.set(cachestr, items, checksum=checksum)
self.add_artist_listitems(items)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_artists:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_artists)
def browse_toptracks(self):
xbmcplugin.setContent(self.addon_handle, "songs")
results = self.sp.current_user_top_tracks(limit=20, offset=0)
cachestr = "spotify.toptracks.%s" % self.userid
checksum = self.cache_checksum(results["total"])
items = self.cache.get(cachestr, checksum=checksum)
if not items:
items = results["items"]
while results["next"]:
results = self.sp.next(results)
items.extend(results["items"])
items = self.prepare_track_listitems(tracks=items)
self.cache.set(cachestr, items, checksum=checksum)
self.add_track_listitems(items, True)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_songs:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_songs)
def browse_album(self):
xbmcplugin.setContent(self.addon_handle, "songs")
album = self.sp.album(self.albumid, market=self.usercountry)
xbmcplugin.setProperty(self.addon_handle, 'FolderName', album["name"])
tracks = self.get_album_tracks(album)
if album.get("album_type") == "compilation":
self.add_track_listitems(tracks, True)
else:
self.add_track_listitems(tracks)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_TRACKNUM)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_TITLE)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_SONG_RATING)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_ARTIST)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_songs:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_songs)
def search_artists(self):
xbmcplugin.setContent(self.addon_handle, "artists")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(133))
result = self.sp.search(
q="artist:%s" %
self.artistid,
type='artist',
limit=self.limit,
offset=self.offset,
market=self.usercountry)
artists = self.prepare_artist_listitems(result['artists']['items'])
self.add_artist_listitems(artists)
self.add_next_button(result['artists']['total'])
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_artists:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_artists)
def search_tracks(self):
xbmcplugin.setContent(self.addon_handle, "songs")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(134))
result = self.sp.search(
q="track:%s" %
self.trackid,
type='track',
limit=self.limit,
offset=self.offset,
market=self.usercountry)
tracks = self.prepare_track_listitems(tracks=result["tracks"]["items"])
self.add_track_listitems(tracks, True)
self.add_next_button(result['tracks']['total'])
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_songs:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_songs)
def search_albums(self):
xbmcplugin.setContent(self.addon_handle, "albums")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(132))
result = self.sp.search(
q="album:%s" %
self.albumid,
type='album',
limit=self.limit,
offset=self.offset,
market=self.usercountry)
albumids = []
for album in result['albums']['items']:
albumids.append(album["id"])
albums = self.prepare_album_listitems(albumids)
self.add_album_listitems(albums, True)
self.add_next_button(result['albums']['total'])
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_albums:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_albums)
def search_playlists(self):
xbmcplugin.setContent(self.addon_handle, "files")
result = self.sp.search(
q=self.playlistid,
type='playlist',
limit=self.limit,
offset=self.offset,
market=self.usercountry)
log_msg(result)
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(136))
playlists = self.prepare_playlist_listitems(result['playlists']['items'])
self.add_playlist_listitems(playlists)
self.add_next_button(result['playlists']['total'])
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_playlists:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_playlists)
def artist_view(artist_id):
if session.is_logged_in:
session.user.favorites.load_all()
artist = session.get_artist(artist_id)
xbmcplugin.setContent(plugin.handle, 'albums')
add_directory(_T(30225), plugin.url_for(artist_bio, artist_id), thumb=artist.image, fanart=artist.fanart, isFolder=False)
add_directory(_T(30226), plugin.url_for(top_tracks, artist_id), thumb=artist.image, fanart=artist.fanart)
add_directory(_T(30110), plugin.url_for(artist_videos, artist_id), thumb=artist.image, fanart=artist.fanart)
add_directory(_T(30227), plugin.url_for(artist_radio, artist_id), thumb=artist.image, fanart=artist.fanart)
add_directory(_T(30228), plugin.url_for(artist_playlists, artist_id), thumb=artist.image, fanart=artist.fanart)
add_directory(_T(30229), plugin.url_for(similar_artists, artist_id), thumb=artist.image, fanart=artist.fanart)
if session.is_logged_in:
if session.user.favorites.isFavoriteArtist(artist_id):
add_directory(_T(30220), plugin.url_for(favorites_remove, content_type='artists', item_id=artist_id), thumb=artist.image, fanart=artist.fanart, isFolder=False)
else:
add_directory(_T(30219), plugin.url_for(favorites_add, content_type='artists', item_id=artist_id), thumb=artist.image, fanart=artist.fanart, isFolder=False)
albums = session.get_artist_albums(artist_id) + \
session.get_artist_albums_ep_singles(artist_id) + \
session.get_artist_albums_other(artist_id)
add_items(albums, content=None)
def search_type(field):
last_field = addon.getSetting('last_search_field').decode('utf-8')
search_text = addon.getSetting('last_search_text').decode('utf-8')
if last_field <> field or not search_text:
addon.setSetting('last_search_field', field)
keyboard = xbmc.Keyboard('', _T(30206))
keyboard.doModal()
if keyboard.isConfirmed():
search_text = keyboard.getText()
else:
search_text = ''
addon.setSetting('last_search_text', search_text)
if search_text:
searchresults = session.search(field, search_text)
add_items(searchresults.artists, content=CONTENT_FOR_TYPE.get('files'), end=False)
add_items(searchresults.albums, end=False)
add_items(searchresults.playlists, end=False)
add_items(searchresults.tracks, end=False)
add_items(searchresults.videos, end=True)
else:
#xbmcplugin.setContent(plugin.handle, content='files')
xbmcplugin.endOfDirectory(plugin.handle, succeeded=False, updateListing=False)
def addShow(name, mode, icon, fanart, info, show_info):
u = sys.argv[0] + "?mode=" + str(mode)
u += '&program_id=' + show_info['program_id']
liz = xbmcgui.ListItem(name)
if fanart == None: fanart = FANART
liz.setArt({'icon': icon, 'thumb': icon, 'fanart': fanart})
liz.setInfo(type="Video", infoLabels=info)
show_values =''
for key, value in show_info.iteritems():
show_values += '&' + key + '=' + value
context_items = [('Add To My Shows', 'RunPlugin(plugin://plugin.video.psvue/?mode=1001'+show_values+')'),
('Remove From My Shows', 'RunPlugin(plugin://plugin.video.psvue/?mode=1002'+show_values+')')]
liz.addContextMenuItems(context_items)
ok = xbmcplugin.addDirectoryItem(handle=addon_handle, url=u, listitem=liz, isFolder=True)
xbmcplugin.setContent(addon_handle, 'tvshows')
def addStream(name, link_url, title, icon, fanart, info=None, properties=None, show_info=None):
u = sys.argv[0] + "?url=" + urllib.quote_plus(link_url) + "&mode=" + str(900)
#xbmc.log(str(info))
liz = xbmcgui.ListItem(name)
liz.setArt({'icon': icon, 'thumb': icon, 'fanart': fanart})
if info != None: liz.setInfo(type="Video", infoLabels=info)
if properties != None:
for key, value in properties.iteritems():
liz.setProperty(key,value)
xbmc.log(str(show_info))
if show_info != None:
show_values =''
for key, value in show_info.iteritems():
show_values += '&' + key + '=' + value
u += show_values
if len(show_info) == 1:
#Only add this option for channels not episodes
context_items = [('Add To Favorites Channels', 'RunPlugin(plugin://plugin.video.psvue/?mode=1001'+show_values+')'),
('Remove From Favorites Channels', 'RunPlugin(plugin://plugin.video.psvue/?mode=1002'+show_values+')')]
liz.addContextMenuItems(context_items)
ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=False)
xbmcplugin.setContent(addon_handle, 'tvshows')
return ok
def listSeasonsFromSeries(series_id):
url = skygo.baseUrl + '/sg/multiplatform/web/json/details/series/' + str(series_id) + '_global.json'
r = requests.get(url)
data = r.json()['serieRecap']['serie']
xbmcplugin.setContent(addon_handle, 'seasons')
for season in data['seasons']['season']:
url = common.build_url({'action': 'listSeason', 'id': season['id'], 'series_id': data['id']})
label = '%s - Staffel %02d' % (data['title'], season['nr'])
li = xbmcgui.ListItem(label=label)
li.setProperty('IsPlayable', 'false')
li.setArt({'poster': skygo.baseUrl + season['path'],
'fanart': getHeroImage(data)})
li.setInfo('video', {'plot': data['synopsis'].replace('\n', '').strip()})
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
listitem=li, isFolder=True)
xbmcplugin.addSortMethod(handle=addon_handle, sortMethod=xbmcplugin.SORT_METHOD_NONE)
xbmcplugin.addSortMethod(handle=addon_handle, sortMethod=xbmcplugin.SORT_METHOD_TITLE)
xbmcplugin.addSortMethod(handle=addon_handle, sortMethod=xbmcplugin.SORT_METHOD_LABEL)
xbmcplugin.addSortMethod(handle=addon_handle, sortMethod=xbmcplugin.SORT_METHOD_VIDEO_YEAR)
xbmcplugin.endOfDirectory(addon_handle, cacheToDisc=True)
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 browse_main(self):
# main listing
xbmcplugin.setContent(self.addon_handle, "files")
items = []
items.append(
(self.addon.getLocalizedString(11013),
"plugin://plugin.audio.spotify/?action=browse_main_library",
"DefaultMusicCompilations.png", True))
items.append(
(self.addon.getLocalizedString(11014),
"plugin://plugin.audio.spotify/?action=browse_main_explore",
"DefaultMusicGenres.png", True))
items.append(
(xbmc.getLocalizedString(137),
"plugin://plugin.audio.spotify/?action=search",
"DefaultMusicSearch.png", True))
items.append(
("%s: %s" % (self.addon.getLocalizedString(11039), self.playername),
"plugin://plugin.audio.spotify/?action=browse_playback_devices",
"DefaultMusicPlugins.png", True))
if self.addon.getSetting("multi_account") == "true":
cur_user_label = self.sp.me()["display_name"]
if not cur_user_label:
cur_user_label = self.sp.me()["id"]
label = "%s: %s" % (self.addon.getLocalizedString(11047), cur_user_label)
items.append(
(label,
"plugin://plugin.audio.spotify/?action=switch_user",
"DefaultActor.png", False))
for item in items:
li = xbmcgui.ListItem(
item[0],
path=item[1],
iconImage=item[2]
)
li.setProperty('IsPlayable', 'false')
li.setArt({"fanart": "special://home/addons/plugin.audio.spotify/fanart.jpg"})
li.addContextMenuItems([], True)
xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=item[1], listitem=li, isFolder=item[3])
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
def artist_toptracks(self):
xbmcplugin.setContent(self.addon_handle, "songs")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', self.addon.getLocalizedString(11011))
tracks = self.sp.artist_top_tracks(self.artistid, country=self.usercountry)
tracks = self.prepare_track_listitems(tracks=tracks["tracks"])
self.add_track_listitems(tracks)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_TRACKNUM)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_TITLE)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_SONG_RATING)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_songs:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_songs)
def related_artists(self):
xbmcplugin.setContent(self.addon_handle, "artists")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', self.addon.getLocalizedString(11012))
cachestr = "spotify.relatedartists.%s" % self.artistid
checksum = self.cache_checksum()
artists = self.cache.get(cachestr, checksum=checksum)
if not artists:
artists = self.sp.artist_related_artists(self.artistid)
artists = self.prepare_artist_listitems(artists['artists'])
self.cache.set(cachestr, artists, checksum=checksum)
self.add_artist_listitems(artists)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_artists:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_artists)
def browse_playlist(self):
xbmcplugin.setContent(self.addon_handle, "songs")
playlistdetails = self.get_playlist_details(self.ownerid, self.playlistid)
xbmcplugin.setProperty(self.addon_handle, 'FolderName', playlistdetails["name"])
self.add_track_listitems(playlistdetails["tracks"]["items"], True)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_songs:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_songs)
def browse_category(self):
xbmcplugin.setContent(self.addon_handle, "files")
playlists = self.get_category(self.filter)
self.add_playlist_listitems(playlists['playlists']['items'])
xbmcplugin.setProperty(self.addon_handle, 'FolderName', playlists['category'])
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_category:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_category)
def browse_newreleases(self):
xbmcplugin.setContent(self.addon_handle, "albums")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', self.addon.getLocalizedString(11005))
albums = self.get_newreleases()
self.add_album_listitems(albums)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_albums:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_albums)
def browse_artistalbums(self):
xbmcplugin.setContent(self.addon_handle, "albums")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(132))
artist = self.sp.artist(self.artistid)
artistalbums = self.sp.artist_albums(
self.artistid,
limit=50,
offset=0,
market=self.usercountry,
album_type='album,single,compilation')
count = len(artistalbums['items'])
albumids = []
while artistalbums['total'] > count:
artistalbums['items'] += self.sp.artist_albums(self.artistid,
limit=50,
offset=count,
market=self.usercountry,
album_type='album,single,compilation')['items']
count += 50
for album in artistalbums['items']:
albumids.append(album["id"])
albums = self.prepare_album_listitems(albumids)
self.add_album_listitems(albums)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_ALBUM_IGNORE_THE)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_SONG_RATING)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_albums:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_albums)
def browse_savedalbums(self):
xbmcplugin.setContent(self.addon_handle, "albums")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(132))
albums = self.get_savedalbums()
self.add_album_listitems(albums, True)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_ALBUM_IGNORE_THE)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_SONG_RATING)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
xbmcplugin.setContent(self.addon_handle, "albums")
if self.defaultview_albums:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_albums)
def browse_savedtracks(self):
xbmcplugin.setContent(self.addon_handle, "songs")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(134))
tracks = self.get_saved_tracks()
self.add_track_listitems(tracks, True)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_songs:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_songs)
def browse_savedartists(self):
xbmcplugin.setContent(self.addon_handle, "artists")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(133))
artists = self.get_savedartists()
self.add_artist_listitems(artists)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_TITLE)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_artists:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_artists)
def create_listing(listing, succeeded=True, update_listing=False, cache_to_disk=False, sort_methods=None,
view_mode=None, content=None, category=None):
"""
Create and return a context dict for a virtual folder listing
:param listing: the list of the plugin virtual folder items
:type listing: list or types.GeneratorType
:param succeeded: if ``False`` Kodi won't open a new listing and stays on the current level.
:type succeeded: bool
:param update_listing: if ``True``, Kodi won't open a sub-listing but refresh the current one.
:type update_listing: bool
:param cache_to_disk: cache this view to disk.
:type cache_to_disk: bool
:param sort_methods: the list of integer constants representing virtual folder sort methods.
:type sort_methods: tuple
:param view_mode: a numeric code for a skin view mode.
View mode codes are different in different skins except for ``50`` (basic listing).
:type view_mode: int
:param content: string - current plugin content, e.g. 'movies' or 'episodes'.
See :func:`xbmcplugin.setContent` for more info.
:type content: str
:param category: str - plugin sub-category, e.g. 'Comedy'.
See :func:`xbmcplugin.setPluginCategory` for more info.
:type category: str
:return: context object containing necessary parameters
to create virtual folder listing in Kodi UI.
:rtype: ListContext
"""
return ListContext(listing, succeeded, update_listing, cache_to_disk,
sort_methods, view_mode, content, category)
def _add_directory_items(self, context):
"""
Create a virtual folder listing
:param context: context object
:type context: ListContext
:raises SimplePluginError: if sort_methods parameter is not int, tuple or list
"""
self.log_debug('Creating listing from {0}'.format(str(context)))
if context.category is not None:
xbmcplugin.setPluginCategory(self._handle, context.category)
if context.content is not None:
xbmcplugin.setContent(self._handle, context.content) # This must be at the beginning
for item in context.listing:
is_folder = item.get('is_folder', True)
if item.get('list_item') is not None:
list_item = item['list_item']
else:
list_item = self.create_list_item(item)
if item.get('is_playable'):
list_item.setProperty('IsPlayable', 'true')
is_folder = False
xbmcplugin.addDirectoryItem(self._handle, item['url'], list_item, is_folder)
if context.sort_methods is not None:
if isinstance(context.sort_methods, int):
xbmcplugin.addSortMethod(self._handle, context.sort_methods)
elif isinstance(context.sort_methods, (tuple, list)):
for method in context.sort_methods:
xbmcplugin.addSortMethod(self._handle, method)
else:
raise TypeError(
'sort_methods parameter must be of int, tuple or list type!')
xbmcplugin.endOfDirectory(self._handle,
context.succeeded,
context.update_listing,
context.cache_to_disk)
if context.view_mode is not None:
xbmc.executebuiltin('Container.SetViewMode({0})'.format(context.view_mode))
def set_content(content):
xbmcplugin.setContent(int(sys.argv[1]), content)
def set_view(view_mode, view_code=0):
_log("set_view view_mode='"+view_mode+"', view_code="+str(view_code))
# Set the content for extended library views if needed
if view_mode==MOVIES:
_log("set_view content is movies")
xbmcplugin.setContent( int(sys.argv[1]) ,"movies" )
elif view_mode==TV_SHOWS:
_log("set_view content is tvshows")
xbmcplugin.setContent( int(sys.argv[1]) ,"tvshows" )
elif view_mode==SEASONS:
_log("set_view content is seasons")
xbmcplugin.setContent( int(sys.argv[1]) ,"seasons" )
elif view_mode==EPISODES:
_log("set_view content is episodes")
xbmcplugin.setContent( int(sys.argv[1]) ,"episodes" )
# Reads skin name
skin_name = xbmc.getSkinDir()
_log("set_view skin_name='"+skin_name+"'")
try:
if view_code==0:
_log("set_view view mode is "+view_mode)
view_codes = ALL_VIEW_CODES.get(view_mode)
view_code = view_codes.get(skin_name)
_log("set_view view code for "+view_mode+" in "+skin_name+" is "+str(view_code))
xbmc.executebuiltin("Container.SetViewMode("+str(view_code)+")")
else:
_log("set_view view code forced to "+str(view_code))
xbmc.executebuiltin("Container.SetViewMode("+str(view_code)+")")
except:
_log("Unable to find view code for view mode "+str(view_mode)+" and skin "+skin_name)