def listCourses(slug): username = plugin.get_setting('username') password = plugin.get_setting('password') if isSettingsBad(username, password): return [] classes = loadClasses(username, password) if slug not in classes: plugin.log.warn("%s not found in classes: %s", slug, [x["slug"] for x in classes]) return [] course = classes[slug] sessions = course['sessions'] if len(sessions) == 1: plugin.log.debug("Only one item found") return listCourseContents( courseShortName=get_session_short_name(sessions[0])) ret = [] for session in sessions: label = session.get('startDateString', 'Unknown') duration_string = session.get('durationString') if duration_string: label = "%s (%s)" % (label, duration_string) short_name = get_session_short_name(session) url = plugin.url_for('listCourseContents', courseShortName=short_name) ret.append({ 'label': label, 'path': url, 'icon': course['photoUrl'], 'thumbnail': course['photoUrl'], 'is_playable': False }) return ret
def index(): username = plugin.get_setting('username') password = plugin.get_setting('password') if isSettingsBad(username, password): plugin.open_settings() username = plugin.get_setting('username') password = plugin.get_setting('password') if isSettingsBad(username, password): return [] try: classes = loadClasses(username, password) except requests.HTTPError as ex: if ex.code != 401: raise ex plugin.notify(msg="Unable to login to Coursera") plugin.log.warn("Unable to login to Coursera") return [] plugin.log.debug(classes) plugin.add_sort_method(SortMethod.TITLE_IGNORE_THE) items = [] for slug, c in classes.iteritems(): url = plugin.url_for('listCourses', slug=slug) items.append({ 'label': c["name"], 'path': url, 'is_playable': False, 'label2': c.get("description", ""), 'icon': c['photoUrl'], 'thumbnail': c['photoUrl'], }) return items