def display_lectures(self, url): """displays the lectures for a given course url""" html = urlread(url) #get the div which contains all of the <li> lecture tags div_tag = BS(html, parseOnlyThese=SS('div', {'class': 'results-list'})) #parse the name, url, desc, tn for each lecture dirs = [{'name': li.h4.a.text, 'htmlurl': self._urljoin(li.h4.a['href']), 'info': {'plot': li.p.text, 'title': li.h4.a.text}, 'tn':self._urljoin( li.find('img', {'class': 'thumb-144'})['src'])} for li in div_tag('li')] #for each dir, download the lecture's html page and parse the video url self.dp = DialogProgress(self.getString(30000), line1=self.getString(30101), num_steps=(len(dirs))) urls = [d['htmlurl'] for d in dirs] responses = async_urlread(urls, self.dp) [d.update({'url': self._get_video_url(response)}) for d, response in zip(dirs, responses)] #filter out lectures that don't have urls, currently a fix for a chem #course which contains a bad link to a lecture dirs = filter(lambda d: d['url'] != None, dirs) self.dp.update(100) self.dp.close() self.add_videos(dirs)
def display_courses(self, url): """Takes a topic url and displays all courses""" html = urlread(url) courses, lectures = self._get_courses_lectures(html) #add listings to UI, courses first, lectures at the bottom. self.add_dirs(courses, end=False) self.add_videos(lectures)
def display_genres(self, url): src = urlread(url) #fix terrible html src = src.replace('</font color>', '</font>') src = src.replace(r'<ol class=\"latestnews \">', '<ol class="latestnews">') div_tag = BS(src, parseOnlyThese=SS('div', {'id': 'rightcol'})) dirs = [{'name': a.span.string.replace('&', '&'), 'url': self._urljoin(a['href']), 'mode': '1'} for a in div_tag.find('div', {'class': 'moduletable'})('a')] print dirs
def display_subjects(self, url): """Takes a url and displays subjects.""" html = urlread(url) div_tags = BS(html, parseOnlyThese=SS('div', {'class': 'institution-list'})) #Build the list of subjects. Sometimes there is more than one div_tag, #so loop through each div_tag, and then for each div_tag, loop through #all the <a> tags and parse the subject information. dirs = [{'name': a.text, 'url': self._urljoin(a['href']), 'mode': '1'} for div in div_tags for a in div('a')] #Filter out the paid courses subjects dirs = [d for d in dirs if d['name'] not in IGNORE_LIST] self.add_dirs(dirs)
def display_topics(self, url): """Takes a subject url and displays a list of all topics on the page""" html = urlread(url) #get the div which contains all of the topic <a> tags div_topics = BS(html, parseOnlyThese=SS('div', {'class': 'results-side'})) #create the list of dirs by parsing all the a tags in the div dirs = [{'name': a.text, 'url': self._urljoin(a['href']), 'mode': '2'} for a in div_topics('a')] #filter out paid courses and the 'All' listing, since we build our own dirs = [d for d in dirs if d['name'].startswith('Online') == False and 'Courses for Credit' not in d['name'] and d['name'].startswith('All') == False] #make the first choice on the list = 'View All' dirs.insert(0, {'name': self.getString(30100), 'url': url, 'mode': '4'}) self.add_dirs(dirs)
def display_allresults(self, url): """displays all results for a given url, used on a subject page t lis all video results without having to drill down into each category""" #dp = self.xbmcgui.DialogProgress() html = urlread(url) #get the div which contains all of the topic <a> tags div_topics = BS(html, parseOnlyThese=SS('div', {'class': 'results-side'})) #create a list of urls for all topics topic_urls = [self._urljoin(a['href']) for a in div_topics('a') if a.text.startswith('Online') == False and 'Credit' not in a.text and not a.text.startswith('All')] self.dp = DialogProgress(self.getString(30000), line1=self.getString(30102), num_steps=(2 * len(topic_urls))) topic_htmls = async_urlread(topic_urls, self.dp) courses, lectures = self._get_courses_lectures(topic_htmls) self.dp.update(100) self.dp.close() courses = sorted(courses, key=lambda c: c['name']) lectures = sorted(lectures, key=lambda l: l['name']) self.add_dirs(courses, end=False) self.add_videos(lectures)