def decodeUrl(url): item = {} if url.find("&") == -1: item[u"url"] = smart_unicode(urllib.unquote(url)) item[u"type"] = u"start" else: for info_name_value in url.split("&"): info_name, info_value = info_name_value.split("=", 1) if info_name == "mode": mode.setMode(info_value) else: if info_name == "url": info_value = info_value.replace("%20", "%2520") item[smart_unicode(info_name)] = urllib.unquote(smart_unicode(info_value)) return item
def log(s): if enable_debug: try: xbmc.log(s) except UnicodeEncodeError: xbmc.log(smart_unicode(s).encode("ISO-8859-1")) return
def loadFile(lItem): ext = getFileExtension(lItem[u'url']) if ext == u'cfg' or ext == u'list': filename = lItem[u'url'] else: filename = lItem[u'cfg'] for directory in [resDir, cacheDir, allsitesDir, catDir, '']: try: f = open(os.path.join(directory, filename), 'r') except IOError: pass else: data = smart_unicode(f.read()) f.close() data = data.splitlines() keys = [] values = [] for line in reversed(data): if line and not line.startswith(u'#'): key, value = line.split(u'=', 1) keys.append(key) values.append(value) return keys, values else: traceback.print_exc(file = sys.stdout) log(u'File Not Found: "%s"' % filename) raise
def clean_safe(s): if not s: return '' try: o = smart_unicode(s) # remove any number of "amp;" #&/& --> & #&#XXX/&#XXX --> &#XXX #&XXX/&XXX --> &XXX #& jane&'s --> & jane's o = o.replace(u'amp;', u'') # remove &#XXX; &#xXXX; &XXX; o = decode(o) # remove \uXXX o = re.sub(r'\\u(....)', lambda m: unichr(int(m.group(1), 16)), o) except: if enable_debug: traceback.print_exc(file = sys.stdout) o = s return o
def loadCatcher(self, filename): del self.key[:] del self.value[:] self.key, self.value = smart_read_file(filename) if self.key == None and self.value == None: return None site = None rule = None while self.key: old_line = len(self.key) if self.loadKey(u'url'): if site: self.sites.append(site) site = CCatcherRuleSite() site.url = self.value.pop() if self.loadKey(u'data'): site.data = self.value.pop() if self.loadKey(u'header'): index = self.value[-1].find(u'|') site.txheaders[self.value[-1][:index]] = self.value[-1][index+1:] del self.value[-1] if self.loadKey(u'limit'): site.limit = int(self.value.pop()) if self.loadKey(u'startRE'): site.startRE = self.value.pop() if self.loadKey(u'stopRE'): site.stopRE = self.value.pop() while self.key: old_line = len(self.key) if self.loadKey(u'target'): if rule: site.rules.append(rule) rule = CCatcherRuleItem() rule.target = smart_unicode(self.value.pop()) if self.loadKey(u'quality'): rule.quality = self.value.pop() continue if self.loadKey(u'priority'): rule.priority = int(self.value.pop()) continue if self.loadKey(u'type'): rule.type = self.value.pop() if rule.type == u'forward' or rule.type.startswith(u'redirect'): site.rules.append(rule) rule = None break else: if self.loadKey(u'actions'): if self.value[-1].find(u'|') != -1: rule.actions.extend(self.value.pop().split(u'|')) else: rule.actions.append(self.value.pop()) if self.loadKey(u'build'): rule.build = self.value.pop() if self.loadKey(u'dkey'): rule.dkey = smart_unicode(self.value.pop()) if self.loadKey(u'dkey_actions'): if self.value[-1].find(u'|') != -1: rule.dkey_actions.extend(self.value.pop().split(u'|')) else: rule.dkey_actions.append(self.value.pop()) if self.loadKey(u'extension'): rule.extension = self.value.pop() if self.loadKey(u'info'): rule.info = self.value.pop() if self.loadKey(u'player'): rule.player = self.value.pop() if len(self.key) == old_line: log(u'Syntax Error:\n"%s" is invalid.' % self.filename) if len(self.key) == old_line: log(u'Syntax Error:\n"%s" is invalid.' % self.filename) if rule != None: site.rules.append(rule) self.sites.append(site) return None
elif compression == 'deflate': try: data = zlib.decompress(data) except zlib.error, e: try: # The data may have no headers and no checksum. data = zlib.decompress(data, -15) except zlib.error, e: log('Skipping due to zlib decompression failure') return items if enable_debug: f = open(os.path.join(cacheDir, site.cfg + u'.page.html'), 'w') f.write('<Title>'+ site.start + '</Title>\n\n') f.write(data) f.close() data = smart_unicode(data) if site.startRE: point = data.find(site.startRE) if point == -1: log('startRe not found for %s' % site.cfg) point = 0 else: point = 0 # if mode == u'VIEWALL_DIRECTORY' or mode == u'VIEW_RSS_DIRECTORY': # lock = [u'video', u'video_list'] # else: # lock = [] lock = [] for item_rule in site.rules: rule_items, tmp_rule_items = [], [] if item_rule.type in lock: