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
|
# -*- coding: cp1252 -*-
import urllib, urllib2, re, xbmcplugin, xbmcgui, json
import xbmcaddon
import sys
from StringIO import StringIO
import gzip
# Set default encoding to 'UTF-8' instead of 'ascii'
reload(sys)
sys.setdefaultencoding("UTF8")
addon = xbmcaddon.Addon('plugin.video.kla.tv')
__language__ = addon.getLocalizedString
__icon__ = addon.getAddonInfo('icon')
__fanart__ = addon.getAddonInfo('fanart')
lang_setting = max([int(addon.getSetting('LanguageID') or 0) or 0, 0])
if lang_setting >= 30951:
lang_setting -= 30951
exp_lang_codes = ['de', 'en', 'fr', 'nl', 'it', 'pl']
payload_index = {
"de": 1,
"en": 2,
"fr": 3,
"nl": 4,
"it": 5,
"pl": 6
}
if lang_setting == 0:
lang_id = addon.getLocalizedString(id=30950)
else:
lang_id = exp_lang_codes[lang_setting-1]
payload_id = payload_index.get(lang_id, 2)
base_headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0 SeaMonkey/2.46",
"Accept-Encoding": "gzip"
}
page_headers = base_headers.copy()
page_headers.update({
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
})
api_headers = base_headers.copy()
api_headers.update({
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=utf-8"
})
def decode_response(response):
if response.info().get('Content-Encoding') == "gzip":
buff = StringIO(response.read())
f = gzip.GzipFile(fileobj=buff)
return f.read()
else:
return response.read()
def INDEX(url):
req = urllib2.Request(url, headers=api_headers)
post_args = {"mode": "action",
"data":
{"type": "loadingNextVideos",
"offset": 0,
"count": 60,
"category": "",
"sendtyp": "",
"langid": str(payload_id)
}
}
data = json.dumps(post_args)
content = decode_response(urllib2.urlopen(req, data=data))
video_index = json.loads(content)
data_digest = video_index.get('data', [])
for video in data_digest:
title = video.get('title', '')
image = 'https://www.kla.tv/{}'.format(video.get('img', ''))
url = "https://www.kla.tv/{}".format(video.get('longlink', '')).replace('lang=de', 'lang={}'.format(lang_id))
if url == 'https://www.kla.tv/':
continue
add_dir(title.encode('utf8'), url.encode('utf8'), 2, image)
def VIDEOLINKS(url, name):
req = urllib2.Request(url, headers=page_headers)
response = urllib2.urlopen(req)
link = decode_response(response).replace('\n', '').replace('\t', ' ')
while ' ' in link:
link = link.replace(' ', ' ')
response.close()
compiled_regex = re.compile('"src": "(.+?)", "label": "(.+?)"')
value_tuples = compiled_regex.findall(link)
for entry in value_tuples:
if "blockid" in entry[0].lower() or "label:" in entry[0].lower():
continue
add_link('{0} ({1})'.format(name, entry[1]), 'https://www.kla.tv/{}'.format(entry[0]), __icon__)
def get_params():
param = []
paramstring = sys.argv[2]
if len(paramstring) >= 2:
params = sys.argv[2]
cleanedparams = params.replace('?', '')
if (params[len(params) - 1] == '/'):
params = params[0:len(params) - 2]
pairsofparams = cleanedparams.split('&')
param = {}
for i in range(len(pairsofparams)):
splitparams = pairsofparams[i].split('=')
if (len(splitparams)) == 2:
param[splitparams[0]] = splitparams[1]
return param
def add_link(name, url, icon_image):
liz = xbmcgui.ListItem(name)
liz.setArt({"thumb": icon_image})
liz.setInfo(type="Video", infoLabels={"title": name, "mediatype": "video"})
ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=liz)
return ok
def add_dir(name, url, mode, icon_image):
u = sys.argv[0] + "?url=" + urllib.quote_plus(url) + "&mode=" + str(mode) + "&name=" + urllib.quote_plus(name)
liz = xbmcgui.ListItem(name)
liz.setInfo(type="Video", infoLabels={"title": name, "mediatype": "video"})
liz.setArt({"thumb": icon_image})
ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=True)
return ok
params = get_params()
url = None
name = None
mode = None
try:
url = urllib.unquote_plus(params["url"])
except:
pass
try:
name = urllib.unquote_plus(params["name"])
except:
pass
try:
mode = int(params["mode"])
except:
pass
if mode == None or url == None or len(url) < 1:
INDEX('https://www.kla.tv/en')
elif mode == 1:
INDEX(url)
elif mode == 2:
VIDEOLINKS(url, name)
else:
INDEX('https://www.kla.tv/en')
xbmcplugin.endOfDirectory(int(sys.argv[1]))
|