我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用xbmcplugin.addSortMethod()。
def showShows(category_url): """Display all shows under a sub category params: category_url: a sub category is a unique id """ showListData = get_show_list(category_url) if showListData is None: xbmcplugin.endOfDirectory(thisPlugin) return for show_id, (title, thumbnail) in showListData.iteritems(): addDir(title, str(show_id), Mode.SHOW_INFO, thumbnail) xbmcplugin.addSortMethod(thisPlugin, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.endOfDirectory(thisPlugin)
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_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 show_sport_selection(self): """Creates the KODI list items for the static sport selection""" self.utils.log('Sport selection') sports = self.constants.get_sports_list() for sport in sports: url = self.utils.build_url({'for': sport}) list_item = xbmcgui.ListItem(label=sports.get(sport).get('name')) list_item = self.item_helper.set_art( list_item=list_item, sport=sport) xbmcplugin.addDirectoryItem( handle=self.plugin_handle, url=url, listitem=list_item, isFolder=True) xbmcplugin.addSortMethod( handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_DATE) xbmcplugin.endOfDirectory(self.plugin_handle)
def channeltypes(params,url,category): logger.info("channelselector.channeltypes") lista = getchanneltypes() for item in lista: addfolder(item.title,item.channel,item.action,category=item.category,thumbnailname=item.thumbnail) if config.get_platform()=="kodi-krypton": import plugintools plugintools.set_view( plugintools.TV_SHOWS ) # Label (top-right)... import xbmcplugin xbmcplugin.setPluginCategory( handle=int( sys.argv[ 1 ] ), category="" ) xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_NONE ) xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=True ) if config.get_setting("forceview")=="true": # Confluence - Thumbnail import xbmc xbmc.executebuiltin("Container.SetViewMode(500)")
def listchannels(params,url,category): logger.info("channelselector.listchannels") lista = filterchannels(category) for channel in lista: if config.is_xbmc() and (channel.type=="xbmc" or channel.type=="generic"): addfolder(channel.title , channel.channel , "mainlist" , channel.channel) elif config.get_platform()=="boxee" and channel.extra!="rtmp": addfolder(channel.title , channel.channel , "mainlist" , channel.channel) if config.get_platform()=="kodi-krypton": import plugintools plugintools.set_view( plugintools.TV_SHOWS ) # Label (top-right)... import xbmcplugin xbmcplugin.setPluginCategory( handle=int( sys.argv[ 1 ] ), category=category ) xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_NONE ) xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=True ) if config.get_setting("forceview")=="true": # Confluence - Thumbnail import xbmc xbmc.executebuiltin("Container.SetViewMode(500)")
def MyRecordings(url,group): net.set_cookies(cookie_jar) url='http://www.filmon.com/my/recordings' html = net.http_GET(url).content link = html.encode('ascii', 'ignore') match=re.compile('"stream_url":"(.+?),"stream_name":"(.+?)","id":".+?","title":"(.+?)","description":"(.+?)","channel_id":"(.+?)"').findall(link) for a, playPath, name, description, channel in match: url1=str(a).replace('\/','/') url2=str(a).replace('\/','/').replace('"','') regex = re.compile('rtmp://(.+?)/(.+?)/(.+?)/(.+?)/(.+?)/(.+?)/(.+?)"') match1 = regex.search(url1) try: app = '%s/%s/%s/%s/%s/%s' %(match1.group(2), match1.group(3),match1.group(4),match1.group(5),match1.group(6),match1.group(7)) except: app='' tcUrl=str(url2) iconimage='https://static.filmon.com/couch/channels/%s/big_logo.png' % str(channel) swfUrl= 'http://www.filmon.com/tv/modules/FilmOnTV/files/flashapp/filmon/FilmonPlayer.swf' pageUrl = 'http://www.filmon.com/my/recordings' url= str(url2)+'/'+str(playPath)+' playpath='+str(playPath)+' app='+str(app)+' swfUrl='+str(swfUrl)+' tcUrl='+str(tcUrl)+' pageurl='+str(pageUrl) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) addLink(name,url,iconimage,playPath,app,pageUrl,swfUrl,tcUrl,description) setView('movies', 'epg')
def addDir(name,url,mode,iconimage,plot='',isFolder=True): try: PID = iconimage.split('productionId=')[1] except:pass u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&iconimage="+urllib.quote_plus(iconimage) ok=True liz=xbmcgui.ListItem(name,iconImage="DefaultVideo.png", thumbnailImage=iconimage) liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot": plot,'Premiered' : '2012-01-01','Episode' : '7-1' } ) menu=[] if mode == 2: menu.append(('[COLOR yellow]Add To Favourites[/COLOR]','XBMC.RunPlugin(%s?mode=13&url=%s&name=%s&iconimage=%s)'% (sys.argv[0],url,name,PID))) if mode == 204: menu.append(('[COLOR yellow]Remove Favourite[/COLOR]','XBMC.RunPlugin(%s?mode=14&url=%s&name=%s&iconimage=%s)'% (sys.argv[0],url,name,iconimage))) liz.addContextMenuItems(items=menu, replaceItems=False) if mode==3: xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE) if isFolder==False: liz.setProperty("IsPlayable","true") ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=isFolder) return ok
def TG4_CATCHUP(name): link= OPEN_URL('http://www.tg4.ie/wp-content/themes/tg4-starter/assets/json/tg4data.json')#.encode('utf8') #print link.encode('ascii','ignore') import json data=json.loads(link) uniques=[] for field in data: id= field['id'] iconimage=field['videoStillURL'] description=htmlcleaner.cleanUnicode(field['shortDescription']) name=htmlcleaner.cleanUnicode(field['customFields']['seriestitle']) if name not in uniques: uniques.append(name) try:addDir(name,'url',12,iconimage,description) except:pass xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE)
def GetContent(url): CHANNEL = url xunity='http://vschedules.uktv.co.uk/mobile/v2/most_popular?channel=%s&carousel_limit=100&platform=ios&app_ver=4.1.0' % CHANNEL response=OPEN_URL(xunity) link=json.loads(response) #data=link['brands'] for field in link: name= field['brand_name'].encode("utf-8") iconimage= field['brand_image'].encode("utf-8") channel=field['channel'].encode("utf-8") try:desc=field['teaser_text'].encode("utf-8") except:desc='' brand_id=field['brand_id'] if CHANNEL in channel: addDir(name.strip(),str(brand_id),2,iconimage,desc) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) setView('movies', 'default')
def GetCat(url): xunity='http://vschedules.uktv.co.uk/mobile/v2/genres?platform=ios&app_ver=4.1.0' response=OPEN_URL(xunity) link=json.loads(response) #data=link['data'] for field in link: name= field['title'].encode("utf-8") iconimage= field['image'].encode("utf-8") brand_id=field['name'] addDir(name.strip(),str(brand_id),4,iconimage,'') xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) setView('movies', 'default')
def GetEpisodes(url): xunity='http://vschedules.uktv.co.uk/mapi/branddata/?format=json&brand_id='+url response=OPEN_URL(xunity) link=json.loads(response) data=link['videos'] for field in data: name= 'S'+field['series_txt']+'E'+field['episode_txt']+' - '+field['brand_name'].encode("utf-8") iconimage= field['episode_img_cached'].encode("utf-8") channel=field['channel'].encode("utf-8") desc=field['teaser_text'].encode("utf-8") brightcove=field['brightcove_video_id'] addDir(name,str(brightcove),200,iconimage,desc) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) setView('movies', 'default')
def FindSearch(url): response=OPEN_URL(url) link=json.loads(response) link=link['brands'] for field in link: count=field['video_count'] channel=field['channel'].encode("utf-8").title() color='grey' if 'Dave' in channel: color='green' if 'Drama' in channel: color='red' if 'Yesterday' in channel: color='yellow' if 'Really' in channel: color='orange' name= field['brand_name'].encode("utf-8") + ' (%s Episodes) - [COLOR %s]%s[/COLOR]' % (str(count),color,channel) iconimage= field['brand_image'].encode("utf-8") brand_id=field['brand_id'] addDir(name.strip(),str(brand_id),2,iconimage,'') xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) setView('movies', 'default')
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 channeltypes(params,url,category): logger.info("channelselector.mainlist channeltypes") categoria=category.decode('latin1').encode('utf-8') if config.get_localized_string(30119) in categoria: lista = getchanneltypes() for item in lista: addfolder(item.title,item.channel,item.action,item.category,item.thumbnail,item.thumbnail) # Label (top-right)... import xbmcplugin xbmcplugin.setPluginCategory( handle=int( sys.argv[ 1 ] ), category="" ) xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_NONE ) xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=True ) if config.get_setting("forceview")=="true": # Confluence - Thumbnail import xbmc xbmc.executebuiltin("Container.SetViewMode(500)") else: listchannels({'action': 'listchannels', 'category': '%2a', 'channel': 'channelselector'},'','*')
def LIST_MOVIES(filter='', value=False, sortcol=False, sortaz=True, search=False, cmmode=0): import movies as moviesDB if 'year' in filter: value = value.replace('0 -', '') movies = moviesDB.loadMoviedb(movie_filter=filter, value=value, sortcol=sortcol) count = 0 for moviedata in movies: count += 1 ADD_MOVIE_ITEM(moviedata, cmmode=cmmode) if not search: if sortaz: if 'year' not in filter: xbmcplugin.addSortMethod(common.pluginhandle, xbmcplugin.SORT_METHOD_VIDEO_TITLE) xbmcplugin.addSortMethod(common.pluginhandle, xbmcplugin.SORT_METHOD_VIDEO_YEAR) xbmcplugin.addSortMethod(common.pluginhandle, xbmcplugin.SORT_METHOD_VIDEO_RUNTIME) xbmcplugin.addSortMethod(common.pluginhandle, xbmcplugin.SORT_METHOD_VIDEO_RATING) xbmcplugin.addSortMethod(common.pluginhandle, xbmcplugin.SORT_METHOD_DURATION) xbmcplugin.addSortMethod(common.pluginhandle, xbmcplugin.SORT_METHOD_STUDIO_IGNORE_THE) common.SetView('movies') return count
def LIST_TVSHOWS(filter='', value=False, sortcol=False, sortaz=True, search=False, cmmode=0): import tv as tvDB if 'year' in filter: value = value.replace('0 -', '') shows = tvDB.loadTVShowdb(filter=filter, value=value, sortcol=sortcol) count = 0 for showdata in shows: count += 1 ADD_SHOW_ITEM(showdata, cmmode=cmmode) if not search: if sortaz: if 'year' not in filter: xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_LABEL) xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_VIDEO_YEAR) xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_VIDEO_RATING) xbmcplugin.addSortMethod(pluginhandle, xbmcplugin.SORT_METHOD_STUDIO_IGNORE_THE) common.SetView('tvshows') return count
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 rootDir(): print sys.argv nav = getNav() #Livesender liveChannelsDir() #Navigation der Ipad App for item in nav: if item.attrib['hide'] == 'true' or item.tag == 'item': continue url = common.build_url({'action': 'listPage', 'id': item.attrib['id']}) addDir(item.attrib['label'], url) li = xbmcgui.ListItem(item.attrib['label']) #Merkliste watchlistDir() #Suchfunktion url = common.build_url({'action': 'search'}) addDir('Suche', url) xbmcplugin.addSortMethod(handle=addon_handle, sortMethod=xbmcplugin.SORT_METHOD_NONE) xbmcplugin.addSortMethod(handle=addon_handle, sortMethod=xbmcplugin.SORT_METHOD_LABEL) xbmcplugin.endOfDirectory(addon_handle, cacheToDisc=True)
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 SelectHost(): for host in HostsList: if ADDON.getSetting(host[0]) == 'true': hostName = host[1].replace("https:",'').replace("http:",'').replace("/",'').replace("www.",'') hostImage = '%s/icons/%s.png' % (ADDON.getSetting("kodiIPTVpath"), host[0]) list_item = xbmcgui.ListItem(label = hostName) list_item.setArt({'thumb': hostImage,}) list_item.setInfo('video', {'title': hostName, 'genre': hostName}) url = get_url(action='startHost', host=host[0]) myLog(url) is_folder = True # Add our item to the Kodi virtual folder listing. xbmcplugin.addDirectoryItem(ADDON_handle, url, list_item, is_folder) # Add a sort method for the virtual folder items (alphabetically, ignore articles) xbmcplugin.addSortMethod(ADDON_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) # Finish creating a virtual folder. xbmcplugin.endOfDirectory(ADDON_handle) return
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 _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 show_date_list(self, _for): """ Creates the KODI list items for a list of dates with contents based on the current date & syndication. :param _for: Chosen sport :type _for: string """ self.utils.log('Main menu') plugin_handle = self.plugin_handle addon_data = self.utils.get_addon_data() epg = self.get_epg(_for) for _date in epg.keys(): title = '' items = epg.get(_date) for item in items: title = title + \ str(' '.join(item.get('title').replace('Uhr', '').split( ' ')[:-2]).encode('utf-8')) + '\n\n' url = self.utils.build_url({'date': date, 'for': _for}) list_item = xbmcgui.ListItem(label=_date) list_item.setProperty('fanart_image', addon_data.get('fanart')) list_item.setInfo('video', { 'date': date, 'title': title, 'plot': title, }) xbmcplugin.addDirectoryItem( handle=plugin_handle, url=url, listitem=list_item, isFolder=True) xbmcplugin.addSortMethod( handle=plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_DATE) xbmcplugin.endOfDirectory(plugin_handle)
def show_matches_list(self, game_date, _for): """ Creates the KODI list items with the contents of available matches for a given date :param game_date: Chosen event-lane :type game_date: string :param _for: Chosen sport :type _for: string """ self.utils.log('Matches list: ' + _for) addon_data = self.utils.get_addon_data() plugin_handle = self.plugin_handle epg = self.get_epg(_for) items = epg.get(game_date) for item in items: url = self.utils.build_url( {'hash': item.get('hash'), 'date': game_date, 'for': _for}) list_item = xbmcgui.ListItem(label=item.get('title')) list_item.setProperty('fanart_image', addon_data.get('fanart')) xbmcplugin.addDirectoryItem( handle=plugin_handle, url=url, listitem=list_item, isFolder=True) xbmcplugin.addSortMethod( handle=plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_NONE) xbmcplugin.endOfDirectory(plugin_handle)
def mainlist(params,url,category): logger.info("channelselector.mainlist") # Verifica actualizaciones solo en el primer nivel if config.get_platform()!="boxee": try: from core import updater except ImportError: logger.info("channelselector.mainlist No disponible modulo actualizaciones") else: if config.get_setting("updatecheck2") == "true": logger.info("channelselector.mainlist Verificar actualizaciones activado") updater.checkforupdates() else: logger.info("channelselector.mainlist Verificar actualizaciones desactivado") itemlist = getmainlist("squares") for elemento in itemlist: logger.info("channelselector item="+elemento.tostring()) addfolder(elemento.title , elemento.channel , elemento.action , thumbnailname=elemento.thumbnail, folder=elemento.folder) if config.get_platform()=="kodi-krypton": import plugintools plugintools.set_view( plugintools.TV_SHOWS ) # Label (top-right)... import xbmcplugin #xbmcplugin.setPluginCategory( handle=int( sys.argv[ 1 ] ), category="" ) #xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_NONE ) xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=True ) if config.get_setting("forceview")=="true": # Confluence - Thumbnail import xbmc xbmc.executebuiltin("Container.SetViewMode(500)")
def Channels(url,name,group): r='<li class="channel i-box-sizing".+?channel_id="(.+?)">.+?"channel_logo" src="(.+?)" title="(.+?)"' net.set_cookies(cookie_jar) html = OPEN_URL('http://www.filmon.com'+url) match=re.compile(r,re.DOTALL).findall(html) for id , iconimage , name in match: addDir(name,'http://www.filmon.com'+url.replace('channel','tv'),2,iconimage,id,group) xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) setView('movies', 'default') #GA('None',group)
def filmon_epg(url,group): url1='http://www.filmon.com/tvguide/' html = net.http_GET(url1).content link1 = html.encode('ascii', 'ignore') link=str(link1).replace('\n','') match=re.compile('bottom">(.+?)</h3>.+?href="(.+?)" > <img src="(.+?)".+?.+?div class="title">.+?</div>.+?h4>(.+?)/h4>.+?"description">(.+?)/div>').findall(link) for name, url1, iconimage, showname, description in match: cleandesc=str(description).replace('",','').replace(' ','').replace('<a class="read-more" href="/tvguide/','').replace('">Read more... →</a>','').replace('\xc3','').replace('\xa2','').replace('\xe2','').replace('\x82','').replace('\xac','').replace('\x84','').replace('\xa2s','').replace('\xc2','').replace('\x9d','').replace('<','') showname = str(showname).replace('<','') description = '[B]%s [/B]\n\n%s' % (showname,cleandesc) url = 'http://www.filmon.com'+str(url1) addDir(name,url,2,iconimage,description,'TV Guide') xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) setView('movies', 'epg')
def GetCatList(url): xunity='http://vschedules.uktv.co.uk/mobile/v2/genre_items?genre_name=%s&platform=ios&app_ver=4.1.0' % url.upper() response=OPEN_URL(xunity) link=json.loads(response) #data=link['data'] for field in link: count=field['video_count'] channel=field['channel'].encode("utf-8") color='grey' if 'Dave' in channel: color='green' if 'Drama' in channel: color='red' if 'Yesterday' in channel: color='yellow' if 'Really' in channel: color='orange' name= field['brand_name'].encode("utf-8") + ' (%s Episodes) - [COLOR %s]%s[/COLOR]' % (str(count),color,channel) iconimage= field['brand_image'].encode("utf-8") brand_id=field['brand_id'] addDir(name.strip(),str(brand_id),2,iconimage,'') xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) setView('movies', 'default')
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 build_search_result_folder(self, build_url, term): """Add search result folder Parameters ---------- build_url : :obj:`fn` Function to build the subsequent routes term : :obj:`str` Search term Returns ------- :obj:`str` Search result folder URL """ # add search result as subfolder li_rec = xbmcgui.ListItem( label='({})'.format(term), iconImage=self.default_fanart) li_rec.setProperty('fanart_image', self.default_fanart) url_rec = build_url({'action': 'search_result', 'term': term}) xbmcplugin.addDirectoryItem( handle=self.plugin_handle, url=url_rec, listitem=li_rec, isFolder=True) xbmcplugin.addSortMethod( handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_UNSORTED) xbmcplugin.endOfDirectory(self.plugin_handle) self.set_custom_view(VIEW_FOLDER) return url_rec
def album_view(album_id): xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_TRACKNUM) album = session.get_album(album_id) if album and album.numberOfVideos > 0: add_directory(_T(30110), plugin.url_for(album_videos, album_id=album_id)) add_items(session.get_album_tracks(album_id), content=CONTENT_FOR_TYPE.get('tracks'))
def album_videos(album_id): xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_TRACKNUM) add_items(session.get_album_items(album_id, ret='videos'), content=CONTENT_FOR_TYPE.get('videos'))
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))