-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathaddon.py
More file actions
executable file
·300 lines (257 loc) · 12.7 KB
/
Copy pathaddon.py
File metadata and controls
executable file
·300 lines (257 loc) · 12.7 KB
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# coding: utf-8
from __future__ import (absolute_import, division,
print_function, unicode_literals)
import os
import sys
import inputstreamhelper
try:
from urllib.parse import parse_qsl
except ImportError:
from urlparse import parse_qsl
import xbmc
import xbmcgui
import xbmcaddon
import xbmcplugin
from resources.lib.errlib.menu import Menu
import resources.lib.errlib.helpers as helpers
from resources.lib.errlib.category import Category
from resources.lib.errlib.content import Content
from resources.lib.errlib.search import Search
from resources.lib.errlib.constants import (
ERR_API_BASEURL,
ERR_API_VERSION
)
# import web_pdb
# Get the plugin url in plugin:// notation.
PATH = sys.argv[0]
# Get the plugin _handle as an integer number.
_handle = int(sys.argv[1])
FANART = 'https://s.err.ee/photo/crop/2020/03/30/765343had90t16.png'
__settings__ = xbmcaddon.Addon(id='plugin.video.jupiter.err.ee')
ADDON = xbmcaddon.Addon()
KODI_VERSION_MAJOR = int(xbmc.getInfoLabel('System.BuildVersion').split('.')[0])
PROTOCOL = 'mpd'
DRM = 'com.widevine.alpha'
MIME_TYPE = 'application/dash+xml'
is_helper = inputstreamhelper.Helper(PROTOCOL, drm=DRM)
def list_category():
items = list()
menu = Menu()
menuitems = menu.get_menu_items()
search_icon = os.path.join(ADDON.getAddonInfo('path'), 'resources', 'search.png')
item = xbmcgui.ListItem(ADDON.getLocalizedString(30012))
item.setArt({'fanart': search_icon, 'poster': search_icon, 'icon': search_icon})
items.append((PATH + '?action=search', item, True))
for menuitem in menuitems:
if menuitem['kids_count'] > 0:
item = xbmcgui.ListItem(
'[COLOR {}]{}[/COLOR]'.format(helpers.get_colour(__settings__.getSetting('colourCategory')),
menuitem['name']))
item.setArt({'fanart': FANART, 'poster': FANART, 'icon': FANART})
items.append((PATH + '?action=category&category={}'.format(menuitem['link'].replace('/', '')), item, False))
for sub_item in menuitem['kids']:
if sub_item['kids_count'] < 2: # Audio submenu has Järjejutud as kid
item = xbmcgui.ListItem(' {}'.format(sub_item['name']))
item.setArt({'fanart': FANART})
items.append(
(PATH + '?action=category&category={}'.format(sub_item['link'].replace('/', '')), item, True))
# Inject extra items
item = xbmcgui.ListItem(' Saated A-Ü')
item.setArt({'fanart': FANART})
items.append((PATH + '?action=listing&category={}'.format(menuitem['name'].lower()), item, True))
# make menu
xbmcplugin.addDirectoryItems(_handle, items)
xbmcplugin.endOfDirectory(_handle)
def get_search_string():
kb = xbmc.Keyboard('', ADDON.getLocalizedString(30013))
kb.doModal()
if not kb.isConfirmed():
return
query = kb.getText()
return query
def do_search():
search = Search(search_phrase=get_search_string())
items = list()
available_types = ["video", "audio"]
for index, content_type in enumerate(available_types):
item = xbmcgui.ListItem(
'[COLOR {}]{} {}: {}[/COLOR]'.format(helpers.get_colour(__settings__.getSetting('colourCategory')),
content_type.capitalize(),
ADDON.getLocalizedString(30014),
search.get_response()[index]))
item.setArt({'fanart': FANART})
items.append((PATH + '', item, False))
for result in search.get_results(content_type=content_type):
item = xbmcgui.ListItem(result['heading'])
item.setArt({'fanart': FANART})
items.append((PATH + '?action=section§ion={}&sub=false'.format(result['id']), item, True))
xbmcplugin.addDirectoryItems(_handle, items)
xbmcplugin.endOfDirectory(_handle)
def get_category(categorykey):
# web_pdb.set_trace()
categories = Category(categorykey)
items = list()
for category in categories.get_categories():
item = xbmcgui.ListItem(
"[COLOR {}]{}[/COLOR]".format(helpers.get_colour(__settings__.getSetting('colourCategory')), category))
items.append((PATH, item))
for category_item in categories.get_gategory_items(category):
(item_id, heading, image_url, plot) = (
category_item[0], category_item[1], category_item[2], category_item[3])
info_labels = {'title': heading, 'plot': plot}
item = xbmcgui.ListItem(heading)
if 'true' in __settings__.getSetting('enableImages'):
item.setArt({'fanart': image_url, 'poster': image_url, 'icon': image_url})
item.setInfo(type="Video", infoLabels=info_labels)
items.append((PATH + '?action=section§ion={}&sub=false'.format(item_id), item, True))
xbmcplugin.addDirectoryItems(_handle, items)
xbmcplugin.endOfDirectory(_handle)
def get_section(section, sub=''):
# web_pdb.set_trace()
data = Content(section)
items = list()
# xbmc.log('DATA: %s' % data, xbmc.LOGINFO)
content_type = data.get_page_type()
season_type = data.get_seasonlist_type()
if content_type in 'series' or sub == 'marine':
for season in data.get_season():
if data.get_item_id(season) is not None:
# Season
item = xbmcgui.ListItem("[COLOR {}]Hooaeg: {}[/COLOR]".format(
helpers.get_colour(__settings__.getSetting('colourSeason')),
str(data.get_item_id(season)))
)
items.append(
(PATH + '?action=section§ion={}&sub=marine'.format(data.get_primaryid(season)),
item, True)
)
if season_type == 'monthly':
for month in data.get_items(season):
item = xbmcgui.ListItem(
" [COLOR {}]{}[/COLOR]".format(
helpers.get_colour(__settings__.getSetting('colourCategory')),
data.get_item_name(month))
)
# item.setArt({'fanart': fanart, 'poster': fanart, 'icon': fanart})
items.append(
(PATH + '?action=section§ion={}&sub=marine'.format(
data.get_item_primaryid(month)), item, True)
)
if data.get_item_contents(month) is not None:
for day in data.get_item_contents(month):
title = ''
if data.get_item_episode(day) > 0:
title = data.get_item_heading(day) + " " + str(data.get_item_episode(day))
else:
title = data.get_item_heading(day)
# no plot, use on-air date // TODO find something else instead
plot = helpers.convert_timestamp(data.get_item_schedule_start(day))
info_labels = {'title': title, 'plot': plot}
fanart = data.get_item_photo(day)
item = xbmcgui.ListItem(" {}".format(title))
if 'true' in __settings__.getSetting('enableImages'):
item.setArt({'fanart': fanart, 'poster': fanart, 'icon': fanart})
item.setInfo(type="Video", infoLabels=info_labels)
items.append((PATH + '?action=section§ion={}&sub=false'.format(
data.get_item_id(day)), item, True))
elif season_type in ('seasonal', 'shortSeriesList') and data.get_item_contents(
season) is not None:
# xbmc.log(' Season: %s' % str(season_type), xbmc.LOGINFO)
for episood in data.get_item_contents(season):
subheading = data.get_item_subheading(episood)
heading = data.get_item_heading(episood)
fanart = data.get_item_photo(episood)
if subheading is not None and len(subheading) > 2:
title = subheading
elif heading is not None:
title = heading
else:
title = str(data.get_item_episode(episood))
item = xbmcgui.ListItem(title)
if 'true' in __settings__.getSetting('enableImages'):
item.setArt({'fanart': fanart, 'poster': fanart, 'icon': fanart})
items.append((PATH + '?action=section§ion={}&sub=false'.format(episood['id']), item, True))
elif content_type in ('movie', 'episode'):
sub = []
languages = []
languages.extend((
helpers.get_subtitle_language(__settings__.getSetting('primaryLanguage')),
helpers.get_subtitle_language(__settings__.getSetting('secondaryLanguage'))
))
title = data.get_heading()
video = data.get_hls()
plot = helpers.strip_tags(data.get_body())
drm = data.get_drm()
# we can play DRM content
if drm:
token = data.get_token()
license_server = data.get_license_server()
video = data.get_dash()
info_labels = {'title': title, 'plot': plot}
for language in languages:
if data.get_subtitles(language) is not None:
sub.append(data.get_subtitles(language))
# web_pdb.set_trace()
fanart = data.get_photo()
item = xbmcgui.ListItem(title, path=video)
if 'true' in __settings__.getSetting('enableImages'):
item.setArt({'fanart': fanart, 'poster': fanart, 'icon': fanart})
item.setInfo(type="Video", infoLabels=info_labels)
helper = inputstreamhelper.Helper('hls')
if 'true' in __settings__.getSetting('isa') and helper.check_inputstream():
if KODI_VERSION_MAJOR >= 19:
item.setProperty('inputstream','inputstream.adaptive')
else:
item.setProperty('inputstreamaddon','inputstream.adaptive')
item.setProperty('inputstream.adaptive.manifest_type', 'hls')
item.setProperty('IsPlayable', 'True')
item.setProperty('isFolder', 'False')
if drm:
if is_helper.check_inputstream():
item.setContentLookup(False)
item.setMimeType(MIME_TYPE)
if KODI_VERSION_MAJOR >= 19:
item.setProperty('inputstream', is_helper.inputstream_addon)
else:
item.setProperty('inputstreamaddon', is_helper.inputstream_addon)
item.setProperty('inputstream.adaptive.manifest_type', PROTOCOL)
item.setProperty('inputstream.adaptive.license_type', DRM)
item.setProperty('inputstream.adaptive.license_key',
license_server + '|X-AxDRM-Message=' + token + '|R{SSM}|')
item.setSubtitles(sub)
items.append((video, item))
xbmcplugin.addDirectoryItems(_handle, items)
xbmcplugin.endOfDirectory(_handle)
def get_all_shows(type):
url = '{}{}/series/getSeriesData?type={}'.format(ERR_API_BASEURL, ERR_API_VERSION, type)
# xbmc.log('url: %s' % url, xbmc.LOGNOTICE)
items = list()
data = helpers.download_url(url).json()
for show in data['data']['items']:
item = xbmcgui.ListItem("{}".format(show['heading']))
if 'photoUrlOriginal' in show['photos'][0]:
fanart = show['photos'][0]['photoUrlOriginal']
if 'true' in __settings__.getSetting('enableImages'):
item.setArt({'fanart': fanart, 'poster': fanart, 'icon': fanart})
items.append((PATH + '?action=section§ion={}&sub=false'.format(show['id']), item, True))
xbmcplugin.addDirectoryItems(_handle, items)
xbmcplugin.endOfDirectory(_handle)
def router(paramstring):
params = dict(parse_qsl(paramstring))
if params:
if params['action'] == 'category':
get_category(params['category'])
elif params['action'] == 'section':
get_section(params['section'], params['sub'])
elif params['action'] == 'listing':
get_all_shows(params['category'])
elif params['action'] == 'search':
do_search()
else:
raise ValueError('Invalid paramstring: {0}!'.format(paramstring))
else:
list_category()
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:])