-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdouyutv.py
executable file
·101 lines (78 loc) · 3.46 KB
/
douyutv.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
# -*- coding: utf-8 -*-
# douyutv.py
import sys
import DouyuAPI
import xbmcplugin
import xbmcgui
from urllib.parse import urlencode, unquote, parse_qs
import urllib3
urllib3.disable_warnings()
base_url = sys.argv[0]
handle = int(sys.argv[1])
args = parse_qs(sys.argv[2][1:])
api = DouyuAPI.DouyuAPI()
action = args.get('action', None)
def build_url(query):
return base_url + '?' + urlencode(query)
def onControl(self, control):
if control == self.list:
item = self.list.getSelectedItem()
item.setLabel('Casino Royale')
if action is None:
url = build_url({"action": "live", "cate_id": "0"})
listitem = xbmcgui.ListItem(" => 正在直播 <=")
xbmcplugin.addDirectoryItem(handle, url, listitem, isFolder=True)
data = api.loadCategory()
for game in data:
url = build_url({"action": "category", "short_name": game["short_name"], "cate_id":game["cate_id"]})
listitem = xbmcgui.ListItem(label=game["cate_name"], path=url)
xbmcplugin.addDirectoryItem(handle, url, listitem, isFolder=True)
xbmcplugin.endOfDirectory(handle)
exit(0)
if action[0] == "live":
cateId = args.get('cate_id', "0")
tagId = args.get('tag_id', "0")
offset = args.get('offset', "0")
o = int(offset[0], 0)
limit = 12
if cateId[0] != "0":
data = api.loadCateRoom(cateId[0], o)
elif tagId[0] != "0":
data = api.loadTagRoom(tagId[0], o)
else:
data = api.loadRoom(o)
data2 = sorted(data, key=lambda k: k['online'], reverse=True)
for game in data2:
url = build_url({"action": "play", "room_id": game["room_id"], "room_name": game["room_name"].encode('utf-8'), "nickname": game["nickname"].encode('utf-8')})
listitem = xbmcgui.ListItem(label = unquote(game["game_name"]) + " - " + unquote(game["nickname"]) + " - " + unquote(game["room_name"]), path=url)
listitem.setArt({ "poster": game["pic_name"].rstrip("/dy1"), "thumb": game["pic_name"], })
xbmcplugin.addDirectoryItem(handle, url, listitem)
url = build_url({"action": "live", "cate_id": cateId[0], "tag_id": tagId[0],"offset": int(o + limit)})
listitem = xbmcgui.ListItem(label="下一页", path=url)
xbmcplugin.addDirectoryItem(handle, url, listitem, isFolder=True)
xbmcplugin.endOfDirectory(handle)
exit(0)
if action[0] == "category":
cateId = args.get('cate_id', "0")
shortName = args.get('short_name', "0")
url = build_url({"action": "live", "cate_id": cateId[0]})
listitem = xbmcgui.ListItem(" => 正在直播 <=")
xbmcplugin.addDirectoryItem(handle, url, listitem, isFolder=True)
data = api.loadSubCategory(shortName[0])
for game in data:
url = build_url({"action": "live", "tag_id": game["tag_id"]})
listitem = xbmcgui.ListItem(label=game["tag_name"], path=url)
listitem.setArt({ "poster": game["pic_name"].rstrip("/dy1"), "thumb": game["pic_name"], })
xbmcplugin.addDirectoryItem(handle, url, listitem, isFolder=True)
xbmcplugin.endOfDirectory(handle)
exit(0)
if action[0] == "play":
roomId = args.get('room_id', "0")[0]
roomName = args.get('room_name', "unknown")[0]
nickname = args.get('nickname', "unknown")[0]
# videoUrl = realurl.get_real_url(roomId)
data = api.loadSource(roomId)
item = xbmcgui.ListItem("Test")
item.setProperty("PlayPath", data["source"])
item.setInfo("video", {'title': nickname + " - " + roomName, 'writer': nickname})
player = xbmc.Player().play(data["source"] + "11223344", item)