def addItem(self, title, mode, url=None, img='', args={}, video_info={}, isFolder=True, total_items=0):
        # Create action url
        args['mode'] = mode;
        if url:
            args['url'] = url
        if img:
            img = resizeImage(img)
            args['icon'] = img
        args = [k + '=' + urllib.quote_plus(v.encode('ascii', 'ignore')) for k, v in args.iteritems()]
        action_url = sys.argv[0] + '?' + "&".join(args)

        li = xbmcgui.ListItem(label=title, iconImage=img, thumbnailImage=img)
        video_info = dict((k, v) for k, v in video_info.iteritems() if k in ['date', 'plot'])
        if video_info:
            li.setInfo('video', video_info)
        if 'duration' in video_info:
            # To set with second granularity must do this rather than via setInfo
            li.addStreamInfo('video', { 'duration' : video_info['duration'] })
        if not isFolder:
            li.setProperty("IsPlayable", "true")  # let xbmc know this can be played, unlike a folder.
            context_menu = menu_util.create_context_menu(getLS=plugin.getLS)
            li.addContextMenuItems(context_menu, replaceItems=True)
        else:
            li.addContextMenuItems([], replaceItems=True)
        xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=action_url, listitem=li, isFolder=isFolder, totalItems=total_items)
 def getTalks(self):
     talkContainer = SoupStrainer(attrs = {'class':re.compile('box clearfix')})
     for talk in BeautifulSoup(self.html, parseOnlyThese = talkContainer):
         title = talk.h4.a.string
         link = URLTED+talk.dt.a['href']
         pic = resizeImage(talk.find('img', attrs = {'src':re.compile('.+?\.jpg')})['src'])
         yield {'url':link, 'Title':title, 'Thumb':pic}
Example #3
0
    def addItem(self, title, mode, url=None, img='', args={}, video_info={}, isFolder=True, total_items=0):
        # Create action url
        args['mode'] = mode;
        if url:
            args['url'] = url
        if img:
            img = resizeImage(img)
            args['icon'] = img
        args = [k + '=' + urllib.quote_plus(v.encode('ascii', 'ignore')) for k, v in args.iteritems()]
        action_url = sys.argv[0] + '?' + "&".join(args)

        li = xbmcgui.ListItem(label=title, iconImage=img, thumbnailImage=img)
        video_info = dict((k, v) for k, v in video_info.iteritems() if k in ['date', 'plot'])
        if video_info:
            li.setInfo('video', video_info)
        if 'duration' in video_info:
            # To set with second granularity must do this rather than via setInfo
            li.addStreamInfo('video', { 'duration' : video_info['duration'] })
        if not isFolder:
            li.setProperty("IsPlayable", "true")  # let xbmc know this can be played, unlike a folder.
            context_menu = menu_util.create_context_menu(getLS=plugin.getLS)
            li.addContextMenuItems(context_menu, replaceItems=True)
        else:
            li.addContextMenuItems([], replaceItems=True)
        xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=action_url, listitem=li, isFolder=isFolder, totalItems=total_items)
 def getTalks(self, url):
     html = self.get_HTML(url)
     talkContainer = SoupStrainer(attrs={'class':re.compile('box clearfix')})
     for talk in BeautifulSoup(html, parseOnlyThese=talkContainer):
         title = talk.h4.a.string
         link = URLTED + talk.dt.a['href']
         pic = resizeImage(talk.find('img', attrs={'src':re.compile('.+?\.jpg')})['src'])
         yield title, link, pic
 def getTalks(self):
     talkContainer = SoupStrainer(
         attrs={'class': re.compile('box clearfix')})
     for talk in BeautifulSoup(self.html, parseOnlyThese=talkContainer):
         title = talk.h4.a.string
         link = URLTED + talk.dt.a['href']
         pic = resizeImage(
             talk.find('img', attrs={'src':
                                     re.compile('.+?\.jpg')})['src'])
         yield {'url': link, 'Title': title, 'Thumb': pic}
 def getTalks(self):
     # themes loaded with a json call. Why are they not more consistant?
     from simplejson import loads
     # search HTML for the link to tedtalk's "api".  It is easier to use regex here than BS.
     jsonUrl = URLTED+re.findall('DataSource\("(.+?)"', self.html)[0]
     # make a dict from the json formatted string from above url
     talksMarkup = loads(self.get_HTML(jsonUrl))
     # parse through said dict for all the metadata
     for markup in talksMarkup['resultSet']['result']:
         talk = BeautifulSoup(markup['markup'])
         link = URLTED+talk.dt.a['href']
         title = cleanHTML(talk.dt.a['title'])
         pic = resizeImage(talk.find('img', attrs = {'src':re.compile('.+?\.jpg')})['src'])
         yield {'url':link, 'Title':title, 'Thumb':pic}
 def getTalks(self):
     # themes loaded with a json call. Why are they not more consistant?
     from simplejson import loads
     # search HTML for the link to tedtalk's "api".  It is easier to use regex here than BS.
     jsonUrl = URLTED + re.findall('DataSource\("(.+?)"', self.html)[0]
     # make a dict from the json formatted string from above url
     talksMarkup = loads(self.get_HTML(jsonUrl))
     # parse through said dict for all the metadata
     for markup in talksMarkup['resultSet']['result']:
         talk = BeautifulSoup(markup['markup'])
         link = URLTED + talk.dt.a['href']
         title = cleanHTML(talk.dt.a['title'])
         pic = resizeImage(
             talk.find('img', attrs={'src':
                                     re.compile('.+?\.jpg')})['src'])
         yield {'url': link, 'Title': title, 'Thumb': pic}
    def getNewTalks(self, url = None):
        """
        Returns 2-tuples, first value is whether this is a folder, second is attributes dict
        """
        if url == None:
            url = 'http://www.ted.com/talks/list/page/'
        html = self.getHTML(url)

        # Forward/backwards        
        navItems = getNavItems(html)
        if navItems['next']:
            yield True, {'mode':'newTalks', 'Title': self.getLS(30020), 'url':navItems['next']}
        if navItems['previous']:
            yield True, {'mode':'newTalks', 'Title': self.getLS(30021), 'url':navItems['previous']}
        
        talkContainers = SoupStrainer(attrs = {'class':re.compile('talkMedallion')})
        for talk in BeautifulSoup(html, parseOnlyThese = talkContainers):
            link = URLTED+talk.dt.a['href']
            title = cleanHTML(talk.dt.a['title'])
            pic = resizeImage(talk.find('img', attrs = {'src':re.compile('.+?\.jpg')})['src'])
            yield False, {'mode':'playVideo', 'url':link, 'Title':title, 'Thumb':pic}
    def getNewTalks(self, url=None):
        """
        Returns 2-tuples, first value is whether this is a folder, second is attributes dict
        """
        if url == None:
            url = 'http://www.ted.com/talks/list/page/'
        html = self.getHTML(url)

        # Forward/backwards
        navItems = getNavItems(html)
        if navItems['next']:
            yield True, {
                'mode': 'newTalks',
                'Title': self.getLS(30020),
                'url': navItems['next']
            }
        if navItems['previous']:
            yield True, {
                'mode': 'newTalks',
                'Title': self.getLS(30021),
                'url': navItems['previous']
            }

        talkContainers = SoupStrainer(
            attrs={'class': re.compile('talkMedallion')})
        for talk in BeautifulSoup(html, parseOnlyThese=talkContainers):
            link = URLTED + talk.dt.a['href']
            title = cleanHTML(talk.dt.a['title'])
            pic = resizeImage(
                talk.find('img', attrs={'src': re.compile('.+?\.jpg')})['src'])
            yield False, {
                'mode': 'playVideo',
                'url': link,
                'Title': title,
                'Thumb': pic
            }