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)
python类addSortMethod()的实例源码
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))