def infoFormatter(items, infos):
    if u'title' in infos:
        for item in items:
            if item[u'title'] != u'':
                item[u'title'] = clean_safe(item[u'title'].replace(u'\r\n', u'').replace(u'\n', u'').replace(u'\t', u''))
                item[u'title'] = item[u'title'].lstrip(u' -@#$%^&*_-+=.,\';:"\|/?`~>)]}!u')
                item[u'title'] = item[u'title'].rstrip(u' -@#$%^&*_-+=.,;:\'"\|/?`~<([{')
                item[u'title'] = item[u'title'].title()
            else:
                item[u'title'] = u' ... '
    if u'duration' in infos:
        for item in items:
            item[u'duration'] = item[u'duration'].strip(u' ()')
            if item[u'duration'][-2] == u':':
                item[u'duration'] = item[u'duration'][:-2] + u'0' + item[u'duration'][-2:]
            item[u'title'] = item[u'title'] + u' (' +  item[u'duration'] + u')'
    if u'icon' in infos:
        for item in items:
            if item[u'icon'] == u'':
                item[u'icon'] = os.path.join(imgDir, 'video.png')
    for info in infos:
        if info.endswith(u'.tmp'):
            for item in items:
                del item[info]
    return items
 def selectLink(self):
     if int(addon.getSetting(u'video_type')) != 0:
         selection = 0
     else:
         dia = xbmcgui.Dialog()
         selection = dia.select(__language__(30055), self.selectionList)
     self.urlList[selection] = clean_safe(urllib.unquote(self.urlList[selection]))
     if self.dkey != None:
         self.dkey = clean_safe(urllib.unquote(self.dkey))
         self.urlList[selection] = sesame.decrypt(self.urlList[selection], self.dkey, 256)
     elif self.decryptList[selection] != None:
         self.decryptList[selection] = clean_safe(urllib.unquote(self.decryptList[selection]))
         self.urlList[selection] = sesame.decrypt(self.urlList[selection], self.decryptList[selection], 256)
     self.link = self.urlList[selection]
     self.videoExtension = u'.' + self.extensionList[selection]
     self.player = self.playerList[selection]
     return None
    def parseVideoPage(self, url):
        video_found = False
        for index, site in enumerate(self.sites):
            if video_found:
                break
            # Download website
            if site.data == u'':
                if site.url.find(u'%') != -1:
                    url = site.url % url
                req = Request(url, None, site.txheaders)
                urlfile = opener.open(req)
                if site.limit == 0:
                    data = urlfile.read()
                else:
                    data = urlfile.read(site.limit)
            else:
                data_url = site.data % url
                req = Request(site.url, data_url, site.txheaders)
                response = urlopen(req)
                if site.limit == 0:
                    data = response.read()
                else:
                    data = response.read(site.limit)
            if enable_debug:
                f = open(os.path.join(cacheDir, 'site.html'), 'w')
                f.write(u'<Titel>'+ url + u'</Title>\n\n')
                f.write(data)
                f.close()

            if site.startRE:
                start = data.find(site.startRE.encode('utf-8'))
                if start == -1:
                    log(u'startRe not found for %s' % url)
                else:
                    data = data[start:]
                    if site.stopRE:
                        stop = data.find(site.stopRE.encode('utf-8'))
                        if stop == -1:
                            log(u'stopRe not found for %s' % url)
                        else:
                            data = data[:stop]

            # If user setting is not set to "Ask me"
            # Sort rules to parse in the order specified in the settings
            # Parsing will continue until a match is found with rule.priority anything other than 0
            if len(site.rules) > 1:
                decorated1 = [(rule.priority, i, rule) for i, rule in enumerate(site.rules) if rule.priority < 0]
                decorated1 = sorted(decorated1, reverse = True)
                if int(addon.getSetting(u'video_type')) == 3:
                    decorated = [(rule.priority, i, rule) for i, rule in enumerate(site.rules) if rule.priority >= 0]
                    decorated = sorted(decorated)
                    site.rules = [rule for priority, i, rule in decorated]
                elif int(addon.getSetting(u'video_type')) == 2:
                    decorated = [(rule.priority, i, rule) for i, rule in enumerate(site.rules) if rule.priority > 0]
                    decorated = sorted(decorated)
                    if len(decorated) % 2 == 0:
                        decorated = decorated[len(decorated) // 2 - 1:] + list(reversed(decorated[:len(decorated) // 2 - 1]))
                    else:
                        decorated = decorated[len(decorated) // 2:] + list(reversed(decorated[:len(decorated) // 2]))
                    site.rules = [rule for rule in site.rules if rule.priority == 0] + [rule for priority, i, rule in decorated]
                elif int(addon.getSetting(u'video_type')) == 1:
                    decorated = [(rule.priority, i, rule) for i, rule in enumerate(site.rules) if rule.priority > 0]
                    decorated = sorted(decorated, reverse = True)
                    site.rules = [rule for rule in site.rules if rule.priority == 0] + [rule for priority, i, rule in decorated]
                site.rules += [rule for priority, i, rule in decorated1]
            # Parse Website
            for rule in site.rules:
                match = re.search(rule.target, data, re.IGNORECASE + re.DOTALL + re.MULTILINE)
                if match:
                    link = match.group(1)
                    if len(rule.actions) > 0:
                        for group in range(1, len(match.groups()) + 1):
                            if group == 1:
                                link = {u'match' : link}
                            else:
                                link[u'group' + str(group)] = match.group(group)
                        link = parseActions(link, rule.actions)[u'match']
                    if rule.build != None:
                        link = rule.build % link
                    if rule.type == u'video':
                        video_found = True
                        self.urlList.append(link)
                        self.extensionList.append(rule.extension)
                        self.playerList.append(rule.player)
                        if rule.dkey != None:
                            match = re.search(rule.dkey, data, re.IGNORECASE + re.DOTALL + re.MULTILINE)
                            if match:
                                dkey = match.group(1)
                                if len(rule.dkey_actions) > 0:
                                    dkey = {u'match' : dkey}
                                    dkey = parseActions(dkey, rule.dkey_actions)[u'match']
                                self.decryptList.append(dkey)
                        else:
                            self.decryptList.append(None)
                        if int(addon.getSetting(u'video_type')) == 0:
                            selList_type = {
                                u'low' : __language__(30056), 
                                u'standard' : __language__(30057), 
                                u'high' : __language__(30058)
                            }
                            append = rule.info or rule.extension
                            self.selectionList.append(selList_type[rule.quality] + u' (' + append + u')')
                    elif rule.type == u'dkey':
                        self.dkey = link
                    elif rule.type == u'forward':
                        url = clean_safe(urllib.unquote(link))
                        break
                    elif rule.type.startswith(u'redirect'):
                        tmp_lItem = {u'url': clean_safe(urllib.unquote(link))}
                        if rule.type.find(u"(") != -1:
                            tmp_lItem[u'catcher'] = rule.type[rule.type.find(u"(") + 1:-1]
                        ### need to make the else statement below an elif statement 
                        ### and make the else default to simple-match catcher 
                        else:
                            for root, dirs, files in os.walk(catDir):
                                for filename in files:
                                    if url.find(filename) != -1:
                                        tmp_lItem[u'catcher'] = filename
                        ret_videoItem = CCatcherList(tmp_lItem)
                        if ret_videoItem.videoItem != None:
                            return ret_videoItem
                        break
                    if int(addon.getSetting(u'video_type')) != 0 and rule.priority != 0:
                        break
        return None