我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用xbmcplugin.setProperty()。
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 add_artist_listitems(self, artists): for item in artists: if KODI_VERSION > 17: li = xbmcgui.ListItem(item["name"], path=item['url'], offscreen=True) else: li = xbmcgui.ListItem(item["name"], path=item['url']) infolabels = { "title": item["name"], "genre": item["genre"], "artist": item["name"], "rating": item["rating"] } li.setInfo(type="Music", infoLabels=infolabels) li.setArt({"thumb": item['thumb']}) li.setProperty('do_not_analyze', 'true') li.setProperty('IsPlayable', 'false') li.setLabel2(item["followerslabel"]) li.addContextMenuItems(item["contextitems"], True) xbmcplugin.addDirectoryItem( handle=self.addon_handle, url=item["url"], listitem=li, isFolder=True, totalItems=len(artists))
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 add_next_button(self, listtotal): # adds a next button if needed params = self.params if listtotal > self.offset + self.limit: params["offset"] = self.offset + self.limit url = "plugin://plugin.audio.spotify/" for key, value in params.iteritems(): if key == "action": url += "?%s=%s" % (key, value[0]) elif key == "offset": url += "&%s=%s" % (key, value) else: url += "&%s=%s" % (key, value[0]) li = xbmcgui.ListItem( xbmc.getLocalizedString(33078), path=url, iconImage="DefaultMusicAlbums.png" ) li.setProperty('do_not_analyze', 'true') li.setProperty('IsPlayable', 'false') xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=url, listitem=li, isFolder=True)
def precache_library(self): if not self.win.getProperty("Spotify.PreCachedItems"): monitor = xbmc.Monitor() self.win.setProperty("Spotify.PreCachedItems", "busy") userplaylists = self.get_user_playlists(self.userid) for playlist in userplaylists: self.get_playlist_details(playlist['owner']['id'], playlist["id"]) if monitor.abortRequested(): return self.get_savedalbums() if monitor.abortRequested(): return self.get_savedartists() if monitor.abortRequested(): return self.get_saved_tracks() del monitor self.win.setProperty("Spotify.PreCachedItems", "done")
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 browse_main_explore(self): # explore nodes xbmcplugin.setContent(self.addon_handle, "files") xbmcplugin.setProperty(self.addon_handle, 'FolderName', self.addon.getLocalizedString(11014)) items = [] items.append( (self.addon.getLocalizedString(11015), "plugin://plugin.audio.spotify/?action=browse_playlists&applyfilter=featured", "DefaultMusicPlaylists.png")) items.append( (self.addon.getLocalizedString(11016), "plugin://plugin.audio.spotify/?action=browse_newreleases", "DefaultMusicAlbums.png")) # add categories items += self.get_explore_categories() for item in items: li = xbmcgui.ListItem( item[0], path=item[1], iconImage=item[2] ) li.setProperty('do_not_analyze', 'true') 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=True) xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED) xbmcplugin.endOfDirectory(handle=self.addon_handle)
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_playlists(self): xbmcplugin.setContent(self.addon_handle, "files") if self.filter == "featured": playlists = self.get_featured_playlists() xbmcplugin.setProperty(self.addon_handle, 'FolderName', playlists['message']) playlists = playlists['playlists']['items'] else: xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(136)) playlists = self.get_user_playlists(self.ownerid) self.add_playlist_listitems(playlists) xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED) xbmcplugin.endOfDirectory(handle=self.addon_handle) if self.defaultview_playlists: xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_playlists)
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 add_album_listitems(self, albums, append_artist_to_label=False): # process listing for item in albums: if append_artist_to_label: label = "%s - %s" % (item["artist"], item['name']) else: label = item['name'] if KODI_VERSION > 17: li = xbmcgui.ListItem(label, path=item['url'], offscreen=True) else: li = xbmcgui.ListItem(label, path=item['url']) infolabels = { "title": item['name'], "genre": item["genre"], "year": item["year"], "album": item["name"], "artist": item["artist"], "rating": item["rating"] } li.setInfo(type="Music", infoLabels=infolabels) li.setArt({"thumb": item['thumb']}) li.setProperty('do_not_analyze', 'true') li.setProperty('IsPlayable', 'false') li.addContextMenuItems(item["contextitems"], True) xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=item["url"], listitem=li, isFolder=True)
def add_playlist_listitems(self, playlists): for item in playlists: if KODI_VERSION > 17: li = xbmcgui.ListItem(item["name"], path=item['url'], offscreen=True) else: li = xbmcgui.ListItem(item["name"], path=item['url']) li.setProperty('do_not_analyze', 'true') li.setProperty('IsPlayable', 'false') li.addContextMenuItems(item["contextitems"], True) li.setArt({"fanart": "special://home/addons/plugin.audio.spotify/fanart.jpg", "thumb": item['thumb']}) xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=item["url"], listitem=li, isFolder=True)
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_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 browse_followedartists(self): xbmcplugin.setContent(self.addon_handle, "artists") xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(133)) artists = self.get_followedartists() self.add_artist_listitems(artists) xbmcplugin.endOfDirectory(handle=self.addon_handle) if self.defaultview_artists: xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_artists)
def browse_playback_devices(self): '''set the active playback device''' xbmcplugin.setContent(self.addon_handle, "files") items = [] if self.win.getProperty("spotify.supportsplayback"): # local playback label = self.addon.getLocalizedString(11037) if self.local_playback: label += " [%s]" % self.addon.getLocalizedString(11040) url = "plugin://plugin.audio.spotify/?action=set_playback_device&deviceid=local" li = xbmcgui.ListItem(label, iconImage="DefaultMusicCompilations.png") 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=url, listitem=li, isFolder=False) else: # local playback using a remote service label = self.addon.getLocalizedString(11060) if self.addon.getSetting("playback_device") == "remote": label += " [%s]" % self.addon.getLocalizedString(11040) url = "plugin://plugin.audio.spotify/?action=set_playback_device&deviceid=remote" li = xbmcgui.ListItem(label, iconImage="DefaultMusicCompilations.png") 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=url, listitem=li, isFolder=False) # connect devices for device in self.sp.devices()["devices"]: label = "Spotify Connect: %s" % device["name"] if device["is_active"] and self.addon.getSetting("playback_device") == "connect": label += " [%s]" % self.addon.getLocalizedString(11040) url = "plugin://plugin.audio.spotify/?action=set_playback_device&deviceid=%s" % device["id"] li = xbmcgui.ListItem(label, iconImage="DefaultMusicCompilations.png") 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=url, listitem=li, isFolder=False) if xbmc.getCondVisibility("System.HasAddon(plugin.audio.squeezebox)"): # LMS playback label = xbmc.getInfoLabel("System.AddonTitle(plugin.audio.squeezebox)") if self.addon.getSetting("playback_device") == "squeezebox": label += " [%s]" % self.addon.getLocalizedString(11040) url = "plugin://plugin.audio.spotify/?action=set_playback_device&deviceid=squeezebox" li = xbmcgui.ListItem(label, iconImage="DefaultMusicCompilations.png") 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=url, listitem=li, isFolder=False) xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED) xbmcplugin.endOfDirectory(handle=self.addon_handle)
def browse_main_library(self): # library nodes xbmcplugin.setContent(self.addon_handle, "files") xbmcplugin.setProperty(self.addon_handle, 'FolderName', self.addon.getLocalizedString(11013)) items = [] items.append( (xbmc.getLocalizedString(136), "plugin://plugin.audio.spotify/?action=browse_playlists&ownerid=%s" % (self.userid), "DefaultMusicPlaylists.png")) items.append( (xbmc.getLocalizedString(132), "plugin://plugin.audio.spotify/?action=browse_savedalbums", "DefaultMusicAlbums.png")) items.append( (xbmc.getLocalizedString(134), "plugin://plugin.audio.spotify/?action=browse_savedtracks", "DefaultMusicSongs.png")) items.append( (xbmc.getLocalizedString(133), "plugin://plugin.audio.spotify/?action=browse_savedartists", "DefaultMusicArtists.png")) items.append( (self.addon.getLocalizedString(11023), "plugin://plugin.audio.spotify/?action=browse_topartists", "DefaultMusicArtists.png")) items.append( (self.addon.getLocalizedString(11024), "plugin://plugin.audio.spotify/?action=browse_toptracks", "DefaultMusicSongs.png")) for item in items: li = xbmcgui.ListItem( item[0], path=item[1], iconImage=item[2] ) li.setProperty('do_not_analyze', 'true') 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=True) xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED) xbmcplugin.endOfDirectory(handle=self.addon_handle)
def search(self): xbmcplugin.setContent(self.addon_handle, "files") xbmcplugin.setPluginCategory(self.addon_handle, xbmc.getLocalizedString(283)) kb = xbmc.Keyboard('', xbmc.getLocalizedString(16017)) kb.doModal() if kb.isConfirmed(): value = kb.getText() items = [] result = self.sp.search( q="%s" % value, type='artist,album,track,playlist', limit=1, market=self.usercountry) items.append( ("%s (%s)" % (xbmc.getLocalizedString(133), result["artists"]["total"]), "plugin://plugin.audio.spotify/?action=search_artists&artistid=%s" % (value))) items.append( ("%s (%s)" % (xbmc.getLocalizedString(136), result["playlists"]["total"]), "plugin://plugin.audio.spotify/?action=search_playlists&playlistid=%s" % (value))) items.append( ("%s (%s)" % (xbmc.getLocalizedString(132), result["albums"]["total"]), "plugin://plugin.audio.spotify/?action=search_albums&albumid=%s" % (value))) items.append( ("%s (%s)" % (xbmc.getLocalizedString(134), result["tracks"]["total"]), "plugin://plugin.audio.spotify/?action=search_tracks&trackid=%s" % (value))) for item in items: li = xbmcgui.ListItem( item[0], path=item[1], iconImage="DefaultMusicAlbums.png" ) li.setProperty('do_not_analyze', 'true') li.setProperty('IsPlayable', 'false') li.addContextMenuItems([], True) xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=item[1], listitem=li, isFolder=True) xbmcplugin.endOfDirectory(handle=self.addon_handle)