/
addon.py
executable file
·58 lines (42 loc) · 1.36 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
from xbmcswift2 import Plugin
from resources.lib import tnb
plugin = Plugin()
@plugin.route('/')
def categories():
items = []
for category in tnb.get_categories():
title = category['title']
items.append({
'label': title,
'path': plugin.url_for('topics', category=title)})
return items
@plugin.route('/topics/<category>')
def topics(category):
items = []
for topic in tnb.get_topics(category):
title = topic['title']
items.append({
'label': title,
'path': plugin.url_for('lessons', lesson_id=topic['lesson_id']),
'thumbnail': topic.get('thumbnail')
})
return items
@plugin.route('/lessons/<lesson_id>')
def lessons(lesson_id):
items = []
for lesson in tnb.get_lessons(lesson_id):
items.append({
'label': lesson['title'],
'path': plugin.url_for(
'video', lesson_id=lesson['lesson_id'],
video_id=lesson['video_id']),
'is_playable': True})
return items
@plugin.route('/videos/<lesson_id>/<video_id>')
def video(lesson_id, video_id):
youtube_id = tnb.get_video(lesson_id, video_id)
return plugin.set_resolved_url(
'plugin://plugin.video.youtube?action=play_video&videoid={0}'.format(
youtube_id))
if __name__ == '__main__':
plugin.run()