-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddon.py
234 lines (200 loc) · 6.86 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
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
# -*- coding: utf-8 -*-
# Module: default
# Author: asciidisco
# Created on: 24.07.2017
# License: MIT https://goo.gl/WA1kby
"""Kodi plugin for Telekom Sport (https://telekomsport.de)"""
from sys import argv
from urlparse import parse_qsl
from resources.lib.Cache import Cache
from resources.lib.Constants import Constants
from resources.lib.ContentLoader import ContentLoader
from resources.lib.Dialogs import Dialogs
from resources.lib.ItemHelper import ItemHelper
from resources.lib.Session import Session
from resources.lib.Settings import Settings
from resources.lib.Utils import Utils
# setup plugin base stuff
try:
PLUGIN_HANDLE = int(argv[1])
KODI_BASE_URL = argv[0]
except ValueError:
PLUGIN_HANDLE = 1
KODI_BASE_URL = ''
# init plugin object structure
CONSTANTS = Constants()
CACHE = Cache()
UTILS = Utils(constants=CONSTANTS, kodi_base_url=KODI_BASE_URL)
DIALOGS = Dialogs(utils=UTILS)
ITEM_HELPER = ItemHelper(constants=CONSTANTS, utils=UTILS)
SETTINGS = Settings(utils=UTILS, dialogs=DIALOGS, constants=CONSTANTS)
SESSION = Session(constants=CONSTANTS, util=UTILS, settings=SETTINGS)
CONTENT_LOADER = ContentLoader(
session=SESSION,
item_helper=ITEM_HELPER,
cache=CACHE,
handle=PLUGIN_HANDLE)
def router(paramstring, user, password):
"""
Converts paramstrings into dicts & decides which
method should be called in order to display contents
:param user: Telekom account email address or user id
:type user: string
:param password: Telekom account password
:type password: string
:returns: bool -- Matching route found
"""
params = dict(parse_qsl(paramstring))
keys = params.keys()
# settings action routes
processed = __settings_action(params=params)
# check login
if __login_failed_action(user=user, password=password) is False:
return False
# plugin list & video routes
# play a video
processed = __play_action(params=params, processed=processed)
# show details of the match found (gamereport, relive, interviews...)
processed = __match_details_action(params=params, processed=processed)
# show main menue, selection of sport categories
processed = __sport_selection_action(keys=keys, processed=processed)
# show contents (lanes) scraped from the website
processed = __event_lane_action(params=params, processed=processed)
# show list of found matches/videos
processed = __categories_action(params=params, processed=processed)
# show contents scraped from the api (with website scraped id)
processed = __matches_list_action(params=params, processed=processed)
return processed
def __settings_action(params):
"""
Operates on actions from within the settings pane
Can logout the user, can switch users account
:param params: Route paramters
:type params: dict
:returns: bool -- Route matched
"""
if params.get('action') is not None:
if params.get('action') == 'logout':
SESSION.logout()
else:
SESSION.switch_account()
return True
return False
def __login_failed_action(user, password):
"""
Veryfies the users login & shows a notification if it failes
:param user: Telekom account email address or user id
:type user: string
:param password: Telekom account password
:type password: string
:returns: bool -- Login succeeded
"""
if SESSION.login(user, password) is False:
# show login failed dialog if login didn't succeed
DIALOGS.show_login_failed_notification()
return False
return True
def __sport_selection_action(keys, processed):
"""
Show sport selection
:param keys: Route paramters keys
:type keys: list
:param processed: Other route already matched
:type processed: bool
:returns: bool -- Route matched
"""
if len(keys) == 0 and processed is False:
CONTENT_LOADER.show_sport_selection()
return True
return False
def __match_details_action(params, processed):
"""
Show match details selection
:param params: Route paramters
:type params: dict
:param processed: Other route already matched
:type processed: bool
:returns: bool -- Route matched
"""
if params.get('target') is not None and processed is False:
CONTENT_LOADER.show_match_details(
params.get('target'),
params.get('lane'),
params.get('for'))
return True
return False
def __matches_list_action(params, processed):
"""
Show matches list selection
:param params: Route paramters
:type params: dict
:param processed: Other route already matched
:type processed: bool
:returns: bool -- Route matched
"""
if params.get('date') is not None and processed is False:
CONTENT_LOADER.show_matches_list(
params.get('date'),
params.get('for'))
return True
return False
def __event_lane_action(params, processed):
"""
Show event lane selection
:param params: Route paramters
:type params: dict
:param processed: Other route already matched
:type processed: bool
:returns: bool -- Route matched
"""
if params.get('lane') is not None and processed is False:
CONTENT_LOADER.show_event_lane(
sport=params.get('for'),
lane=params.get('lane'))
return True
return False
def __categories_action(params, processed):
"""
Show categories selection
:param params: Route paramters
:type params: dict
:param processed: Other route already matched
:type processed: bool
:returns: bool -- Route matched
"""
_for = params.get('for')
if _for is not None and processed is False:
CONTENT_LOADER.show_sport_categories(
sport=_for)
return True
return False
def __play_action(params, processed):
"""
Play an item
:param params: Route paramters
:type params: dict
:param processed: Other route already matched
:type processed: bool
:returns: bool -- Route matched
"""
video_id = params.get('video_id')
if video_id is not None and processed is False:
CONTENT_LOADER.play(video_id=video_id)
return True
return False
if __name__ == '__main__':
# Load addon data & start plugin
ADDON = UTILS.get_addon()
ADDON_DATA = UTILS.get_addon_data()
UTILS.log('Started (Version ' + ADDON_DATA.get('version') + ')')
# show user settings dialog if settings are not complete
# store the credentials if user added them
if SETTINGS.has_credentials():
USER, PASSWORD = SETTINGS.get_credentials()
else:
USER, PASSWORD = SETTINGS.set_credentials()
# 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(argv[2][1:], user=USER, password=PASSWORD)