The branch, eden has been updated
       via  5a3cbe93bad147fef3668ddb00c2ba5f4ea34468 (commit)
      from  18fd739fc1beae457b5d85dfac52ef7426b2eab9 (commit)

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

commit 5a3cbe93bad147fef3668ddb00c2ba5f4ea34468
Author: Martijn Kaijser <[email protected]>
Date:   Wed Sep 5 18:51:02 2012 +0200

    [plugin.video.academicearth] -v1.3

diff --git a/plugin.video.academicearth/addon.py 
b/plugin.video.academicearth/addon.py
index 0a5766c..cf4104d 100755
--- a/plugin.video.academicearth/addon.py
+++ b/plugin.video.academicearth/addon.py
@@ -13,279 +13,77 @@
 #
 # 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, SoupStrainer as SS
-from urlparse import urljoin
-from resources.lib.videohosts import resolve
-import re
+from operator import itemgetter
+from xbmcswift2 import Plugin
+from resources.lib.academicearth.api import (AcademicEarth, Subject, Course,
+                                             Lecture)
 
-from resources.lib.favorites import favorites
-from xbmcswift import xbmcgui
+PLUGIN_NAME = 'Academic Earth'
+PLUGIN_ID = 'plugin.video.academicearth'
+plugin = Plugin(PLUGIN_NAME, PLUGIN_ID, __file__)
 
-__plugin_name__ = 'New Academic Earth'
-__plugin_id__ = 'plugin.video.academicearth'
-
-plugin = Plugin(__plugin_name__, __plugin_id__, filepath=__file__)
-plugin.register_module(favorites, '/favorites')
-
-BASE_URL = 'http://academicearth.org'
-def full_url(path):
-    return urljoin(BASE_URL, path)
-
-def htmlify(url):
-    return BS(download_page(url), convertEntities=BS.HTML_ENTITIES)
-
-def filter_free(items):
-    return filter(lambda item: not item['label'].startswith('Online'), items)
 
 @plugin.route('/')
 def show_index():
     items = [
-        {'label': plugin.get_string(30200), 'url': 
plugin.url_for('show_subjects')},
-        {'label': plugin.get_string(30201), 'url': 
plugin.url_for('show_universities')},
-        {'label': plugin.get_string(30202), 'url': 
plugin.url_for('show_instructors')},
-        {'label': plugin.get_string(30203), 'url': 
plugin.url_for('show_top_instructors')},
-        {'label': plugin.get_string(30204), 'url': 
plugin.url_for('show_playlists')},
-        {'label': plugin.get_string(30205), 'url': 
plugin.url_for('favorites.show_favorites')},
+        {'label': plugin.get_string(30200),
+         'path': plugin.url_for('show_subjects')},
     ]
-    return plugin.add_items(items)
-
[email protected]('/subjects/', url=full_url('subjects'))
-def show_subjects(url):
-    html = htmlify(url)
-    subjects = html.findAll('a', {'class': 'subj-links'})
-
-    items = [{
-        'label': subject.div.string.strip(),
-        'url': plugin.url_for('show_topics', url=full_url(subject['href'])),
-    } for subject in subjects]
-
-    # Filter out non-free subjects
-    items = filter(lambda item: item['label'] != 'Courses for Credit', items)
-
-    return plugin.add_items(items)
-
[email protected]('/universities/', url=full_url('universities'))
-def show_universities(url):
-    html = htmlify(url)
-    universities = html.findAll('a', {'class': 'subj-links'})
-
-    items = [{
-        'label': item.div.string.strip(),
-        'url': plugin.url_for('show_topics', url=full_url(item['href'])),
-    } for item in universities]
-
-    return plugin.add_items(items)
-
[email protected]('/instructors/', page='1')
[email protected]('/instructors/<page>/', name='show_instructors_page')
-def show_instructors(page):
-    def get_pagination(html):
-        items = []
-        previous = html.find('span', {'class': 'tab-nav-arrow 
tab-nav-arrow-l'})
-        if int(page) > 1:
-            items.append({
-                'label': '< Previous',
-                'url': plugin.url_for('show_instructors_page', 
page=str(int(page)-1)),
-            })
-
-        next = html.find('span', {'class': 'tab-nav-arrow tab-nav-arrow-r'})
-        if next:
-            items.append({
-                'label': 'Next >',
-                'url': plugin.url_for('show_instructors_page', 
page=str(int(page)+1)),
-            })
-        return items
-
-    url = full_url('speakers/page:%s' % page)
-    html = htmlify(url)
-    speakers = html.findAll('div', {'class': 'blue-hover'})
-
-    items = [{
-        'label': item.div.string,
-        'url': plugin.url_for('show_instructor_courses', 
url=full_url(item.a['href'])),
-    } for item in speakers]
-
-    # Add pagination
-    return plugin.add_items(get_pagination(html) + items)
-
[email protected]('/topinstructors/', url=BASE_URL)
-def show_top_instructors(url):
-    html = htmlify(url)
-    menu = html.find('ul', {'id': 'categories-accordion'})
-    speakers = menu.findAll('a', {'class': 'accordion-item', 'href': lambda h: 
'/speakers/' in h})
+    return items
 
-    items = [{
-        'label': item.string,
-        'url': plugin.url_for('show_instructor_courses', 
url=full_url(item['href'])),
-    } for item in speakers]
-
-    return plugin.add_items(items)
 
[email protected]('/playlists/', url=full_url('playlists'))
-def show_playlists(url):
-    html = htmlify(url)
-    playlists = html.find('ol', {'class': 'playlist-list'}).findAll('li', 
recursive=False)
[email protected]('/subjects/')
+def show_subjects():
+    api = AcademicEarth()
+    subjects = api.get_subjects()
 
     items = [{
-        'label': item.h4.findAll('a')[-1].string,
-        'url': plugin.url_for('show_lectures', url=full_url(item.a['href'])),
-        'thumbnail': full_url(item.find('img', {'width': '144'})['src']),
-    } for item in playlists]
-
-    return plugin.add_items(items)
-
+        'label': subject.name,
+        'path': plugin.url_for('show_subject_info', url=subject.url),
+    } for subject in subjects]
 
+    sorted_items = sorted(items, key=lambda item: item['label'])
+    return sorted_items
 
[email protected]('/instructors/courses/<url>/')
-def show_instructor_courses(url):
-    html = htmlify(url)
-    parent_div = html.find('div', {'class': 'results-list'})
-    courses_lectures = parent_div.findAll('li')
 
-    courses = filter(lambda item: '/courses/' in item.h4.a['href'], 
courses_lectures)
-    lectures = filter(lambda item: '/lectures/' in item.h4.a['href'], 
courses_lectures)
[email protected]('/subjects/<url>/')
+def show_subject_info(url):
+    subject = Subject.from_url(url)
 
-    course_items = [{
-        'label': item.h4.a.string,
-        'url': plugin.url_for('show_lectures', 
url=full_url(item.h4.a['href'])),
-        'thumbnail': full_url(item.find('img', {'width': '144'})['src']),
-    } for item in courses]
+    courses = [{
+        'label': course.name,
+        'path': plugin.url_for('show_course_info', url=course.url),
+    } for course in subject.courses]
 
-    lecture_items = [{
-        'label': '%s: %s' % (plugin.get_string(30206), item.h4.a.string),
-        'url': plugin.url_for('watch_lecture', 
url=full_url(item.h4.a['href'])),
-        'thumbnail': full_url(item.find('img', {'class': 'thumb-144'})['src']),
-        'is_folder': False,
+    lectures = [{
+        'label': 'Lecture: %s' % lecture.name,
+        'path': plugin.url_for('play_lecture', url=lecture.url),
         'is_playable': True,
-    } for item in lectures]
-
-    return plugin.add_items(course_items + lecture_items)
-
[email protected]('/topics/<url>/')
-def show_topics(url):
-    html = htmlify(url)
-    topics = html.findAll('a', {'class': 'tab-details-link '})
-
-    items = [{
-        'label': topic.string,
-        'url': plugin.url_for('show_courses', url=full_url(topic['href'])),
-    } for topic in topics]
+    } for lecture in subject.lectures]
 
-    # Filter out non free topics
-    items = filter_free(items)
+    by_label = itemgetter('label')
+    items = sorted(courses, key=by_label) + sorted(lectures, key=by_label)
+    return items
 
-    # If we only have one item, just redirect to the show_topics page,
-    # there's no need to display a single item in the list
-    if len(items) == 1:
-        return plugin.redirect(items[0]['url'])
-
-    return plugin.add_items(items)
 
 @plugin.route('/courses/<url>/')
[email protected]('/courses/<url>/<page>/', name='show_courses_page')
-def show_courses(url, page='1'):
-    def get_pagination(html):
-        items = []
-        if int(page) > 1:
-            items.append({
-                'label': '< Previous',
-                'url': plugin.url_for('show_courses_page', url=url, 
page=str(int(page)-1)),
-            })
-
-        next = html.find('span', {'class': 'tab-nav-arrow tab-nav-arrow-r'})
-        if next:
-            items.append({
-                'label': 'Next >',
-                'url': plugin.url_for('show_courses_page', url=url, 
page=str(int(page)+1)),
-            })
-        return items
-
-    html = htmlify('%s/page:%s' % (url, page))
-    courses_lectures = html.findAll('div', {'class': 'thumb'})
-
-    # Some of the results can be a standalone lecture, not a link to a course
-    # page. We need to display these separately.
-    courses = filter(lambda item: '/courses/' in item.a['href'], 
courses_lectures)
-    lectures = filter(lambda item: '/lectures/' in item.a['href'], 
courses_lectures)
-
-    course_items = [{
-        'label': item.parent.find('a', {'class': 
'editors-picks-title'}).string,
-        'url': plugin.url_for('show_lectures', url=full_url(item.a['href'])),
-        'thumbnail': full_url(item.find('img', {'class': 'thumb-144'})['src']),
-    } for item in courses]
-
-    lecture_items = [{
-        'label': '%s: %s' % (plugin.get_string(30206),
-            item.parent.find('a', {'class': 'editors-picks-title'}).string),
-        'url': plugin.url_for('watch_lecture', url=full_url(item.a['href'])),
-        'thumbnail': full_url(item.find('img', {'class': 'thumb-144'})['src']),
-        'is_folder': False,
+def show_course_info(url):
+    course = Course.from_url(url)
+    lectures = [{
+        'label': 'Lecture: %s' % lecture.name,
+        'path': plugin.url_for('play_lecture', url=lecture.url),
         'is_playable': True,
-    } for item in lectures]
+    } for lecture in course.lectures]
 
-    pagination_items = get_pagination(html)
-    return plugin.add_items(pagination_items + course_items + lecture_items)
+    return sorted(lectures, key=itemgetter('label'))
 
[email protected]('/lectures/<url>/')
-def show_lectures(url):
-    def get_plot(item):
-        if item.p:
-            return item.p.string
-        return ''
-
-    def get_add_to_favorites_url(item):
-        path = item.find('a', {'class': 'add'})
-        if path:
-            return (plugin.get_string(30300), # Add to favorites
-                    'XBMC.RunPlugin(%s)' % favorites.url_for(
-                        'favorites.add_lecture',
-                        url=full_url(path)['href']
-            ))
-        return
-
-    html = htmlify(url)
-    parent_div = html.find('div', {'class': 'results-list'})
-    lectures = parent_div.findAll('li')
-
-    items = [{
-        'label': item.h4.a.string,
-        'url': plugin.url_for('watch_lecture', 
url=full_url(item.h4.a['href'])),
-        'thumbnail': full_url(item.find('img', {'class': 'thumb-144'})['src']),
-        'is_folder': False,
-        'is_playable': True,
-        # Call to get_plot is because we are using this view to parse a course 
page
-        # and also parse a playlist page. The playlist pages don't contain a 
lecture
-        # description.
-        'info': {'plot': get_plot(item)},
-        'context_menu': [
-            (plugin.get_string(30300), # Add to favorites
-             'XBMC.RunPlugin(%s)' % favorites.url_for(
-                'favorites.add_lecture',
-                url=full_url(item.find('a', {'class': 'add'})['href'])
-            )),
-        ],
 
-    } for item in lectures]
-
-    return plugin.add_items(items)
-
[email protected]('/watch/<url>/')
-def watch_lecture(url):
-    src = download_page(url)
-
-    # First attempt to look for easy flv urls
-    pattern = re.compile(r'flashVars.flvURL = "(.+?)"')
-    m = pattern.search(src)
-    if m:
-        resolved_url = m.group(1)
-    else:
-        resolved_url = resolve(src)
-    if resolved_url:
-        return plugin.set_resolved_url(resolved_url)
-
-    xbmcgui.Dialog().ok(plugin.get_string(30000), plugin.get_string(30400))
-    raise Exception, 'No video url found. Please alert plugin author.'
[email protected]('/lectures/<url>/')
+def play_lecture(url):
+    lecture = Lecture.from_url(url)
+    url = 'plugin://plugin.video.youtube/?action=play_video&videoid=%s' % 
lecture.youtube_id
+    plugin.log.info('Playing url: %s' % url)
+    plugin.set_resolved_url(url)
 
 
 if __name__ == '__main__':
diff --git a/plugin.video.academicearth/addon.xml 
b/plugin.video.academicearth/addon.xml
index ec4a72f..fa194fb 100644
--- a/plugin.video.academicearth/addon.xml
+++ b/plugin.video.academicearth/addon.xml
@@ -3,8 +3,8 @@
   <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="plugin.video.youtube" version="2.9.1"/>
+    <import addon="script.module.xbmcswift2" version="1.1.1"/>
+    <import addon="plugin.video.youtube" version="3.1.0"/>
   </requires>
   <extension point="xbmc.python.pluginsource" library="addon.py">
     <provides>video</provides>

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

Summary of changes:
 plugin.video.academicearth/addon.py                |  294 +++-----------------
 plugin.video.academicearth/addon.xml               |    4 +-
 .../resources/lib/academicearth}/__init__.py       |    0
 .../resources/lib/academicearth/api.py             |  141 ++++++++++
 .../resources/lib/academicearth/scraper.py         |  151 ++++++++++
 .../resources/lib/getflashvideo.py                 |  151 ----------
 6 files changed, 340 insertions(+), 401 deletions(-)
 copy {plugin.audio.radio_de/resources => 
plugin.video.academicearth/resources/lib/academicearth}/__init__.py (100%)
 create mode 100644 
plugin.video.academicearth/resources/lib/academicearth/api.py
 create mode 100644 
plugin.video.academicearth/resources/lib/academicearth/scraper.py
 delete mode 100644 plugin.video.academicearth/resources/lib/getflashvideo.py


hooks/post-receive
-- 
Plugins

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons

Reply via email to