-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsc2casts.py
258 lines (221 loc) · 10.2 KB
/
sc2casts.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import os
import re
import sys
import urllib
import urllib2
import xbmc
import xbmcaddon
import xbmcgui
import xbmcplugin
class SC2Casts:
SC2CASTS_URL = 'http://sc2casts.com'
VIDEO_URL = 'http://www.youtube.com'
VIDEO_PLUGIN_URL = 'plugin://plugin.video.youtube'
USERAGENT = ('Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.8) '
'Gecko/20100722 Firefox/3.6.8')
__settings__ = xbmcaddon.Addon(id='plugin.video.sc2casts')
__language__ = __settings__.getLocalizedString
def getCastsURL(self, path):
return self.SC2CASTS_URL + path
def action(self, params):
get = params.get
if (get('action') == 'rootTop'):
self.rootTop()
if (get('action') == 'rootBrowse'):
self.rootBrowse()
if (get('action') == 'browseEvents'):
self.browseEvents(params)
if (get('action') == 'browseMatchups'):
self.browseMatchups()
if (get('action') == 'browseCasters'):
self.browseCasters(params)
if (get('action') == 'showTitles'
or get('action') == 'showTitlesTop'
or get('action') == 'showTitlesSearch'):
self.showTitles(params)
if (get('action') == 'showGames'):
self.showGames(params)
# Menu functions #
# display the root menu
def root(self):
self.addCategory(self.__language__(31000),
self.getCastsURL('/index.php'),
'showTitles')
self.addCategory(self.__language__(31001), '', 'rootTop')
self.addCategory(self.__language__(31002), '', 'rootBrowse')
self.addCategory(self.__language__(31003), '', 'showTitlesSearch')
# display the top casts menu
def rootTop(self):
self.addCategory(self.__language__(31004),
self.getCastsURL('/top/index.php?all'),
'showTitlesTop')
self.addCategory(self.__language__(31005),
self.getCastsURL('/top/index.php?month'),
'showTitlesTop')
self.addCategory(self.__language__(31006),
self.getCastsURL('/top/index.php?week'),
'showTitlesTop')
self.addCategory(self.__language__(31007),
self.getCastsURL('/top/index.php'),
'showTitlesTop')
# display the browse casts menu
def rootBrowse(self):
self.addCategory(self.__language__(31008),
self.getCastsURL('/browse/index.php'),
'browseEvents')
self.addCategory(self.__language__(31009), '', 'browseMatchups')
self.addCategory(self.__language__(31010),
self.getCastsURL('/browse/index.php'),
'browseCasters')
# display the browse events menu
def browseEvents(self, params = {}):
get = params.get
link = self.getRequest(get('url'))
event = re.compile('<a href="/event(.*?)">(.*?)</a>').findall(link)
for i in range(len(event)):
self.addCategory(event[i][1],
self.getCastsURL('/event'+event[i][0]),
'showTitles')
# display the browse casters menu
def browseMatchups(self):
self.addCategory('PvZ', self.getCastsURL('/matchups-PvZ'),
'showTitles')
self.addCategory('PvT', self.getCastsURL('/matchups-PvT'),
'showTitles')
self.addCategory('TvZ', self.getCastsURL('/matchups-TvZ'),
'showTitles')
self.addCategory('PvP', self.getCastsURL('/matchups-PvP'),
'showTitles')
self.addCategory('TvT', self.getCastsURL('/matchups-TvT'),
'showTitles')
self.addCategory('ZvZ', self.getCastsURL('/matchups-ZvZ'),
'showTitles')
# display the browse casters menu
def browseCasters(self, params = {}):
get = params.get
link = self.getRequest(get('url'))
caster = re.compile('<a href="/caster(.*?)">(.*?)</a>').findall(link)
for i in range(len(caster)):
self.addCategory(caster[i][1],
self.getCastsURL('/caster'+caster[i][0]),
'showTitles', len(caster))
# Add functions #
def addCategory(self, title, url, action, count = 0):
url=(sys.argv[0] + '?url=' + urllib.quote_plus(url) + '&title=' +
urllib.quote_plus(title) + '&action=' + urllib.quote_plus(action))
listitem=xbmcgui.ListItem(title, iconImage='DefaultFolder.png',
thumbnailImage='DefaultFolder.png')
listitem.setInfo(type='Video', infoLabels={ 'Title': title })
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url,
listitem=listitem, isFolder=True,
totalItems=count)
def addVideo(self, title, url):
# Check if URL is a 'fillUp' URL
if url != 'fillUp':
url = ('%s/?action=play_video&videoid=%s'
%(self.VIDEO_PLUGIN_URL, url))
liz=xbmcgui.ListItem(title, iconImage='DefaultVideo.png',
thumbnailImage='DefaultVideo.png')
liz.setInfo(type='Video', infoLabels={ 'Title': title })
liz.setProperty('IsPlayable','true')
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,
listitem=liz)
# Show functions #
def showTitles(self, params = {}):
get = params.get
url = get('url')
# Check if user want to search
if get('action') == 'showTitlesSearch':
keyboard = xbmc.Keyboard('')
keyboard.doModal()
url = self.getCastsURL('/?q=' + keyboard.getText())
link = self.getRequest(url)
# Get settings
boolMatchup = self.__settings__.getSetting('matchup')
boolNr_games = self.__settings__.getSetting('nr_games')
boolEvent = self.__settings__.getSetting('event')
boolRound = self.__settings__.getSetting('round')
boolCaster = self.__settings__.getSetting('caster')
# Get info to show
caster = re.compile('<a href="/.+?"><span class="caster_name">'
'(.*?)</span></a>').findall(link)
matchup = (re.compile('<span style="color:#cccccc">(.*?)</span>')
.findall(link))
roundname = (re.compile('<span class="round_name">(.*?)</span>')
.findall(link))
checkSource = (re.compile('<span class="source_name">(.*?)</span>')
.findall(link))
event = (re.compile('<span class="event_name".*?>(.*?)</span>')
.findall(link))
#Different source if URL is .../top
if get('action') == 'showTitlesTop':
title = (re.compile('<h3><a href="(.+?)"><b >(.+?)</b> vs '
'<b >(.+?)</b> \((.*?)\)</a></h3>')
.findall(link))
else:
title = re.compile('<h2><a href="(.+?)"><b >(.+?)</b> vs <b >'
'(.+?)</b> \((.*?)\)</a>').findall(link)
for i in range(len(event)):
if checkSource[i] != '@ YouTube':
pass
else:
url = ''
if boolMatchup == 'true':
url += matchup[i] + ' | '
url += title[i][1] + ' vs ' + title[i][2] + ' | '
if boolNr_games == 'true':
url += title[i][3] + ' | '
if boolEvent == 'true':
url += event[i] + ' | '
if boolRound == 'true':
url += roundname[i] + ' | '
if boolCaster == 'true':
url += 'cast by: ' + caster[i]
self.addCategory(url,title[i][0],'showGames')
def showGames(self, params = {}):
get = params.get
link = self.getRequest(self.getCastsURL(get('url')))
matchCount = (re.compile('<div id="g(.+?)"(.+?)</div></div>')
.findall(link))
if len(matchCount) > 0:
for i in range(len(matchCount)):
videoContent=re.compile('src="https://www.youtube.com/embed'
'/(.+?)"').findall(matchCount[i][1])
if len(videoContent) == 0:
self.addVideo('Game ' + str(i + 1), 'fillUp')
if len(videoContent) == 1:
self.addVideo('Game ' + str(i + 1), videoContent[0])
if len(videoContent) > 1:
for k in range(len(videoContent)):
self.addVideo('Game ' + str(i + 1) + ', part ' +
str(k + 1),
videoContent[k])
else:
videoContent=(re.compile('<param name="movie" '
'value="%s/v/(.+?)'
'\?.+?"></param>' % self.VIDEO_URL)
.findall(link))
if len(videoContent) > 1:
for n in range(len(videoContent)):
self.addVideo('Game 1, part '+ str(n+1), videoContent[n])
else:
self.addVideo('Game 1', videoContent[0])
# Data functions #
def getParams(self, paramList):
splitParams = paramList[paramList.find('?') + 1:].split('&')
paramsFinal = {}
for value in splitParams:
splitParams = value.split('=')
type = splitParams[0]
content = splitParams[1]
if type == 'url':
content = urllib.unquote_plus(content)
paramsFinal[type] = content
return paramsFinal
def getRequest(self, url):
req = urllib2.Request(url)
req.add_header('User-Agent', self.USERAGENT)
response = urllib2.urlopen(req)
link=response.read()
response.close()
return link