我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用xbmcplugin.setContent()。
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)
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)
def setView(content, viewType): # set content type so library shows more views and info if content: xbmcplugin.setContent(int(sys.argv[1]), content) if ADDON.getSetting('auto-view') == 'true':#<<<----see here if auto-view is enabled(true) xbmc.executebuiltin("Container.SetViewMode(%s)" % ADDON.getSetting(viewType) )#<<<-----then get the view type
def setView(content, viewType): # set content type so library shows more views and info if content: xbmcplugin.setContent(int(sys.argv[1]), content) if ADDON.getSetting('auto-view') == 'true': xbmc.executebuiltin("Container.SetViewMode(%s)" % ADDON.getSetting(viewType) ) #checkGA()
def setView(content, viewType): if content: xbmcplugin.setContent(int(sys.argv[1]), content) if ADDON.getSetting('auto-view') == 'true':#<<<----see here if auto-view is enabled(true) xbmc.executebuiltin("Container.SetViewMode(%s)" % ADDON.getSetting(viewType) )#<<<-----then get the view type
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 category(group): promoGroup = {'rising': 'RISING', 'discovery': 'DISCOVERY', 'featured': 'NEWS'}.get(group, None) items = session.get_category_items(group) totalCount = 0 for item in items: totalCount += len(item.content_types) if totalCount == 1: # Show Single content directly (Movies and TV Shows) for item in items: content_types = item.content_types for content_type in content_types: category_content(group, item.path, content_type, offset=0) return xbmcplugin.setContent(plugin.handle, 'files') if promoGroup and totalCount > 10: # Add Promotions as Folder on the Top if more than 10 Promotions available add_directory(_T(30120), plugin.url_for(featured, group=promoGroup)) add_directory('Master %s (MQA)' % _T(30107), plugin.url_for(master_albums, offset=0)) add_directory('Master %s (MQA)' % _T(30108), plugin.url_for(master_playlists, offset=0)) # Add Category Items as Folders add_items(items, content=None, end=not(promoGroup and totalCount <= 10)) if promoGroup and totalCount <= 10: # Show up to 10 Promotions as single Items promoItems = session.get_featured(promoGroup, types=['ALBUM', 'PLAYLIST', 'VIDEO']) if promoItems: add_items(promoItems, end=True)
def create_listing(listing, succeeded=True, update_listing=False, cache_to_disk=False, sort_methods=None, view_mode=None, content=None): """ Create and return a context dict for a virtual folder listing :param listing: the list of the plugin virtual folder items :type listing: :class:`list` or :class:`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 :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)
def _add_directory_items(self, context): """ Create a virtual folder listing :param context: context object :type context: ListContext """ self.log_debug('Creating listing from {0}'.format(str(context))) 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: [xbmcplugin.addSortMethod(self._handle, method) for method in context.sort_methods] 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 addLink(name,url,title,iconimage,fanart,info=None): ok=True liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage,) liz.setProperty('fanart_image',fanart) liz.setProperty("IsPlayable", "true") liz.setInfo( type="Video", infoLabels={ "Title": title } ) if info != None: liz.setInfo( type="Video", infoLabels=info) ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz) xbmcplugin.setContent(int(sys.argv[1]), 'episodes') return ok
def addFreeLink(name,link_url,iconimage,fanart=None,scrape_type=None,info=None): params = get_params() ok=True u=sys.argv[0]+"?url="+urllib.quote_plus(link_url)+"&mode=6&icon_image="+urllib.quote_plus(iconimage) liz=xbmcgui.ListItem(name, iconImage=ICON, thumbnailImage=iconimage) liz.setProperty("IsPlayable", "true") liz.setInfo( type="Video", infoLabels={ "Title": name } ) if info != None: liz.setInfo( type="Video", infoLabels=info) liz.setProperty('fanart_image', fanart) ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz) xbmcplugin.setContent(int(sys.argv[1]), 'episodes') return ok
def addPremiumLink(name,link_url,iconimage,fanart=None,scrape_type=None,info=None): params = get_params() ok=True u=sys.argv[0]+"?url="+urllib.quote_plus(link_url)+"&mode=5&icon_image="+urllib.quote_plus(iconimage) liz=xbmcgui.ListItem(name, iconImage=ICON, thumbnailImage=iconimage) liz.setProperty("IsPlayable", "true") liz.setInfo( type="Video", infoLabels={ "Title": name } ) if info != None: liz.setInfo( type="Video", infoLabels=info) liz.setProperty('fanart_image', fanart) ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz) xbmcplugin.setContent(int(sys.argv[1]), 'episodes') return ok
def addDir(name,url,mode,iconimage,fanart=None,scrape_type=None,isFolder=True,info=None): params = get_params() ok=True u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&scrape_type="+urllib.quote_plus(str(scrape_type))+"&icon_image="+urllib.quote_plus(str(iconimage)) liz=xbmcgui.ListItem(name, iconImage=ICON, thumbnailImage=iconimage) liz.setInfo( type="Video", infoLabels={ "Title": name } ) if info != None: liz.setInfo( type="Video", infoLabels=info) liz.setProperty('fanart_image', fanart) ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=isFolder) xbmcplugin.setContent(int(sys.argv[1]), 'episodes') return ok
def add_item(title, params, items=False, folder=True, playable=False, set_info=False, set_art=False, watched=False, set_content=False, context_menu=None): listitem = xbmcgui.ListItem(label=title) if playable: listitem.setProperty('IsPlayable', 'true') folder = False if set_art: listitem.setArt(set_art) else: art = { 'icon': addon.getAddonInfo('icon'), 'fanart': addon.getAddonInfo('fanart') } listitem.setArt(art) if set_info: listitem.setInfo('video', set_info) if not watched: listitem.addStreamInfo('video', {'duration': 0}) if set_content: xbmcplugin.setContent(_handle, set_content) if context_menu: run = '%s(%s)' % (context_menu['function'], context_menu['_url']) listitem.addContextMenuItems([(context_menu['title'], run)]) listitem.setContentLookup(False) # allows sending custom headers/cookies to ffmpeg recursive_url = _url + '?' + urllib.urlencode(params) if items is False: xbmcplugin.addDirectoryItem(_handle, recursive_url, listitem, folder) else: items.append((recursive_url, listitem, folder)) return items
def SetView(content): xbmcplugin.setContent(pluginhandle, content) xbmcplugin.endOfDirectory(pluginhandle, updateListing=False)
def set_content(content): xbmcplugin.setContent(int(sys.argv[1]), content) # HELPDIR**************************************************************