The branch, eden-pre has been updated
       via  fdb3deb40988c2a033ead1dadb54cfdc85998432 (commit)
      from  fb86fb2ca2253c036c1d22710b4617be4b5b2430 (commit)

- Log -----------------------------------------------------------------
http://xbmc.git.sourceforge.net/git/gitweb.cgi?p=xbmc/plugins;a=commit;h=fdb3deb40988c2a033ead1dadb54cfdc85998432

commit fdb3deb40988c2a033ead1dadb54cfdc85998432
Author: spiff <[email protected]>
Date:   Fri Jan 13 21:11:59 2012 +0100

    plugin.video.khanacademy] updated to version 1.4

diff --git a/plugin.video.khanacademy/README.md 
b/plugin.video.khanacademy/README.md
index 8b27458..d474b1b 100644
--- a/plugin.video.khanacademy/README.md
+++ b/plugin.video.khanacademy/README.md
@@ -1,6 +1,6 @@
 Khan Academey for XBMC
 =======================
-version 0.3
+version 1.4
 
 ### Summary
 
diff --git a/plugin.video.khanacademy/addon.py 
b/plugin.video.khanacademy/addon.py
index 7238283..4bf91ee 100755
--- a/plugin.video.khanacademy/addon.py
+++ b/plugin.video.khanacademy/addon.py
@@ -1,74 +1,104 @@
 #!/usr/bin/env python
-# Copyright 2011 Jonathan Beluch.  
-# 
-# This program is free software: you can redistribute it and/or modify 
-# it under the terms of the GNU General Public License as published by 
-# the Free Software Foundation, either version 3 of the License, or 
-# (at your option) any later version. 
-# 
-# This program is distributed in the hope that it will be useful, 
-# but WITHOUT ANY WARRANTY; without even the implied warranty of 
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
-# GNU General Public License for more details. 
-# 
-# You should have received a copy of the GNU General Public License 
-# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
-from xbmcswift import Plugin, download_page
-from BeautifulSoup import BeautifulSoup as BS
+# Copyright 2011 Jonathan Beluch.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+import os
+import time
+try:
+    import json
+except ImportError:
+    import simplejson as json
 from urlparse import urljoin
+from xbmcswift import Plugin, download_page, xbmc
+from BeautifulSoup import BeautifulSoup as BS
+from resources.lib.khan import KhanData, download_playlists_json
+from resources.lib.cache import get_cached_data, put_cached_data
 
 __plugin_name__ = 'Khan Academy'
 __plugin_id__ = 'plugin.video.khanacademy'
-
 plugin = Plugin(__plugin_name__, __plugin_id__, __file__)
-
 BASE_URL = 'http://www.khanacademy.org'
+
+
+# Ugly temporary hack until xbmcswift is fixed. Need to ensure the basedirs
+# for the cache already exist before we attempt to use it. Also, in pyton 2.4
+# we don't get the lovely os.makedirs :(
+def make_cache_dirs():
+    '''Make plugin_id and .cache dirs for the current plugin.'''
+    def make_if_not_exist(path):
+        if not os.path.exists(path):
+            os.mkdir(path)
+    cache_root = xbmc.translatePath('special://profile/addon_data')
+    make_if_not_exist(os.path.join(cache_root, __plugin_id__))
+    make_if_not_exist(os.path.join(cache_root, __plugin_id__, '.cache'))
+make_cache_dirs()
+
+
 def full_url(path):
+    '''Returns the full url for the given path. Uses BASE_URL.'''
     return urljoin(BASE_URL, path)
 
+
 def htmlify(url):
+    '''Returns a BeautifulSoup object for a give url's response.'''
     return BS(download_page(url))
 
-# Default View
[email protected]('/')
-def show_subjects():
-    '''Displays subjects from the homepage.'''
-    html = htmlify(BASE_URL)
-    container = html.find('div', {'id': 'library-content-main'})
-    subjects = container.findAll('div', {'data-role': 'page'})
-
-    items = [{
-        'label': s.h2.string,
-        'url': plugin.url_for('show_videos', subject_id=s['id']),
-    } for s in subjects]
-    
-    return plugin.add_items(items)
 
[email protected]('/videos/<subject_id>/')
-def show_videos(subject_id):
-    '''Displays lessons for a give subject id.'''
-    html = htmlify(BASE_URL)
-    subject = html.find('div', {'id': subject_id})
-    videos = subject.findAll('a', {'class': 'vl'})
+def get_khan_data():
+    '''Returns a KhanData instance containg playlist data.
+
+    Behind the scenes, it checks for a local cached copy first. If the cached
+    copy's lifetime has not expired it will use the local copy. Otherwise, it
+    will fetch fresh data from the API and cache it locally.
+    '''
+    json_fn = plugin.cache_fn('playlists.json')
+    timestamp_fn = plugin.cache_fn('playlists.json.ts')
+
+    _json = get_cached_data(json_fn, timestamp_fn)
+    if _json is None:
+        _json = download_playlists_json()
+        put_cached_data(json.dumps(_json), json_fn, timestamp_fn)
+
+    return KhanData(_json)
+
 
-    items =  [{
-        'label': a.span.string,
-        'url': plugin.url_for('play_video', url=full_url(a['href'])),
-        'is_playable': True,
-        'is_folder': False,
-    } for a in videos]
+KHAN_DATA = get_khan_data()
 
+
[email protected]('/')
[email protected]('/<category>/', name='show_category')
+def main_menu(category='_root'):
+    '''This view displays Categories or Playlists.
+
+    This method does a lookup based on the passed category/playlist name to get
+    the members. The "root" or base category is name "_root"
+    '''
+    items = [item.to_listitem(plugin)
+             for item in KHAN_DATA.get_items(category)]
     return plugin.add_items(items)
 
[email protected]('/play/<url>/')
-def play_video(url):
-    '''Resolves a lesson page's url to a playable video url.'''
+
[email protected]('/play/<video_slug>/')
+def play_video(video_slug):
+    '''Resolves a video page's url to a playable video url.'''
     # Videos are both in .mp4 format and youtube. For simplicity's sake just
     # use mp4 for now.
+    url = 'http://www.khanacademy.org/video/%s' % video_slug
     html = htmlify(url)
     a = html.find('a', {'title': 'Download this lesson'})
     plugin.set_resolved_url(a['href'])
 
 
-if __name__ == '__main__': 
+if __name__ == '__main__':
     plugin.run()
diff --git a/plugin.video.khanacademy/addon.xml 
b/plugin.video.khanacademy/addon.xml
index ec52503..3a42a8d 100644
--- a/plugin.video.khanacademy/addon.xml
+++ b/plugin.video.khanacademy/addon.xml
@@ -1,9 +1,10 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<addon id="plugin.video.khanacademy" name="Khan Academy" version="0.3" 
provider-name="Jonathan Beluch (jbel)">
+<addon id="plugin.video.khanacademy" name="Khan Academy" version="1.4" 
provider-name="Jonathan Beluch (jbel)">
   <requires>
     <import addon="xbmc.python" version="2.0"/>
     <import addon="script.module.beautifulsoup" version="3.0.8"/>
     <import addon="script.module.xbmcswift" version="0.2.0"/>
+    <import addon="script.module.simplejson" version="2.0.10"/>
   </requires>
   <extension point="xbmc.python.pluginsource" library="addon.py">
     <provides>video</provides>
diff --git a/plugin.video.khanacademy/changelog.txt 
b/plugin.video.khanacademy/changelog.txt
index 9658deb..685ed6b 100644
--- a/plugin.video.khanacademy/changelog.txt
+++ b/plugin.video.khanacademy/changelog.txt
@@ -1,3 +1,8 @@
+Version 1.4 
+* Bumped Eden version to 1.4 to differentiate from Dharma.
+* The website was changed to use a javacript API. Updated addon to parse this
+  API instead of the static HTML.
+
 Version 0.3
 * Updated required versions of xbmcswift and python for Eden.
 

-----------------------------------------------------------------------

Summary of changes:
 plugin.video.khanacademy/README.md              |    2 +-
 plugin.video.khanacademy/addon.py               |  126 ++++++++++++++---------
 plugin.video.khanacademy/addon.xml              |    3 +-
 plugin.video.khanacademy/changelog.txt          |    5 +
 plugin.video.khanacademy/resources/lib/cache.py |   46 ++++++++
 plugin.video.khanacademy/resources/lib/khan.py  |  114 ++++++++++++++++++++
 6 files changed, 246 insertions(+), 50 deletions(-)
 create mode 100644 plugin.video.khanacademy/resources/lib/cache.py
 create mode 100644 plugin.video.khanacademy/resources/lib/khan.py


hooks/post-receive
-- 
Plugins

------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons

Reply via email to