Created
July 20, 2011 18:38
-
-
Save jbeluch/1095592 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from xbmcswift import Plugin, download_page | |
from BeautifulSoup import BeautifulSoup as BS, SoupStrainer as SS | |
from urlparse import urljoin | |
from resources.lib.getflashvideo import YouTube | |
import re | |
__plugin_name__ = 'Academic Earth' | |
__plugin_id__ = 'plugin.video.academicearth' | |
plugin = Plugin(__plugin_name__, __plugin_id__) | |
BASE_URL = 'http://academicearth.org' | |
def full_url(path): | |
return urljoin(BASE_URL, path) | |
# Default view | |
@plugin.route('/') | |
def show_lectures(): | |
COURSE_URL = 'http://academicearth.org/courses/introduction-to-computer-science-and-programming' | |
src = download_page(COURSE_URL) | |
html = BS(src) | |
parent_div = html.find('div', {'class': 'results-list'}) | |
lectures = parent_div.findAll('li') | |
items = [{ | |
'label': lecture.h4.a.string, | |
'url': plugin.url_for('watch_lecture', url=full_url(lecture.h4.a['href'])), | |
'thumbnail': full_url(lecture.find('img', {'class': 'thumb-144'})['src']), | |
'info': {'plot': lecture.p.string}, | |
'is_folder': False, | |
'is_playable': True, | |
} for lecture in lectures] | |
return plugin.add_items(items) | |
@plugin.route('/watch/<url>') | |
def watch_lecture(url): | |
src = download_page(url) | |
# Get video url here. | |
# Already have youtube code, so extract the youtube video ID and call our code | |
p = re.compile('flashVars.ytID = "(.+?)"') | |
m = p.search(src) | |
if not m: | |
raise Exception, 'Couldn\'t parse youtube ID!' | |
video_url = YouTube.get_flashvideo_url(videoid=m.group(1)) | |
print video_url | |
if __name__ == '__main__': | |
plugin.run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment