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)
评论列表
文章目录