-
Notifications
You must be signed in to change notification settings - Fork 2
/
addon.py
114 lines (103 loc) · 4.24 KB
/
addon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# -*- coding: utf-8 -*-
# Module: default
# Author: Yangqian
# Created on: 25.12.2015
# License: GPL v.3 https://www.gnu.org/copyleft/gpl.html
# Largely following the example at
# https://github.com/romanvm/plugin.video.example/blob/master/main.py
import xbmc,xbmcgui,urllib2,re,xbmcplugin
from BeautifulSoup import BeautifulSoup
from urlparse import parse_qsl
import sys
import json
# Get the plugin url in plugin:// notation.
_url=sys.argv[0]
# Get the plugin handle as an integer number.
_handle=int(sys.argv[1])
def list_categories():
f=urllib2.urlopen('http://www.panda.tv/cate')
rr=BeautifulSoup(f.read())
catel=rr.findAll('li',{'class':'category-list-item'})
rrr=[(x.a['class'], x.a['title']) for x in catel]
listing=[]
for classname,text in rrr:
img=rr.find('img',{'alt':text})['src']
list_item=xbmcgui.ListItem(label=text,thumbnailImage=img)
list_item.setProperty('fanart_image',img)
url='{0}?action=listing&category={1}'.format(_url,classname)
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):
f=urllib2.urlopen('http://www.panda.tv/cate/'+category)
rr=BeautifulSoup(f.read())
videol=rr.findAll('a',{'class':'video-list-item-inner'})
rrr=[(x['href'][1:],x.img,x.findNextSibling('div',{'class':'live-info'})) for x in videol]
listing=[]
for roomid,image,liveinfo in rrr:
img=image['src']
roomname=image['alt']
nickname=liveinfo.find('span',{'class':'nick-name'}).text
peoplenumber=liveinfo.find('span',{'class':'people-number'}).text
combinedname=u'{0}:{1}:{2}'.format(nickname,roomname,peoplenumber)
list_item=xbmcgui.ListItem(label=combinedname,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))
xbmcplugin.addDirectoryItems(_handle,listing,len(listing))
#xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)
def play_video(roomid):
"""
Play a video by the provided path.
:param path: str
:return: None
"""
f=urllib2.urlopen('http://www.panda.tv/api_room?roomid='+roomid)
r=f.read()
ss=json.loads(r)
hostname=ss['data']['hostinfo']['name']
roomname=ss['data']['roominfo']['name']
#s=re.search('''"room_key":"(.*?)"''',r).group(1)
s=ss['data']['videoinfo']['room_key']
img=ss['data']['hostinfo']['avatar']
combinedname=u'{0}:{1}'.format(hostname,roomname)
# Create a playable item with a path to play.
path='http://pl3.live.panda.tv/live_panda/{0}.flv'.format(s)
play_item = xbmcgui.ListItem(path=path,thumbnailImage=img)
play_item.setInfo(type="Video",infoLabels={"Title":combinedname})
# Pass the item to the Kodi player.
xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)
# directly play the item.
xbmc.Player().play(path, play_item)
def router(paramstring):
"""
Router function that calls other functions
depending on the provided paramstring
:param paramstring:
:return:
"""
# Parse a URL-encoded paramstring to the dictionary of
# {<parameter>: <value>} elements
params = dict(parse_qsl(paramstring))
# Check the parameters passed to the plugin
if params:
if params['action'] == 'listing':
# Display the list of videos in a provided category.
list_videos(params['category'])
elif params['action'] == 'play':
# Play a video from a provided URL.
play_video(params['video'])
else:
# If the plugin is called from Kodi UI without any parameters,
# display the list of video categories
list_categories()
if __name__ == '__main__':
# Call the router function and pass the plugin call parameters to it.
# We use string slicing to trim the leading '?' from the plugin call paramstring
router(sys.argv[2][1:])