Esempio n. 1
0
    def searchTitle(self, title, pagenumber, pagelen):
        '''Key word video search of the BBC iPlayer web site
        return an array of matching item elements
        return
        '''
        # Save the origninal URL
        orgUrl = self.bbciplayer_config.find('searchURLS').xpath(".//href")[0].text

        try:
            searchVar = u'/?q=%s&page=%s' % (urllib.quote(title.encode("utf-8")), pagenumber)
        except UnicodeDecodeError:
            searchVar = u'/?q=%s&page=%s' % (urllib.quote(title), pagenumber)

        url = self.bbciplayer_config.find('searchURLS').xpath(".//href")[0].text+searchVar

        if self.config['debug_enabled']:
            print url
            print

        self.bbciplayer_config.find('searchURLS').xpath(".//href")[0].text = url

        # Perform a search
        try:
            resultTree = self.common.getUrlData(self.bbciplayer_config.find('searchURLS'), pageFilter=self.bbciplayer_config.find('searchURLS').xpath(".//pageFilter")[0].text)
        except Exception, errormsg:
            # Restore the origninal URL
            self.bbciplayer_config.find('searchURLS').xpath(".//href")[0].text = orgUrl
            raise BBCUrlDownloadError(self.error_messages['BBCUrlDownloadError'] % (errormsg))
                etree.SubElement(url, "filter").text = u"//atm:entry"
                etree.SubElement(url, "parserType").text = u'xml'
                rssData.append(url)

        if self.config['debug_enabled']:
            print "rssData:"
            sys.stdout.write(
                etree.tostring(rssData, encoding='UTF-8', pretty_print=True))
            print

        # Get the RSS Feed data
        if rssData.find('url') != None:
            try:
                resultTree = self.common.getUrlData(rssData)
            except Exception, errormsg:
                raise BBCUrlDownloadError(
                    self.error_messages['BBCUrlDownloadError'] % (errormsg))
            if self.config['debug_enabled']:
                print "resultTree:"
                sys.stdout.write(
                    etree.tostring(resultTree,
                                   encoding='UTF-8',
                                   pretty_print=True))
                print

            # Set the display type for the link (Fullscreen, Web page, Game Console)
            if self.userPrefs.find('displayURL') != None:
                urlType = self.userPrefs.find('displayURL').text
            else:
                urlType = u'fullscreen'

            # Process each directory of the user preferences that have an enabled rss feed