Esempio n. 1
0
 def __findRTMP(self, data, pageUrl, lItem):
     rtmp = findRTMP(pageUrl, data)
     if rtmp:
         item = CListItem()
         item['title'] = 'RTMP* - ' + rtmp[1]
         item['type'] = 'video'
         item['url'] = rtmp[0] + ' playPath=' + rtmp[1] + ' swfUrl=' + rtmp[2] +' swfVfy=1 live=true pageUrl=' + pageUrl
         item.merge(lItem)
         return item
     
     return None
Esempio n. 2
0
    def __findRTMP(self, data, pageUrl, lItem):
        rtmp = findRTMP(pageUrl, data)
        if rtmp:
            item = CListItem()
            item["title"] = "RTMP* - " + rtmp[1]
            item["type"] = "video"
            item["url"] = (
                rtmp[0] + " playPath=" + rtmp[1] + " swfUrl=" + rtmp[2] + " swfVfy=1 live=true pageUrl=" + pageUrl
            )
            item.merge(lItem)
            return item

        return None
Esempio n. 3
0
 def convertToCListItem(self):
     item = CListItem()
     item.setInfo('title', self.title)
     item.setInfo('type', 'command')
     item.setInfo('icon', self.icon)
     item.setInfo('url', self.url)
     return item
Esempio n. 4
0
    def _parseVirtualFolder(self, path):
        fullpath = self._getFullPath(path)
        data = fu.getFileContent(fullpath)
        data = data.replace('\r\n', '\n').split('\n')
        items = []
        for m in data:
            if m and m[0] != '#':
                index = m.find('=')
                if index != -1:
                    key = lower(m[:index]).strip()
                    value = m[index + 1:]

                    index = value.find('|')
                    if value[:index] == 'sports.devil.locale':
                        value = common.translate(int(value[index + 1:]))
                    elif value[:index] == 'sports.devil.image':
                        value = os.path.join(common.Paths.imgDir,
                                             value[index + 1:])

                    if key == 'title':
                        tmp = CListItem()
                        tmp['title'] = value
                    elif key == 'url':
                        tmp['url'] = value
                        items.append(tmp)
                        tmp = None
                    elif tmp != None:
                        tmp[key] = value
        return items
 def convertToCListItem(self):
     item = CListItem()
     item.setInfo('title', self.title)
     item.setInfo('type', 'command')
     item.setInfo('icon', self.icon)
     item.setInfo('url', self.url)
     return item
Esempio n. 6
0
 def convertToCListItem(self):
     item = CListItem()
     item.setInfo("title", self.title)
     item.setInfo("type", "command")
     item.setInfo("icon", self.icon)
     item.setInfo("url", self.url)
     return item
Esempio n. 7
0
    def __parseHtml(self, url, data, rules, skills, definedIn, lItem):

        #common.log('_parseHtml called')
        items = []

        for item_rule in rules:
            # common.log('rule: ' + item_rule.infos)

            if not hasattr(item_rule, 'precheck') or (item_rule.precheck
                                                      in data):

                revid = re.compile(item_rule.infos,
                                   re.IGNORECASE + re.DOTALL + re.MULTILINE)
                for reinfos in revid.findall(data):
                    tmp = CListItem()

                    if lItem['referer']:
                        tmp['referer'] = lItem['referer']

                    if item_rule.order.find('|') != -1:
                        infos_names = item_rule.order.split('|')
                        infos_values = list(reinfos)
                        i = 0
                        for name in infos_names:
                            tmp[name] = infos_values[i]
                            i = i + 1
                    else:
                        tmp[item_rule.order] = reinfos

                    for info in item_rule.info_list:
                        info_value = tmp[info.name]
                        if info_value:
                            if info.build.find('%s') != -1:
                                tmpVal = enc.smart_unicode(
                                    info.build % enc.smart_unicode(info_value))
                                tmp[info.name] = tmpVal
                            continue

                        if info.build.find('%s') != -1:
                            if info.src.__contains__('+'):
                                tmpArr = info.src.split('+')
                                src = ''
                                for t in tmpArr:
                                    t = t.strip()
                                    if t.find('\'') != -1:
                                        src = src + t.strip('\'')
                                    else:
                                        src = src + enc.smart_unicode(tmp[t])
                            elif info.src.__contains__('||'):
                                variables = info.src.split('||')
                                src = firstNonEmpty(tmp, variables)
                            else:
                                src = tmp[info.src]

                            if src and info.convert != []:
                                src = self.__parseCommands(
                                    tmp, src, info.convert)
                                if isinstance(src, dict):
                                    for dKey in src:
                                        tmp[dKey] = src[dKey]
                                    src = src.values()[0]

                            info_value = info.build % (enc.smart_unicode(src))
                        else:
                            info_value = info.build

                        tmp[info.name] = info_value

                    tmp['url'] = enc.smart_unicode(
                        item_rule.url_build % (enc.smart_unicode(tmp['url'])))
                    tmp.merge(lItem)
                    if item_rule.skill.find('append') != -1:
                        tmp['url'] = url + tmp['url']

                    if item_rule.skill.find('space') != -1:
                        tmp['title'] = ' %s ' % tmp['title'].strip()

                    if skills.find('videoTitle') > -1:
                        tmp['videoTitle'] = tmp['title']

                    tmp['definedIn'] = definedIn
                    items.append(tmp)

        return items
Esempio n. 8
0
    def __parseCfg(self, cfgFile, data, lItem):
        tmpList = CList()

        data = data.replace('\r\n', '\n').split('\n')

        items = []
        tmp = None
        hasOwnCfg = False

        for m in data:
            if m and m[0] != '#':
                index = m.find('=')
                if index != -1:
                    key = lower(m[:index]).strip()
                    value = m[index + 1:]

                    index = value.find('|')
                    if value[:index] == 'sports.devil.locale':
                        value = common.translate(int(value[index + 1:]))
                    elif value[:index] == 'sports.devil.image':
                        value = os.path.join(common.Paths.imgDir,
                                             value[index + 1:])

                    if key == 'start':
                        tmpList.start = value
                    elif key == 'section':
                        tmpList.section = value
                    elif key == 'sort':
                        tmpList.sort = value
                    elif key == 'skill':
                        tmpList.skill = value
                    elif key == 'catcher':
                        tmpList.catcher = value

                    elif key == 'item_infos':
                        rule_tmp = CRuleItem()
                        hasOwnCfg = False
                        rule_tmp.infos = value
                    elif key == 'item_order':
                        rule_tmp.order = value
                    elif key == 'item_skill':
                        rule_tmp.skill = value
                    elif key == 'item_curr':
                        rule_tmp.curr = value
                    elif key == 'item_precheck':
                        rule_tmp.precheck = value

                    elif key.startswith('item_info'):
                        tmpkey = key[len('item_info'):]
                        if tmpkey == '_name':
                            info_tmp = CItemInfo()
                            info_tmp.name = value
                            if value == 'cfg':
                                hasOwnCfg = True
                        elif tmpkey == '_from':
                            info_tmp.src = value
                        elif tmpkey == '':
                            info_tmp.rule = value
                        elif tmpkey == '_default':
                            info_tmp.default = value
                        elif tmpkey == '_convert':
                            info_tmp.convert.append(value)
                        elif tmpkey == '_build':
                            info_tmp.build = value
                            rule_tmp.info_list.append(info_tmp)

                    elif key == 'item_url_build':
                        rule_tmp.url_build = value

                        if tmpList.catcher != '':

                            refInf = CItemInfo()
                            refInf.name = 'referer'
                            refInf.build = value

                            rule_tmp.info_list.append(refInf)

                            if not hasOwnCfg:
                                refInf = CItemInfo()
                                refInf.name = 'catcher'
                                refInf.build = tmpList.catcher

                                rule_tmp.info_list.append(refInf)

                        tmpList.rules.append(rule_tmp)

                    # static menu items (without regex)
                    elif key == 'title':
                        tmp = CListItem()
                        tmp['title'] = value
                        if tmpList.skill.find('videoTitle') > -1:
                            tmp['videoTitle'] = value
                    elif key == 'url':
                        tmp['url'] = value
                        if lItem:
                            tmp.merge(lItem)

                        if tmpList.catcher != '':
                            tmp['referer'] = value
                            if not hasOwnCfg:
                                tmp['catcher'] = tmpList.catcher

                        tmp['definedIn'] = cfgFile
                        items.append(tmp)
                        tmp = None
                    elif tmp != None:
                        if key == 'cfg':
                            hasOwnCfg = True
                        tmp[key] = value

        tmpList.items = items
        tmpList.cfg = cfgFile
        return tmpList
Esempio n. 9
0
    def __loadRemote(self, inputList, lItem):

        try:
            inputList.curr_url = lItem['url']

            count = 0
            i = 1
            maxits = 2  # 1 optimistic + 1 demystified
            ignoreCache = False
            demystify = False
            startUrl = inputList.curr_url
            #print inputList, lItem
            while count == 0 and i <= maxits:
                if i > 1:
                    ignoreCache = True
                    demystify = True

                # Trivial: url is from known streamer
                items = self.__parseHtml(inputList.curr_url,
                                         '"' + inputList.curr_url + '"',
                                         inputList.rules, inputList.skill,
                                         inputList.cfg, lItem)
                count = len(items)

                # try to find items in html source code
                if count == 0:
                    referer = ''
                    if lItem['referer']:
                        referer = lItem['referer']
                    data = common.getHTML(inputList.curr_url, referer,
                                          ignoreCache, demystify)
                    if data == '':
                        return False

                    msg = 'Remote URL ' + str(inputList.curr_url) + ' opened'
                    if demystify:
                        msg += ' (demystified)'
                    common.log(msg)

                    if inputList.section != '':
                        section = inputList.section
                        data = self.__getSection(data, section)

                    if lItem['section']:
                        section = lItem['section']
                        data = self.__getSection(data, section)

                    items = self.__parseHtml(inputList.curr_url, data,
                                             inputList.rules, inputList.skill,
                                             inputList.cfg, lItem)
                    count = len(items)
                    common.log('    -> ' + str(count) + ' item(s) found')

                # find rtmp stream
                #common.log('Find rtmp stream')
                if count == 0:
                    item = self.__findRTMP(data, startUrl, lItem)
                    if item:
                        items = []
                        items.append(item)
                        count = 1

                # find embedding javascripts
                #common.log('Find embedding javascripts')
                if count == 0:
                    item = findJS(data)
                    if item:
                        firstJS = item[0]
                        streamId = firstJS[0]
                        jsUrl = firstJS[1]
                        streamerName = getHostName(jsUrl)
                        jsSource = getHTML(jsUrl, startUrl, True, False)
                        phpUrl = findPHP(jsSource, streamId)
                        if phpUrl:
                            data = getHTML(phpUrl, startUrl, True, True)
                            item = self.__findRTMP(data, phpUrl, lItem)
                            if item:

                                if streamerName:
                                    item['title'] = item['title'].replace(
                                        'RTMP', streamerName)

                                items = []
                                items.append(item)
                                count = 1

                # find vcods
                #common.log('find vcods')
                if count == 0:
                    vcods = findVCods(data)
                    if vcods:
                        sUrl = vcods[0]
                        cod1 = vcods[1]
                        cod2 = vcods[2]
                        swfUrl = vcods[3]
                        unixTS = str(dt.getUnixTimestamp())
                        sUrl = sUrl + '?callback=jQuery1707757964063647694_1347894980192&v_cod1=' + cod1 + '&v_cod2=' + cod2 + '&_=' + unixTS
                        tmpData = getHTML(sUrl, urllib.unquote_plus(startUrl),
                                          True, False)
                        if tmpData and tmpData.find("Bad Request") == -1:
                            newReg = '"result1":"([^\"]+)","result2":"([^\"]+)"'
                            link = regexUtils.findall(tmpData, newReg)
                            if link:
                                _file = link[0][0]
                                rtmp = link[0][1].replace('\\', '')
                                #.replace('/redirect','/vod')
                                item = CListItem()
                                item['title'] = getHostName(
                                    sUrl) + '* - ' + _file
                                item['type'] = 'video'
                                item[
                                    'url'] = rtmp + ' playPath=' + _file + ' swfUrl=' + swfUrl + ' swfVfy=1 live=true pageUrl=' + startUrl
                                item.merge(lItem)
                                items.append(item)
                                count = 1

                # find redirects
                #common.log('find redirects')
                if count == 0:
                    red = self.__findRedirect(startUrl, inputList.curr_url)
                    if startUrl == red:
                        common.log('    -> No redirect found')
                    else:
                        common.log('    -> Redirect: ' + red)
                        inputList.curr_url = red
                        common.log(
                            str(len(inputList.items)) + ' items ' +
                            inputList.cfg + ' -> ' + red)
                        startUrl = red
                        if lItem['referer']:
                            lItem['referer'] = red
                        i = 0

                i += 1

            if count != 0:
                inputList.items = inputList.items + items

        except IOError:
            if common.enable_debug:
                traceback.print_exc(file=sys.stdout)
            return False
        return True
Esempio n. 10
0
    def __parseHtml(self, url, data, rules, skills, definedIn, lItem):          

        common.log('_parseHtml called' + url)
        items = []

        for item_rule in rules:
            common.log('rule: ' + item_rule.infos)
            #print('>>>>item_rule: ',item_rule)
            #print("MMMMMMMM",mydump(item_rule))

            # Zmiana MN
            if not hasattr(item_rule, 'precheck') or (item_rule.precheck in data):

                revid = re.compile(item_rule.infos, re.IGNORECASE + re.DOTALL + re.MULTILINE + re.UNICODE)
                for reinfos in revid.findall(data):
                    tmp = CListItem()
                  
                    if lItem['referer']:
                        tmp['referer'] = lItem['referer']
                      
                    if item_rule.order.find('|') != -1:
                        infos_names = item_rule.order.split('|')
                        infos_values = list(reinfos)
                        i = 0
                        for name in infos_names:
                            tmp[name] = infos_values[i]
                            i = i+1
                    else:
                        tmp[item_rule.order] = reinfos

                    for info in item_rule.info_list:
                        info_value = tmp[info.name]
                        if info_value:
                            if info.build.find('%s') != -1:
                                tmpVal = info.build % info_value
                                tmp[info.name] = tmpVal
                            continue

                        if info.build.find('%s') != -1:
                            if info.src.__contains__('+'):
                                tmpArr = info.src.split('+')
                                src = ''
                                for t in tmpArr:
                                    t = t.strip()
                                    if t.find('\'') != -1:
                                        src = src + t.strip('\'')
                                    else:
                                        src = src + tmp[t]
                            elif info.src.__contains__('||'):
                                variables = info.src.split('||')
                                src = firstNonEmpty(tmp, variables)
                            else:
                                src = tmp[info.src]

                            if src and info.convert != []: 
                                tmp['referer'] = url                              
                                src = self.__parseCommands(tmp, src, info.convert)
                                if isinstance(src, dict):
                                    for dKey in src:
                                        tmp[dKey] = src[dKey]
                                    src = src.values()[0]

                            info_value = info.build % (src)
                        else:
                            info_value = info.build

                        tmp[info.name] = info_value

                    if tmp['url']:
                        tmp['url'] = item_rule.url_build % (tmp['url'])
                    else:
                        tmp['url'] = url
                    
                    tmp.merge(lItem)
                    if item_rule.skill.find('append') != -1:
                        tmp['url'] = url + tmp['url']

                    if item_rule.skill.find('space') != -1:
                        tmp['title'] = ' %s ' % tmp['title'].strip()

                    if skills.find('videoTitle') > -1:
                        tmp['videoTitle'] = tmp['title']

                    tmp['definedIn'] = definedIn
                    items.append(tmp)

        return items
Esempio n. 11
0
    def __parseCfg(self, cfgFile, data, lItem):
        tmpList = CList()

        data = data.replace('\r\n', '\n').split('\n')

        items = []
        tmp = None
        hasOwnCfg = False
        
        for m in data:
            if m and m[0] != '#':
                index = m.find('=')
                if index != -1:
                    key = lower(m[:index]).strip()
                    value = m[index+1:]

                    index = value.find('|')
                    if value[:index] == 'sports.devil.locale':
                        value = common.translate(int(value[index+1:]))
                    elif value[:index] == 'sports.devil.image':
                        value = os.path.join(common.Paths.imgDir, value[index+1:])

                    if key == 'start':
                        tmpList.start = value
                    elif key == 'section':
                        tmpList.section = value
                    elif key == 'sort':
                        tmpList.sort = value
                    elif key == 'skill':
                        tmpList.skill = value
                    elif key == 'catcher':
                        tmpList.catcher = value

                    elif key == 'item_infos':
                        rule_tmp = CRuleItem()
                        hasOwnCfg = False
                        rule_tmp.infos = value
                    elif key == 'item_order':
                        rule_tmp.order = value
                    elif key == 'item_skill':
                        rule_tmp.skill = value
                    elif key == 'item_curr':
                        rule_tmp.curr = value
                    elif key == 'item_precheck':
                        rule_tmp.precheck = value

                    elif key.startswith('item_info'):
                        tmpkey = key[len('item_info'):]
                        if tmpkey == '_name':
                            info_tmp = CItemInfo()
                            info_tmp.name = value
                            if value == 'cfg':
                                hasOwnCfg = True
                        elif tmpkey == '_from':
                            info_tmp.src = value
                        elif tmpkey == '':
                            info_tmp.rule = value
                        elif tmpkey == '_default':
                            info_tmp.default = value
                        elif tmpkey == '_convert':
                            info_tmp.convert.append(value)
                        elif tmpkey == '_build':
                            info_tmp.build = value
                            rule_tmp.info_list.append(info_tmp)

                    elif key == 'item_url_build':
                        rule_tmp.url_build = value
                        
                        if tmpList.catcher != '':
                            
                            refInf = CItemInfo()
                            refInf.name = 'referer'
                            refInf.build = value
                            
                            rule_tmp.info_list.append(refInf)
                            
                            if not hasOwnCfg:
                                refInf = CItemInfo()
                                refInf.name = 'catcher'
                                refInf.build = tmpList.catcher
                                
                                rule_tmp.info_list.append(refInf)
    
                        tmpList.rules.append(rule_tmp)


                    # static menu items (without regex)
                    elif key == 'title':
                        tmp = CListItem()
                        tmp['title'] = value
                        if tmpList.skill.find('videoTitle') > -1:
                            tmp['videoTitle'] = value 
                    elif key == 'url':
                        tmp['url'] = value
                        if lItem:
                            tmp.merge(lItem)
                            
                        if tmpList.catcher != '':
                            tmp['referer'] = value
                            if not hasOwnCfg:
                                tmp['catcher'] = tmpList.catcher
                            
                        tmp['definedIn'] = cfgFile
                        items.append(tmp)
                        tmp = None
                    elif tmp != None:
                        if key == 'cfg':
                            hasOwnCfg = True
                        tmp[key] = value


        tmpList.items = items
        tmpList.cfg = cfgFile
        return tmpList
Esempio n. 12
0
    def __loadRemote(self, inputList, lItem):

        try:
            inputList.curr_url = lItem['url']

            count = 0
            i = 1
            maxits = 2      # 1 optimistic + 1 demystified
            ignoreCache = False
            demystify = False
            startUrl = inputList.curr_url
            #print inputList, lItem
            while count == 0 and i <= maxits:
                if i > 1:
                    ignoreCache = True
                    demystify =  True

                # Trivial: url is from known streamer
                items = self.__parseHtml(inputList.curr_url, '"' + inputList.curr_url + '"', inputList.rules, inputList.skill, inputList.cfg, lItem)
                count = len(items)


                # try to find items in html source code
                if count == 0:
                    referer = ''
                    if lItem['referer']:
                        referer = lItem['referer']
                    inputList.curr_url = HTMLParser.HTMLParser().unescape(urllib.unquote(inputList.curr_url))
                    data = common.getHTML(inputList.curr_url, None, referer, ignoreCache, demystify)
                    if data == '':
                        return False

                    msg = 'Remote URL ' + str(inputList.curr_url) + ' opened'
                    if demystify:
                        msg += ' (demystified)'
                    common.log(msg)

                    
                    if inputList.section != '':
                        section = inputList.section
                        data = self.__getSection(data, section)
                        
                    if lItem['section']:
                        section = lItem['section']
                        data = self.__getSection(data, section)
                                                
                    
                    items = self.__parseHtml(inputList.curr_url, data, inputList.rules, inputList.skill, inputList.cfg, lItem)
                    count = len(items)
                    common.log('    -> ' + str(count) + ' item(s) found')

                # find rtmp stream
                #common.log('Find rtmp stream')
                if count == 0:
                    item = self.__findRTMP(data, startUrl, lItem)
                    if item:
                        items = []
                        items.append(item)
                        count = 1

                # find embedding javascripts
                #common.log('Find embedding javascripts')
                if count == 0:
                    item = findJS(data)
                    if item:
                        firstJS = item[0]
                        streamId = firstJS[0]
                        jsUrl = firstJS[1]
                        streamerName = getHostName(jsUrl)
                        jsSource = getHTML(jsUrl, None, startUrl, True, False)
                        phpUrl = findPHP(jsSource, streamId)
                        if phpUrl:
                            data = getHTML(phpUrl, None, startUrl, True, True)
                            item = self.__findRTMP(data, phpUrl, lItem)
                            if item:
                                
                                if streamerName:
                                    item['title'] = item['title'].replace('RTMP', streamerName)
                                
                                items = []
                                items.append(item)
                                count = 1
                            else:
                                red = phpUrl
                                common.log('    -> Redirect: ' + red)
                                inputList.curr_url = red
                                common.log(str(len(inputList.items)) + ' items ' + inputList.cfg + ' -> ' + red)
                                startUrl = red
                                if lItem['referer']:
                                    lItem['referer'] = red
                                continue

                # find vcods
                #common.log('find vcods')
                if count == 0:
                    vcods = findVCods(data)
                    if vcods:
                        sUrl = vcods[0]
                        cod1 = vcods[1]
                        cod2 = vcods[2]
                        swfUrl = vcods[3]
                        unixTS = str(dt.getUnixTimestamp())
                        sUrl = sUrl + '?callback=jQuery1707757964063647694_1347894980192&v_cod1=' + cod1 + '&v_cod2=' + cod2 + '&_=' + unixTS
                        tmpData = getHTML(sUrl, None, urllib.unquote_plus(startUrl), True, False)
                        if tmpData and tmpData.find("Bad Request") == -1:
                            newReg = '"result1":"([^\"]+)","result2":"([^\"]+)"'
                            link = regexUtils.findall(tmpData, newReg)
                            if link:
                                _file = link[0][0]
                                rtmp = link[0][1].replace('\\','')
                                #.replace('/redirect','/vod')
                                item = CListItem()
                                item['title'] = getHostName(sUrl) + '* - ' + _file
                                item['type'] = 'video'
                                item['url'] = rtmp + ' playPath=' + _file + ' swfUrl=' + swfUrl +' swfVfy=1 live=true pageUrl=' + startUrl
                                item.merge(lItem)
                                items.append(item)
                                count = 1  
                        
                        
                        
                # find redirects
                #common.log('find redirects')
                if count == 0:
                    red = self.__findRedirect(startUrl, inputList.curr_url)
                    if startUrl == red:
                        common.log('    -> No redirect found')
                    else:
                        red = HTMLParser.HTMLParser().unescape(red) 
                        red = urllib.unquote(red)
                        common.log('    -> Redirect: ' + red)
                        inputList.curr_url = red
                        common.log(str(len(inputList.items)) + ' items ' + inputList.cfg + ' -> ' + red)
                        startUrl = red
                        if lItem['referer']:
                            lItem['referer'] = red
                        i = 0

                i += 1


            if count != 0:
                inputList.items = inputList.items + items


        except IOError:
            if common.enable_debug:
                traceback.print_exc(file = sys.stdout)
            return False
        return True
Esempio n. 13
0
    def __parseHtml(self, url, data, rules, skills, definedIn, lItem):

        common.log('_parseHtml called: ')
        items = []

        for item_rule in rules:

            #precheck attribute is used to filter correct rule from _streams.cfg
            if not hasattr(item_rule, 'precheck') or (item_rule.precheck
                                                      in data):
                #common.log('Parser rule: ' + str(item_rule.infos))
                try:
                    common.log('Parser rule precheck: %s' %
                               str(item_rule.precheck))
                except:
                    pass

                revid = re.compile(
                    item_rule.infos,
                    re.IGNORECASE + re.DOTALL + re.MULTILINE + re.UNICODE)
                for reinfos in revid.findall(data):
                    tmp = CListItem()

                    if lItem['referer']:
                        tmp['referer'] = lItem['referer']

                    if item_rule.order.find('|') != -1:
                        infos_names = item_rule.order.split('|')
                        infos_values = list(reinfos)
                        i = 0
                        for name in infos_names:
                            tmp[name] = infos_values[i]
                            i = i + 1
                    else:
                        tmp[item_rule.order] = reinfos

                    for info in item_rule.info_list:
                        info_value = tmp[info.name]
                        if info_value:
                            if info.build.find('%s') != -1:
                                tmpVal = info.build % info_value
                                tmp[info.name] = tmpVal
                            continue

                        if info.build.find('%s') != -1:
                            if info.src.__contains__('+'):
                                tmpArr = info.src.split('+')
                                src = ''
                                for t in tmpArr:
                                    t = t.strip()
                                    if t.find('\'') != -1:
                                        src = src + t.strip('\'')
                                    else:
                                        src = src + (tmp[t] or '')

                            elif info.src.__contains__('||'):
                                variables = info.src.split('||')
                                src = firstNonEmpty(tmp, variables)

                            else:
                                src = tmp[info.src]

                            if src and info.convert != []:
                                tmp['referer'] = url
                                src = self.__parseCommands(
                                    tmp, src, info.convert)
                                if isinstance(src, dict):
                                    for dKey in src:
                                        tmp[dKey] = src[dKey]
                                    src = src.values()[0]

                            info_value = info.build % (src)
                        else:
                            info_value = info.build

                        tmp[info.name] = info_value

                    if tmp['url']:
                        tmp['url'] = item_rule.url_build % (tmp['url'])
                    else:
                        tmp['url'] = url

                    tmp.merge(lItem)
                    if item_rule.skill.find('append') != -1:
                        tmp['url'] = url + tmp['url']

                    if item_rule.skill.find('space') != -1:
                        tmp['title'] = ' %s ' % tmp['title'].strip()

                    if skills.find('videoTitle') > -1:
                        tmp['videoTitle'] = tmp['title']

                    tmp['definedIn'] = definedIn
                    #common.log('JairoXYZParserPy: ' + str(tmp))
                    items.append(tmp)

        return items
Esempio n. 14
0
    def __parseHtml(self, url, data, rules, definedIn, lItem):

        items = []

        for item_rule in rules:
            revid = re.compile(item_rule.infos, re.IGNORECASE + re.DOTALL + re.MULTILINE)
            for reinfos in revid.findall(data):
                tmp = CListItem()
                if item_rule.order.find('|') != -1:
                    tmp.infos_names = item_rule.order.split('|')
                    tmp.infos_values = list(reinfos)
                else:
                    tmp[item_rule.order] = reinfos

                for info in item_rule.info_list:
                    info_value = tmp[info.name]
                    if info_value:
                        if info.build.find('%s') != -1:
                            tmpVal = enc.smart_unicode(info.build % enc.smart_unicode(info_value))
                            tmp[info.name] = tmpVal
                        continue

                    if info.build.find('%s') != -1:
                        if info.src.__contains__('+'):
                            tmpArr = info.src.split('+')
                            src = ''
                            for t in tmpArr:
                                t = t.strip()
                                if t.find('\'') != -1:
                                    src = src + t.strip('\'')
                                else:
                                    src = src + enc.smart_unicode(tmp[t])
                        elif info.src.__contains__('||'):
                            variables = info.src.split('||')
                            src = firstNonEmpty(tmp, variables)
                        else:
                            src = tmp[info.src]

                        if src and info.convert != []:
                            src = self.__parseCommands(tmp, src, info.convert)
                            if isinstance(src, dict):
                                for dKey in src:
                                    tmp[dKey] = src[dKey]
                                src = src.values()[0]

                        info_value = info.build % (enc.smart_unicode(src))
                    else:
                        info_value = info.build

                    tmp[info.name] = info_value


                tmp['url'] = enc.smart_unicode(item_rule.url_build % (enc.smart_unicode(tmp['url'])))
                tmp.merge(lItem)
                if item_rule.skill.find('append') != -1:
                    tmp['url'] = url + tmp['url']

                if item_rule.skill.find('space') != -1:
                    tmp['title'] = ' %s ' % tmp['title'].strip()

                tmp['definedIn'] = definedIn
                items.append(tmp)

        return items
Esempio n. 15
0
    def __parseHtml(self, url, data, rules, skills, definedIn, lItem):

        # common.log('_parseHtml called')
        items = []

        for item_rule in rules:
            # common.log('rule: ' + item_rule.infos)

            if not hasattr(item_rule, "precheck") or (item_rule.precheck in data):

                revid = re.compile(item_rule.infos, re.IGNORECASE + re.DOTALL + re.MULTILINE)
                for reinfos in revid.findall(data):
                    tmp = CListItem()

                    if lItem["referer"]:
                        tmp["referer"] = lItem["referer"]

                    if item_rule.order.find("|") != -1:
                        infos_names = item_rule.order.split("|")
                        infos_values = list(reinfos)
                        i = 0
                        for name in infos_names:
                            tmp[name] = infos_values[i]
                            i = i + 1
                    else:
                        tmp[item_rule.order] = reinfos

                    for info in item_rule.info_list:
                        info_value = tmp[info.name]
                        if info_value:
                            if info.build.find("%s") != -1:
                                tmpVal = enc.smart_unicode(info.build % enc.smart_unicode(info_value))
                                tmp[info.name] = tmpVal
                            continue

                        if info.build.find("%s") != -1:
                            if info.src.__contains__("+"):
                                tmpArr = info.src.split("+")
                                src = ""
                                for t in tmpArr:
                                    t = t.strip()
                                    if t.find("'") != -1:
                                        src = src + t.strip("'")
                                    else:
                                        src = src + enc.smart_unicode(tmp[t])
                            elif info.src.__contains__("||"):
                                variables = info.src.split("||")
                                src = firstNonEmpty(tmp, variables)
                            else:
                                src = tmp[info.src]

                            if src and info.convert != []:
                                src = self.__parseCommands(tmp, src, info.convert)
                                if isinstance(src, dict):
                                    for dKey in src:
                                        tmp[dKey] = src[dKey]
                                    src = src.values()[0]

                            info_value = info.build % (enc.smart_unicode(src))
                        else:
                            info_value = info.build

                        tmp[info.name] = info_value

                    tmp["url"] = enc.smart_unicode(item_rule.url_build % (enc.smart_unicode(tmp["url"])))
                    tmp.merge(lItem)
                    if item_rule.skill.find("append") != -1:
                        tmp["url"] = url + tmp["url"]

                    if item_rule.skill.find("space") != -1:
                        tmp["title"] = " %s " % tmp["title"].strip()

                    if skills.find("videoTitle") > -1:
                        tmp["videoTitle"] = tmp["title"]

                    tmp["definedIn"] = definedIn
                    items.append(tmp)

        return items
Esempio n. 16
0
    def __parseCfg(self, cfgFile, data, lItem):
        tmpList = CList()

        data = data.replace("\r\n", "\n").split("\n")

        items = []
        tmp = None
        hasOwnCfg = False

        for m in data:
            if m and m[0] != "#":
                index = m.find("=")
                if index != -1:
                    key = lower(m[:index]).strip()
                    value = m[index + 1 :]

                    index = value.find("|")
                    if value[:index] == "sports.devil.locale":
                        value = common.translate(int(value[index + 1 :]))
                    elif value[:index] == "sports.devil.image":
                        value = os.path.join(common.Paths.imgDir, value[index + 1 :])

                    if key == "start":
                        tmpList.start = value
                    elif key == "section":
                        tmpList.section = value
                    elif key == "sort":
                        tmpList.sort = value
                    elif key == "skill":
                        tmpList.skill = value
                    elif key == "catcher":
                        tmpList.catcher = value

                    elif key == "item_infos":
                        rule_tmp = CRuleItem()
                        hasOwnCfg = False
                        rule_tmp.infos = value
                    elif key == "item_order":
                        rule_tmp.order = value
                    elif key == "item_skill":
                        rule_tmp.skill = value
                    elif key == "item_curr":
                        rule_tmp.curr = value
                    elif key == "item_precheck":
                        rule_tmp.precheck = value

                    elif key.startswith("item_info"):
                        tmpkey = key[len("item_info") :]
                        if tmpkey == "_name":
                            info_tmp = CItemInfo()
                            info_tmp.name = value
                            if value == "cfg":
                                hasOwnCfg = True
                        elif tmpkey == "_from":
                            info_tmp.src = value
                        elif tmpkey == "":
                            info_tmp.rule = value
                        elif tmpkey == "_default":
                            info_tmp.default = value
                        elif tmpkey == "_convert":
                            info_tmp.convert.append(value)
                        elif tmpkey == "_build":
                            info_tmp.build = value
                            rule_tmp.info_list.append(info_tmp)

                    elif key == "item_url_build":
                        rule_tmp.url_build = value

                        if tmpList.catcher != "":

                            refInf = CItemInfo()
                            refInf.name = "referer"
                            refInf.build = value

                            rule_tmp.info_list.append(refInf)

                            if not hasOwnCfg:
                                refInf = CItemInfo()
                                refInf.name = "catcher"
                                refInf.build = tmpList.catcher

                                rule_tmp.info_list.append(refInf)

                        tmpList.rules.append(rule_tmp)

                    # static menu items (without regex)
                    elif key == "title":
                        tmp = CListItem()
                        tmp["title"] = value
                        if tmpList.skill.find("videoTitle") > -1:
                            tmp["videoTitle"] = value
                    elif key == "url":
                        tmp["url"] = value
                        if lItem:
                            tmp.merge(lItem)

                        if tmpList.catcher != "":
                            tmp["referer"] = value
                            if not hasOwnCfg:
                                tmp["catcher"] = tmpList.catcher

                        tmp["definedIn"] = cfgFile
                        items.append(tmp)
                        tmp = None
                    elif tmp != None:
                        if key == "cfg":
                            hasOwnCfg = True
                        tmp[key] = value

        tmpList.items = items
        tmpList.cfg = cfgFile
        return tmpList