/
default.py
332 lines (265 loc) · 10.7 KB
/
default.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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# -*- coding: utf-8 -*-
'''
XBMC LaTeleLibre.fr video add-on.
Copyright (C) 2014 José Antonio Montes (jamontes)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
This is the first trial of LaTeleLibre.fr video add-on for XBMC.
This add-on gets the videos from LaTeleLibre.fr web site and shows
them properly ordered.
This plugin depends on the lutil and plugin library functions.
'''
from resources.lib.plugin import Plugin
import resources.lib.ltl_api as api
plugin_id = 'plugin.video.latelelibre_fr'
localized_strings = {
'Next page' : 30010,
'Type not suported' : 30011,
'Video not located' : 30012,
'Previous page' : 30013,
'All videos' : 30014,
'Search' : 30015,
}
p = Plugin(plugin_id)
settings = p.get_plugin_settings()
translation = p.get_plugin_translation()
debug_flag = settings.getSetting("debug") == "true"
p.set_debug_mode(debug_flag)
api.set_debug(debug_flag, p.log)
st_release = settings.getSetting('version')
current_release = settings.getAddonInfo('version')
update_settings = False
# This is to make it sure that settings are correctly setup on every addon
# update if required or on first time of update settings either.
if not st_release:
p.log("ltl Warning: First run of update settings.")
settings.openSettings()
settings.setSetting('version', current_release)
elif st_release != current_release:
p.log("ltl Warning: updated release. Check for update settings.")
if update_settings:
settings.openSettings()
settings.setSetting('version', current_release)
# Gets the quality for videos from settings
try:
quality = int(settings.getSetting('quality'))
except:
settings.setSetting('quality', '2') # Sets the default quality to 480
quality = 2 # Default value is bandwith conservative.
p.log('ltl video quality setup to "%s"' % ('1080', '720', '480')[quality])
api.set_video_quality(quality)
def get_located_string(string_name):
"""This function returns the localized string if it is available."""
return translation(localized_strings.get(string_name)).encode('utf-8') or string_name if string_name in localized_strings else string_name
# Entry point
def run():
"""This function is the entry point to the add-on.
It gets the add-on parameters and call the 'action' function.
"""
p.log("ltl.run")
# Get the params
params = p.get_plugin_parms()
if params.get("action") is None:
create_index(params)
else:
action = params.get("action")
exec action+"(params)"
# Main menu
def create_index(params):
"""This function generates the main add-on menu, based on the website sections."""
p.log("ltl.create_index "+repr(params))
menu_index = api.get_create_index()
main_menu = [ {
'thumbnail' : '',
'info': {
'title' : item.get('title'),
'genre' : item.get('title'),
},
'path' : p.get_plugin_path(
action = item.get('action'),
ctype = item.get('ctype'),
themes = item.get('themes'),
sorting = item.get('sorting'),
title = item.get('title'),
) if item.get('action') == 'menu_grille' else p.get_plugin_path(
action = item.get('action'),
menus = item.get('menus', 'no'),
),
'IsPlayable': False,
} for item in menu_index]
p.add_items(main_menu)
def menu_sec(params):
"""This function generates the menu entries for the Emissions, Chroniques, and Series sections."""
p.log("ltl.menu_sec "+repr(params))
root_url = 'http://latelelibre.fr'
genre = params.get('genre')
menus = params.get('menus')
action = 'video_sec'
menu_sec = [ {
'info': {
'title' : imenu.split('¿')[1],
'genre' : genre,
},
'path' : p.get_plugin_path(
url = root_url + imenu.split('¿')[0],
action = action,
),
'IsPlayable' : False,
} for imenu in menus.split('¡') ]
p.add_items(menu_sec)
def video_sec(params):
"""This function list de videos for the Emissions, Chroniques, Series, and Search sections."""
p.log("ltl.video_sec "+repr(params))
video_list = api.get_video_sec(params.get('url'))
video_items = [ {
'thumbnail' : video_entry.get('thumbnail') or '',
'info': {
'title' : video_entry.get('title'),
'plot' : video_entry.get('plot') or '',
'studio': video_entry.get('credits') or '',
'genre' : video_entry.get('genre') or '',
'year' : video_entry.get('year') or '',
'rating': video_entry.get('rating') or '',
},
'path' : p.get_plugin_path(
url = video_entry['url'],
action = 'play_video' if video_entry['IsPlayable'] else 'video_sec',
),
'IsPlayable': video_entry['IsPlayable'],
} for video_entry in video_list]
p.add_items(video_items)
def video_docs(params):
"""This function list the Documentary videos showed by the main page website."""
p.log("ltl.video_docs "+repr(params))
video_list = api.get_video_docs()
action = 'play_video'
video_items = [ {
'thumbnail' : video_entry.get('thumbnail') or '',
'info': {
'title' : video_entry.get('title'),
'plot' : video_entry.get('plot') or '',
'studio' : video_entry.get('credits') or '',
'genre' : video_entry.get('genre') or '',
'year' : video_entry.get('year') or '',
'rating' : video_entry.get('rating') or '',
},
'path' : p.get_plugin_path(
url = video_entry['url'],
action = action,
),
'IsPlayable' : video_entry['IsPlayable'],
} for video_entry in video_list]
p.add_items(video_items)
def menu_grille(params):
"""This function generates the Genres level menu for the 'All the Videos' and 'Reportages' sections."""
p.log("ltl.menu_grille "+repr(params))
ctype = params.get('ctype')
themes = params.get('themes')
sorting = params.get('sorting')
genre = params.get('title')
action = 'grille_sort'
themes_items = [ {
'info': {
'title' : itheme.split('¿')[1],
'genre' : genre,
},
'path' : p.get_plugin_path(
ctype = ctype,
sorting = sorting,
action = action,
theme = itheme.split('¿')[0],
title = genre,
),
'IsPlayable': False,
} for itheme in themes.split('¡') ]
p.add_items(themes_items)
def grille_sort(params):
"""This function generates the 'Sorted by' level menu for the 'All the Videos' and 'Reportages' sections."""
p.log("ltl.grille_sort "+repr(params))
ctype = params.get('ctype')
theme = params.get('theme')
sorting = params.get('sorting')
genre = params.get('title')
action = 'grille_list'
sorting_items = [ {
'info': {
'title' : isorting.split('¿')[1],
'genre' : genre,
},
'path' : p.get_plugin_path(
ctype = ctype,
sorting = isorting.split('¿')[0],
action = action,
theme = theme,
genre = genre,
),
'IsPlayable': False,
} for isorting in sorting.split('¡') ]
p.add_items(sorting_items)
def grille_list(params):
"""This function list the videos for the 'All the Videos' and 'Reportages' sections."""
p.log("ltl.grille_list "+repr(params))
ctype = params.get('ctype')
theme = params.get('theme')
sorting = params.get('sorting')
exclude = params.get('exclude', '')
params_grille = {
'type' : ctype,
'theme' : theme,
'sorting' : sorting,
'exclude' : exclude,
'limit' : '15',
}
videos = api.get_video_items(params=params_grille, localized=get_located_string)
reset_cache = 'yes' if params.get('reset_cache') == 'yes' or videos['reset_cache'] else 'no'
video_list = [ {
'thumbnail' : video_entry.get('thumbnail') or '',
'info': {
'title' : video_entry.get('title'),
'plot' : video_entry.get('plot') or '',
'studio' : video_entry.get('credits') or '',
'genre' : video_entry.get('genre') or '',
'year' : video_entry.get('year') or '',
'rating' : video_entry.get('rating') or '',
},
'path' : p.get_plugin_path(
url = video_entry['url'],
action = 'play_video',
) if video_entry['IsPlayable'] else p.get_plugin_path(
ctype = video_entry['type'],
theme = video_entry['theme'],
exclude = video_entry['exclude'],
sorting = video_entry['sorting'],
limit = video_entry['limit'],
action = 'grille_list',
reset_cache = reset_cache,
),
'IsPlayable' : video_entry['IsPlayable'],
} for video_entry in videos['video_list']]
p.add_items(video_list, reset_cache == 'yes')
def search_videos(params):
"""This function gets the URL for search the videos and list them if something is found on the website archives."""
p.log("ltl.search_video "+repr(params))
search_string = p.get_keyboard_text(get_located_string('Search'))
if search_string:
params['url'] = api.get_search_url(search_string)
p.log("ltl.search Value of search url: %s" % params['url'])
return video_sec(params)
def play_video(params):
"""This function plays the videos if the hosted site of the video is supported."""
p.log("ltl.play_video "+repr(params))
url = api.get_playable_url(params.get("url"))
if url:
return p.play_resolved_url(url)
else:
p.showWarning(get_located_string('Type not suported'))
# Runs the add-on from here.
run()