1
1
import json
2
2
import os
3
3
import requests
4
+ import re
4
5
5
6
from xbmcswift2 import Plugin
6
7
@@ -55,15 +56,13 @@ def login():
55
56
def debug_notify (msg ):
56
57
if setting_get ('debug' ):
57
58
plugin .notify (msg , None , 1000 , icon )
58
-
59
+ print ( msg )
59
60
60
61
def setting_get (key ):
61
62
if os .environ .get ('SETTINGS' ):
62
63
return json .loads (os .environ ['SETTINGS' ]).get (key )
63
64
return plugin .get_setting (key )
64
65
65
-
66
- #
67
66
def get_menu_items ():
68
67
return [
69
68
(plugin .url_for ('courses' ), 30001 ),
@@ -91,25 +90,22 @@ def index():
91
90
92
91
@plugin .route ('/course/<course_id>/play/<lecture_id>' , name = 'course_play' )
93
92
def play (course_id , lecture_id ):
94
- url = base_url + '/api-2.0/users/me/subscribed-courses/%s/lectures/%s' % (course_id , lecture_id )
95
- video = load_json (url ,
96
- params = 'fields%5Basset%5D=@min,download_urls,external_url,slide_urls&fields%5Bcourse%5D=id,is_paid,url&fields%5Blecture%5D=@default,view_html,course&page_config=ct_v4&tracking_tag=ctp_lecture' )
97
- print video
98
- files = video .get ('asset' , {}).get ('download_urls' , {}).get ('Video' , [])
99
- last_file = files .pop ()
100
-
101
- print last_file
102
- return {
103
- 'label' : last_file ['file' ],
104
- 'path' : last_file ['file' ],
105
- 'is_playable' : True ,
106
- }
93
+ ensure_login ()
94
+ url = my_courses_url + '/%s/lectures/%s' % (course_id , lecture_id )
95
+ video = load_json (url , params = 'fields%5Basset%5D=@min,stream_urls,file,label' )
96
+ asset = video .get ('asset' , {})
97
+ files = asset .get ('stream_urls' , {}).get ('Video' , [])
98
+ first_file = files [0 ]
99
+
100
+ print first_file
101
+ plugin .set_resolved_url (first_file ['file' ])
107
102
108
103
109
- @plugin .route ('/course/<course_id>' , name = 'course_details' )
110
- def show_course_details (course_id ):
104
+ @plugin .route ('/course/<course_id>/details/<page> ' , name = 'course_details' )
105
+ def show_course_details (course_id , page ):
111
106
ensure_login ()
112
- course = load_json ("%s/%s/public-curriculum-items" % (courses_url , course_id ))
107
+ url = my_courses_url + '/%s/lectures?page=%s' % (course_id , page )
108
+ course = load_json (url )
113
109
114
110
items = []
115
111
lectures = filter (lambda result : result ['_class' ] == 'lecture' , course ['results' ])
@@ -119,11 +115,24 @@ def show_course_details(course_id):
119
115
items .append ({
120
116
'label' : lecture ['title' ],
121
117
'path' : plugin .url_for ('course_play' , course_id = course_id , lecture_id = lecture ['id' ]),
122
- 'info' :{'label' :lecture ['title' ], 'title' :lecture ['title' ], 'plot' : lecture ['description' ], 'year' : lecture ['created' ], },
123
- # 'thumbnail': data.get('VTU').get('IUR'),
118
+ 'info' : {
119
+ 'label' : lecture ['title' ],
120
+ 'title' : lecture ['title' ],
121
+ 'plot' : lecture ['description' ],
122
+ 'year' : lecture ['created' ]
123
+ },
124
+ 'is_playable' : True ,
124
125
'info_type' : 'video' ,
125
126
})
126
127
128
+ if course ['next' ]:
129
+ next = course ['next' ]
130
+ pageNo = re .search (r'\d+' , next [::- 1 ]).group ()[::- 1 ]
131
+ items .append ({
132
+ 'label' : 'next' ,
133
+ 'path' : plugin .url_for ('course_details' , course_id = course_id , page = pageNo ),
134
+ })
135
+
127
136
return plugin .finish (items )
128
137
129
138
@@ -137,7 +146,7 @@ def show_courses():
137
146
for course in courses ['results' ]:
138
147
item = {
139
148
'label' : course ['title' ],
140
- 'path' : plugin .url_for ('course_details' , course_id = course ['id' ]),
149
+ 'path' : plugin .url_for ('course_details' , course_id = course ['id' ], page = '1' ),
141
150
'thumbnail' : course ['image_480x270' ],
142
151
'info_type' : 'video' ,
143
152
'properties' : {
0 commit comments