def _findItem(self, item):
        title = re.escape(item.getInfo('title'))    
        cfg = item.getInfo('cfg')
        if cfg:
            cfg = re.escape(cfg)
        url = re.escape(item.getInfo('url'))
    
        regex = [\
            '',
            '########################################################',
            '# ' + title.upper(),
            '########################################################',
            'title=' + title,
            '.*?'
            ]
        
        if cfg:
            regex.append('cfg=' + cfg)
        regex.append('url=' + url)
        regex = '(' + '\s*'.join(regex) + ')'
        
        cfgFile = self._favouritesFile
        definedIn = item.getInfo('definedIn')
        if definedIn and definedIn.startswith('favfolders/'):
            cfgFile = os.path.join(self._favouritesFoldersFolder, definedIn.split('/')[1])

        if os.path.exists(cfgFile):
            data = fu.getFileContent(cfgFile)            
            matches = regexUtils.findall(data, regex)
            if matches and len(matches) > 0:
                fav = matches[0]
                return (cfgFile, data, fav)
        return None
def replaceFromDict(dictFilePath, wrd):

    dictionary = getFileContent(dictFilePath)
    dictionary = dictionary.replace('\r\n', '\n')

    p_reg = re.compile('^[^\r\n]+$',
                       re.IGNORECASE + re.DOTALL + re.MULTILINE + re.UNICODE)
    m_reg = p_reg.findall(dictionary)

    word = wrd
    try:
        if m_reg and len(m_reg) > 0:
            index = ''
            words = []
            newword = ''
            for m in m_reg:
                if not m.startswith(' '):
                    index = m
                    del words[:]
                else:
                    replWord = m.strip()
                    words.append(replWord)
                    if word.find(' ') != -1:
                        newword = word.replace(replWord, index)

                if (word in words) or (word == index):
                    return index

            if newword != '' and newword != word:
                return newword
    except:
        common.log('Skipped Replacement: ' + word)

    return word
 def removeCustomModule(self, moduleName):    
     try:
         customCfg = self._customModulesFile
         content = fileUtils.getFileContent(customCfg)
         lines = content.splitlines()
         
         startIdx = -1
         cfgUrl = ''
         for i in range(0, len(lines)):
             if lines[i].startswith("title=%s" % moduleName):
                 startIdx = i
             
             elif startIdx > -1 and lines[i].startswith("url="):
                 tmp = lines[i][4:]
                 cfgUrl = os.path.join(self._customModulesFolder, tmp)
                 break
             
         if os.path.isfile(cfgUrl):
             os.remove(cfgUrl)
             os.remove(cfgUrl.replace(".cfg", ".module"))
             return True
     except:
         pass
     
     return False    
 def moveToFolder(self, cfgFile, item, newCfgFile):
     if os.path.exists(cfgFile) and os.path.exists(newCfgFile):
         fav = self._createFavourite(item)
         old = fu.getFileContent(cfgFile)
         new = old.replace(enc.smart_unicode(fav).encode('utf-8'),'')
         fu.setFileContent(cfgFile, new)
         fu.appendFileContent(newCfgFile, fav)
    def addXbmcFavourite(self):
        fav_dir = xbmc.translatePath( 'special://profile/favourites.xml' )

        # Check if file exists
        if os.path.exists(fav_dir):
            favourites_xml = fu.getFileContent(fav_dir)
            doc = parseString(favourites_xml)
            xbmcFavs = doc.documentElement.getElementsByTagName('favourite')
            menuItems = []
            favItems = []
            for doc in xbmcFavs:
                title = doc.attributes['name'].nodeValue
                menuItems.append(title)
                try:
                    icon = doc.attributes ['thumb'].nodeValue
                except:
                    icon = ''
                url = doc.childNodes[0].nodeValue
                favItem = XbmcFavouriteItem(title, icon, url)
                favItems.append(favItem)

            select = xbmcgui.Dialog().select('Choose' , menuItems)
            if select == -1:
                return False
            else:
                item = favItems[select].convertToCListItem()
                self.addToFavourites(item)
                return True

        common.showInfo('No favourites found')
        return False
 def changeFanart(self, cfgFile, item, newFanart):
     if os.path.exists(cfgFile):
         fav = self._createFavourite(item)
         newfav = self._createFavourite(item, fanart=newFanart)
         old = fu.getFileContent(cfgFile)
         new = old.replace(enc.smart_unicode(fav).encode('utf-8'), enc.smart_unicode(newfav).encode('utf-8'))
         fu.setFileContent(cfgFile, new)
 def changeLabel(self, item, newLabel):
     found = self._findItem(item)
     if found:
         item['title'] = newLabel
         [cfgFile, data, fav] = found
         # if it's a virtual folder, rename file, rename header, update link
         if self._isVirtualFolder(item):           
             url = item.getInfo('url')
             oldFile = self._getFullPath(url)
             newFilename = urllib.quote_plus(fu.cleanFilename(newLabel))
             virtualFolderFile = newFilename + '.cfg'
             physicalFolder = os.path.normpath(self._favouritesFoldersFolder)
             virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile)
             # check if new target is valid
             if os.path.exists(virtualFolderPath):
                 prefix = newFilename + '-'
                 suffix = '.cfg'
                 virtualFolderFile = fu.randomFilename(directory=physicalFolder, prefix=prefix, suffix=suffix)
                 virtualFolderPath = os.path.join(physicalFolder, virtualFolderFile)
             # update header
             content = fu.getFileContent(oldFile)
             oldHeader = self.cfgBuilder.buildHeader(item['title'])
             newHeader = self.cfgBuilder.buildHeader(newLabel)
             content = content.replace(oldHeader, newHeader)
             # rename file
             self._removeVirtualFolder(oldFile, False)
             fu.setFileContent(virtualFolderPath, content)                
             # update link
             item['url'] = self._getShortPath(virtualFolderPath)
         newfav = self._createFavourite(item)
         new = data.replace(fav, enc.smart_unicode(newfav).encode('utf-8'))
         fu.setFileContent(cfgFile, new)
    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 removeCustomModule(self, moduleName):    
        try:
            customCfg = self._customModulesFile
            content = fileUtils.getFileContent(customCfg)
            lines = content.splitlines()
            
            startIdx = -1
            cfgUrl = ''
            for i in range(0, len(lines)):
                if lines[i].startswith("title=%s" % moduleName):
                    startIdx = i
                
                elif startIdx > -1 and lines[i].startswith("url="):
                    tmp = lines[i][4:]
                    cfgUrl = os.path.join(self._customModulesFolder, tmp)
                    break
                
            if os.path.isfile(cfgUrl):
                os.remove(cfgUrl)
                os.remove(cfgUrl.replace(".cfg", ".module"))
                
                # remove all folder that start with cfg name and a dot
                baseDir = os.path.dirname(cfgUrl)
                prefix = os.path.basename(cfgUrl).replace(".cfg", ".")
                dirs = fileUtils.get_immediate_subdirectories(baseDir)
                for d in dirs:
                    if d.startswith(prefix):
                        fileUtils.clearDirectory(os.path.join(baseDir, d))
                        os.removedirs(os.path.join(baseDir, d))

                return True
        except:
            pass
        
        return False    
    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 removeCustomModule(self, moduleName):    
        try:
            customCfg = self._customModulesFile
            content = fileUtils.getFileContent(customCfg)
            lines = content.splitlines()
            
            startIdx = -1
            cfgUrl = ''
            for i in range(0, len(lines)):
                if lines[i].startswith("title=%s" % moduleName):
                    startIdx = i
                
                elif startIdx > -1 and lines[i].startswith("url="):
                    tmp = lines[i][4:]
                    cfgUrl = os.path.join(self._customModulesFolder, tmp)
                    break
                
            if os.path.isfile(cfgUrl):
                os.remove(cfgUrl)
                os.remove(cfgUrl.replace(".cfg", ".module"))
                
                # remove all folder that start with cfg name and a dot
                baseDir = os.path.dirname(cfgUrl)
                prefix = os.path.basename(cfgUrl).replace(".cfg", ".")
                dirs = fileUtils.get_immediate_subdirectories(baseDir)
                for d in dirs:
                    if d.startswith(prefix):
                        fileUtils.clearDirectory(os.path.join(baseDir, d))
                        os.removedirs(os.path.join(baseDir, d))

                return True
        except:
            pass
        
        return False    
Exemple #12
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
Exemple #13
0
    def __replaceCatchers(self, data):
        m_reg = findall(data, self.regex('catch'))
        if not (m_reg is None or len(m_reg) == 0):
            for idat in m_reg:
                if idat.startswith('#'):
                    continue
                ps = idat[7:-2].strip().split(',')
                catcherName = ps.pop(0).strip()

                # import catcher file and insert parameters
                pathImp = os.path.join(common.Paths.catchersDir,
                                       catcherName + '.txt')
                if not (os.path.exists(pathImp)):
                    common.log('Skipped Catcher: ' + catcherName)
                    continue
                dataImp = fu.getFileContent(pathImp)

                for i in range(len(ps)):
                    dataImp = dataImp.replace('@PARAM' + str(i + 1) + '@',
                                              ps.pop(i).strip())

                dataImp = dataImp.replace('\r\n', '\n')
                dataImp += "\nitem_info_name=type\nitem_info_build=video\nitem_url_build=%s"
                data = data.replace(idat, dataImp)
        return data
Exemple #14
0
def replaceFromDict(dictFilePath, wrd):

    dictionary = enc.smart_unicode(getFileContent(dictFilePath))
    dictionary = dictionary.replace('\r\n','\n')

    p_reg = re.compile('^[^\r\n]+$', re.IGNORECASE + re.DOTALL + re.MULTILINE)
    m_reg = p_reg.findall(dictionary)

    word = enc.smart_unicode(wrd).replace(u'Ãœ','Ü').replace(u'Ö','Ö').replace(u'Ä','Ä')
    try:
        if m_reg and len(m_reg) > 0:
            index = ''
            words = []
            newword = ''
            for m in m_reg:
                if not m.startswith(' '):
                    index = m
                    del words[:]
                else:
                    replWord = m.strip()
                    words.append(replWord)
                    if word.find(' ') != -1:
                        newword = word.replace(replWord,index)

                if (word in words) or (word == index):
                    return index

            if newword != '' and newword != word:
                return newword
    except:
        common.log('Skipped Replacement: ' + word)

    return word
    def __init__(self):

        self.simpleScheme = {'(@PLATFORM@)':    os.environ.get('OS'),
                             '(@CURRENT_URL@)': fu.getFileContent(os.path.join(common.Paths.cacheDir, 'lasturl')),
                             '(@LANGUAGE@)':    self.languageShortName(common.language)
                             }

        self.complexScheme = {  'import':     '(#*@IMPORT=([^@]+)@)',
                                'find':       '(#*@FIND\(.*?\)@)',
                                'catch':      '(#*@CATCH\([^\)]+\)@)'
                              }
Exemple #16
0
    def __init__(self):

        self.simpleScheme = {'(@PLATFORM@)':    os.environ.get('OS'),
                             '(@CURRENT_URL@)': fu.getFileContent(os.path.join(common.Paths.cacheDir, 'lasturl')),
                             '(@LANGUAGE@)':    self.languageShortName(common.language)
                             }

        self.complexScheme = {  'import':     '(#*@IMPORT=([^@]+)@)',
                                'find':       '(#*@FIND\(.*?\)@)',
                                'catch':      '(#*@CATCH\([^\)]+\)@)'
                              }
 def _findItem(self, item): 
     cfgFile = self._favouritesFile
     definedIn = item.getInfo('definedIn')
     if definedIn and definedIn.startswith('favfolders/'):
         cfgFile = os.path.join(self._favouritesFolder, definedIn)
     if os.path.exists(cfgFile):
         data = fu.getFileContent(cfgFile)
         regex = self.cfgBuilder.buildItem(re.escape(item.getInfo('title')), "[^#]*", re.escape(item.getInfo('url')))
         matches = regexUtils.findall(data, regex)        
         if matches:
             return (cfgFile, data, matches[0])
     return None
Exemple #18
0
 def install(self, filename):
     destination = xbmc.translatePath(INSTALL_DIR)
     files = self.extract(filename, destination)
     if files:
         addonXml = filter(lambda x: x.filename.endswith('addon.xml'), files)
         if addonXml:
             path = os.path.join(destination, addonXml[0].filename)
             content = getFileContent(path)
             addonId = findall(content, '<addon id="([^"]+)"')
             if addonId:
                 return addonId[0]
     return None
Exemple #19
0
    def __loadLocal(self, filename, lItem=None):
        """Loads cfg, creates list and sets up rules for scraping."""
        params = []

        #get Parameters
        if filename.find('@') != -1:
            params = filename.split('@')
            filename = params.pop(0)

        # get cfg file
        cfg = filename
        if not os.path.exists(cfg):
            cfg = os.path.join(common.Paths.modulesDir, filename)
            if not os.path.exists(cfg):
                tmpPath = os.path.dirname(
                    os.path.join(common.Paths.modulesDir, lItem["definedIn"]))
                cfg = os.path.join(tmpPath, filename)
                if not os.path.exists(cfg):
                    srchFilename = filename
                    if filename.find('/') > -1:
                        srchFilename = srchFilename.split('/')[1]
                    try:
                        cfg = findInSubdirectory(srchFilename,
                                                 common.Paths.modulesDir)
                    except:
                        try:
                            cfg = findInSubdirectory(
                                srchFilename, common.Paths.favouritesFolder)
                        except:
                            try:
                                cfg = findInSubdirectory(
                                    srchFilename,
                                    common.Paths.customModulesDir)
                            except:
                                common.log('File not found: ' + srchFilename)
                                return None

        #load file and apply parameters
        data = getFileContent(cfg)
        data = cr.CustomReplacements().replace(os.path.dirname(cfg), data,
                                               lItem, params)

        #log
        msg = 'Local file ' + filename + ' opened'
        if len(params) > 0:
            msg += ' with Parameter(s): '
            msg += ",".join(params)
        common.log(msg)

        outputList = self.__parseCfg(filename, data, lItem)

        return outputList
    def getSearchPhrase(self):
        searchCache = os.path.join(common.Paths.cacheDir, 'search')
        try:
            curr_phrase = fu.getFileContent(searchCache)
        except:
            curr_phrase = ''
        search_phrase = getKeyboard(default = curr_phrase, heading = common.translate(30102))
        if search_phrase == '':
            return None
        xbmc.sleep(10)
        fu.setFileContent(searchCache, search_phrase)

        return search_phrase
Exemple #21
0
    def getSearchPhrase(self):
        searchCache = os.path.join(common.Paths.cacheDir, 'search')
        default_phrase = fu.getFileContent(searchCache)
        if not default_phrase:
            default_phrase = ''

        search_phrase = common.showOSK(default_phrase, common.translate(30102))
        if search_phrase == '':
            return None
        xbmc.sleep(10)
        fu.setFileContent(searchCache, search_phrase)

        return search_phrase
Exemple #22
0
    def getSearchPhrase(self):
        searchCache = os.path.join(common.Paths.cacheDir, 'search')
        default_phrase = fu.getFileContent(searchCache)
        if not default_phrase:
            default_phrase = ''

        search_phrase = common.showOSK(default_phrase, common.translate(30102))
        if search_phrase == '':
            return None
        xbmc.sleep(10)
        fu.setFileContent(searchCache, search_phrase)

        return search_phrase
Exemple #23
0
 def _findItem(self, item):
     cfgFile = self._favouritesFile
     definedIn = item.getInfo('definedIn')
     if definedIn and definedIn.startswith('favfolders/'):
         cfgFile = os.path.join(self._favouritesFolder, definedIn)
     if os.path.exists(cfgFile):
         data = fu.getFileContent(cfgFile)
         regex = self.cfgBuilder.buildItem(re.escape(item.getInfo('title')),
                                           "[^#]*",
                                           re.escape(item.getInfo('url')))
         matches = regexUtils.findall(data, regex)
         if matches:
             return (cfgFile, data, matches[0])
     return None
    def removeItem(self, item):
        cfgFile = self._favouritesFile
        definedIn = item.getInfo('definedIn')
        if definedIn and definedIn.startswith('favfolders/'):
            cfgFile = os.path.join(self._favouritesFoldersFolder, definedIn.split('/')[1])

        if os.path.exists(cfgFile):
            fav = self._createFavourite(item)
            old = fu.getFileContent(cfgFile)
            new = old.replace(enc.smart_unicode(fav).encode('utf-8'),'')
            fu.setFileContent(cfgFile, new)

            # delete virtual folder
            if self._isVirtualFolder(item):
                self._removeVirtualFolder(item)
 def getCustomModules(self):
     head = [\
         '########################################################',
         '#                    Custom Modules                    #',
         '########################################################',
         ''
         ]        
             
     txt = '\n'.join(head)
     
     self.modules = []
     for root, _, files in os.walk(self._customModulesFolder , topdown = False):
         for name in files:
             if name.endswith('.module'):
                 self.modules.append(name)
                 txt += fileUtils.getFileContent(os.path.join(root, name)) + '\n'
     fileUtils.setFileContent(self._customModulesFile, txt)
 def getCustomModules(self):
     head = [\
         '########################################################',
         '#                    Custom Modules                    #',
         '########################################################',
         ''
         ]        
             
     txt = '\n'.join(head)
     
     self.modules = []
     for root, _, files in os.walk(self._customModulesFolder , topdown = False):
         for name in files:
             if name.endswith('.module'):
                 self.modules.append(name)
                 txt += fileUtils.getFileContent(os.path.join(root, name)) + '\n'
     fileUtils.setFileContent(self._customModulesFile, txt)
Exemple #27
0
    def __loadLocal(self, filename, lItem = None):
        """Loads cfg, creates list and sets up rules for scraping."""
        params = []

        #get Parameters
        if filename.find('@') != -1:
            params = filename.split('@')
            filename = params.pop(0)

        # get cfg file
        cfg = filename
        if not os.path.exists(cfg):
            cfg = os.path.join(common.Paths.modulesDir, filename)
            if not os.path.exists(cfg):
                tmpPath = os.path.dirname(os.path.join(common.Paths.modulesDir, lItem["definedIn"]))
                cfg = os.path.join(tmpPath ,filename)
                if not os.path.exists(cfg):
                    srchFilename = filename
                    if filename.find('/') > -1:
                        srchFilename = srchFilename.split('/')[1]
                    try:
                        cfg = findInSubdirectory(srchFilename, common.Paths.modulesDir)
                    except:
                        try:
                            cfg = findInSubdirectory(srchFilename, common.Paths.favouritesFolder)
                        except:
                            try:
                                cfg = findInSubdirectory(srchFilename, common.Paths.customModulesDir)
                            except:
                                common.log('File not found: ' + srchFilename)
                                return None

        #load file and apply parameters
        data = getFileContent(cfg)
        data = cr.CustomReplacements().replace(os.path.dirname(cfg), data, lItem, params)

        #log
        msg = 'Local file ' +  filename + ' opened'
        if len(params) > 0:
            msg += ' with Parameter(s): '
            msg += ",".join(params)
        common.log(msg)

        outputList = self.__parseCfg(filename, data, lItem)

        return outputList
Exemple #28
0
    def __loadLocal(self, filename, lItem=None):
        params = []

        # get Parameters
        if filename.find("@") != -1:
            params = filename.split("@")
            filename = params.pop(0)

        # get cfg file
        cfg = filename
        if not os.path.exists(cfg):
            cfg = os.path.join(common.Paths.modulesDir, filename)
            if not os.path.exists(cfg):
                tmpPath = os.path.dirname(os.path.join(common.Paths.modulesDir, lItem["definedIn"]))
                cfg = os.path.join(tmpPath, filename)
                if not os.path.exists(cfg):
                    srchFilename = filename
                    if filename.find("/") > -1:
                        srchFilename = srchFilename.split("/")[1]
                    try:
                        cfg = findInSubdirectory(srchFilename, common.Paths.modulesDir)
                    except:
                        try:
                            cfg = findInSubdirectory(srchFilename, common.Paths.favouritesFolder)
                        except:
                            try:
                                cfg = findInSubdirectory(srchFilename, common.Paths.customModulesDir)
                            except:
                                common.log("File not found: " + srchFilename)
                                return None

        # load file and apply parameters
        data = getFileContent(cfg)
        data = cr.CustomReplacements().replace(os.path.dirname(cfg), data, lItem, params)

        # log
        msg = "Local file " + filename + " opened"
        if len(params) > 0:
            msg += " with Parameter(s): "
            msg += ",".join(params)
        common.log(msg)

        outputList = self.__parseCfg(filename, data, lItem)

        return outputList
Exemple #29
0
 def __replaceImports(self, pathToImports, data):
     while True:
         m_reg = findall(data, self.regex('import'))
         if len(m_reg) > 0:
             for idat in m_reg:
                 if idat[0].startswith('#'):
                     data = data.replace(idat[0], '')
                     continue
                 filename = idat[1]
                 pathImp = os.path.join(common.Paths.modulesDir, filename)
                 if not os.path.exists(pathImp):
                     pathImp = os.path.join(pathToImports, filename)
                     if not (os.path.exists(pathImp)):
                         common.log('Skipped Import: ' + filename)
                         continue
                 dataImp = fu.getFileContent(pathImp)
                 dataImp = dataImp.replace('\r\n', '\n')
                 data = data.replace(idat[0], dataImp)
         else:
             break
     return data
 def __replaceImports(self, pathToImports, data):
     while True:
         m_reg = findall(data, self.regex('import'))
         if len(m_reg) > 0:
             for idat in m_reg:
                 if idat[0].startswith('#'):
                     data = data.replace(idat[0],'')
                     continue
                 filename = idat[1]
                 pathImp = os.path.join(self.Paths.modulesDir, filename)
                 if not os.path.exists(pathImp):
                     pathImp = os.path.join(pathToImports, filename)
                     if not (os.path.exists(pathImp)):
                         common.log('Skipped Import: ' + filename)
                         continue
                 dataImp = fu.getFileContent(pathImp)
                 dataImp = dataImp.replace('\r\n','\n')
                 data = data.replace(idat[0], dataImp)
         else:
             break
     return data
    def __replaceCatchers(self, data):
        m_reg = findall(data, self.regex('catch'))
        if not (m_reg is None or len(m_reg) == 0):
            for idat in m_reg:
                if idat.startswith('#'):
                    continue
                ps = idat[7:-2].strip().split(',')
                catcherName = ps.pop(0).strip()

                # import catcher file and insert parameters
                pathImp = os.path.join(self.Paths.catchersDir, catcherName + '.txt')
                if not (os.path.exists(pathImp)):
                    common.log('Skipped Catcher: ' + catcherName)
                    continue
                dataImp = fu.getFileContent(pathImp)
                for i in range(len(ps)):
                    dataImp = dataImp.replace('@PARAM' + str(i+1) + '@',ps.pop(i).strip())

                dataImp = dataImp.replace('\r\n','\n')
                dataImp += "\nitem_info_name=type\nitem_info_build=video\nitem_url_build=%s"
                data = data.replace(idat, dataImp)
        return data
Exemple #32
0
 def changeLabel(self, item, newLabel):
     found = self._findItem(item)
     if found:
         item['title'] = newLabel
         [cfgFile, data, fav] = found
         # if it's a virtual folder, rename file, rename header, update link
         if self._isVirtualFolder(item):
             url = item.getInfo('url')
             oldFile = self._getFullPath(url)
             newFilename = urllib.quote_plus(fu.cleanFilename(newLabel))
             virtualFolderFile = newFilename + '.cfg'
             physicalFolder = os.path.normpath(
                 self._favouritesFoldersFolder)
             virtualFolderPath = os.path.join(physicalFolder,
                                              virtualFolderFile)
             # check if new target is valid
             if os.path.exists(virtualFolderPath):
                 prefix = newFilename + '-'
                 suffix = '.cfg'
                 virtualFolderFile = fu.randomFilename(
                     directory=physicalFolder, prefix=prefix, suffix=suffix)
                 virtualFolderPath = os.path.join(physicalFolder,
                                                  virtualFolderFile)
             # update header
             content = fu.getFileContent(oldFile)
             oldHeader = self.cfgBuilder.buildHeader(item['title'])
             newHeader = self.cfgBuilder.buildHeader(newLabel)
             content = content.replace(oldHeader, newHeader)
             # rename file
             self._removeVirtualFolder(oldFile, False)
             fu.setFileContent(virtualFolderPath, content)
             # update link
             item['url'] = self._getShortPath(virtualFolderPath)
         newfav = self._createFavourite(item)
         new = data.replace(fav, enc.smart_unicode(newfav).encode('utf-8'))
         fu.setFileContent(cfgFile, new)
    def changeLabel(self, cfgFile, item, newLabel):
        if os.path.exists(cfgFile):
            oldfav = self._createFavourite(item)
            old = fu.getFileContent(cfgFile)

            # if it's a virtual folder, change target url too; check if target already exists; rename target
            # (helpful, if you want to edit files manually)

            if self._isVirtualFolder(item):
                url = item.getInfo('url')
                oldTargetFile = os.path.join(self._favouritesFoldersFolder, url.split('/')[1])
                # check if new target is valid
                newTargetFile = os.path.join(self._favouritesFoldersFolder, urllib.quote_plus(newLabel) + '.cfg')
                if os.path.exists(newTargetFile):
                    common.showInfo('Folder already exists')
                    return
                # rename target
                os.rename(oldTargetFile, newTargetFile)
                # update target url
                item.setInfo('url', 'favfolders/' + urllib.quote_plus(newLabel) + '.cfg')

            newfav = self._createFavourite(item, title=newLabel)
            new = old.replace(enc.smart_unicode(oldfav).encode('utf-8'), enc.smart_unicode(newfav).encode('utf-8'))
            fu.setFileContent(cfgFile, new)
Exemple #34
0
    def __parseCommands(self, item, src, convCommands):
        common.log('_parseCommands called')
        # helping function
        def parseCommand(txt):
            command = {"command": txt, "params": ""}
            if txt.find("(") > -1:
                command["command"] = txt[0:txt.find("(")]
                command["params"] = txt[len(command["command"]) + 1:-1]
            return command
        
        for convCommand in convCommands:
            pComm = parseCommand(convCommand)
            command = pComm["command"]
            params = pComm["params"]

            if params.find('@REFERER@'):
                referer = item['referer']
                if not referer:
                    referer = ''
                params = params.replace('@REFERER@', referer)

            if command == 'convDate':
                src = cc.convDate(params, src)

            elif command =='currenturl':
                print("--------------curenturl ------------------------")
                src= getFileContent(os.path.join(common.Paths.cacheDir, 'lasturl'))
                print("--------------curenturl ------------------------",src)

            elif command == 'convTimestamp':
                src = cc.convTimestamp(params, src)

            elif command == 'select':
                src = cc.select(params, src)
                if not src:
                    continue

            elif command == 'unicode_escape':
                src = src.decode('unicode-escape')

            elif command == 'replaceFromDict':
                dictName = str(params.strip('\''))
                path = os.path.join(common.Paths.dictsDir, dictName + '.txt')
                if not (os.path.exists(path)):
                    common.log('Dictionary file not found: ' + path)
                    continue
                src = cc.replaceFromDict(path, src)

            elif command == 'time':
                src = time.time()

            elif command == 'timediff':
                src = dt.timediff(src,params.strip('\''))

            elif command == 'offset':
                src = cc.offset(params, src)

            elif command == 'getSource':
                src = cc.getSource(params, src)

            elif command == 'quote':
                try:
                    src = urllib.quote(params.strip("'").replace('%s', src),'')
                except:
                    cleanParams = params.strip("'")
                    cleanParams = cleanParams.replace("%s",src)
                    src = urllib.quote(cleanParams.encode('utf-8'),'')

            elif command == 'unquote':
                src = urllib.unquote(params.strip("'").replace('%s', src))

            elif command == 'parseText':
                src = cc.parseText(item, params, src)

            elif command == 'getInfo':
                src = cc.getInfo(item, params, src)
            
            elif command == 'getXML':
                src = cc.getInfo(item, params, src, xml=True)
                
            elif command == 'getMobile':
                src = cc.getInfo(item, params, src, mobile=True)

            elif command == 'decodeBase64':
                src = cc.decodeBase64(src)

            elif command == 'decodeRawUnicode':
                src = cc.decodeRawUnicode(src)
                
            elif command == 'resolve':
                src = cc.resolve(src)
            
            elif command == 'decodeXppod':
                src = cc.decodeXppod(src)
            
            elif command == 'decodeXppodHLS':
                src = cc.decodeXppod_hls(src)

            elif command == 'replace':
                src = cc.replace(params, src)

            elif command == 'replaceRegex':
                src = cc.replaceRegex(params, src)

            elif command == 'ifEmpty':
                src = cc.ifEmpty(item, params, src)

            elif command == 'isEqual':
                src = cc.isEqual(item, params, src)

            elif command == 'ifFileExists':
                src = cc.ifFileExists(item, params, src)

            elif command == 'ifExists':
                src = cc.ifExists(item, params, src)

            elif command == 'encryptJimey':
                src = crypt.encryptJimey(params.strip("'").replace('%s', src))

            elif command == 'gAesDec':
                src = crypt.gAesDec(src,item.infos[params])
            
            elif command == 'aesDec':
                src = crypt.aesDec(src,item.infos[params])
                
            elif command == 'getCookies':
                src = cc.getCookies(params, src)

            elif command == 'destreamer':
                src = crypt.destreamer(params.strip("'").replace('%s', src))

            elif command == 'unixTimestamp':
                src = dt.getUnixTimestamp()
                
            elif command == 'rowbalance':
                src = rb.get()

            elif command == 'urlMerge':
                src = cc.urlMerge(params, src)

            elif command == 'translate':
                try:
                    src = common.translate(int(src))
                except:
                    pass

            elif command == 'camelcase':
                src = string.capwords(string.capwords(src, '-'))
                
            elif command == 'lowercase':
                src = string.lower(src)
                
            elif command == 'reverse':
                src = src[::-1]
                
            elif command == 'demystify':
                print 'demystify'
                src = crypt.doDemystify(src)
                print 'after demystify',src

            elif command == 'random':
                paramArr = params.split(',')
                minimum = int(paramArr[0])
                maximum = int(paramArr[1])
                src = str(random.randrange(minimum,maximum))

            elif command == 'debug':
                common.log('Debug from cfg file: ' + src)
                
            elif command == 'divide':
                paramArr = params.split(',')
                a = paramArr[0].strip().strip("'").replace('%s', src)
                a = resolveVariable(a, item)
                b = paramArr[1].strip().strip("'").replace('%s', src)
                b = resolveVariable(b, item)
                
                if not a or not b:
                    continue
                
                a = int(a)
                b = int(b)
                try:
                    src = str(a/b)
                except:
                    pass
                
        return src
Exemple #35
0
    def __parseCommands(self, item, src, convCommands):
        common.log('_parseCommands called')

        #common.log('_parseCommands called %s | %s | %s' % (item,src, convCommands))

        # helping function
        def parseCommand(txt):
            command = {"command": txt, "params": ""}
            if txt.find("(") > -1:
                command["command"] = txt[0:txt.find("(")]
                command["params"] = txt[len(command["command"]) + 1:-1]
            return command

        for convCommand in convCommands:
            pComm = parseCommand(convCommand)
            command = pComm["command"]
            params = pComm["params"]

            if params.find('@REFERER@'):
                referer = item['referer']
                if not referer:
                    referer = ''
                params = params.replace('@REFERER@', referer)

            if command == 'convDate':
                src = cc.convDate(params, src)

            elif command == 'currenturl':
                print("--------------curenturl ------------------------")
                src = getFileContent(
                    os.path.join(common.Paths.cacheDir, 'lasturl'))
                print("--------------curenturl ------------------------", src)

            elif command == 'iklub':
                common.log('--------------ikulb ------------------------')
                common.log('src: %s' % src)
                src = cc.decodeIklub(src)
                common.log('src: %s' % src)
                #common.log('--------------ikulb ------------------------')
            elif command == 'decodemrknow2':
                common.log(
                    '--------------decodemrknow2 ------------------------')
                #common.log('src: %s' % src)
                src = cc.decodeMrknow2(src)
                #common.log('src: %s' % src)
            elif command == 'convTimestamp':
                src = cc.convTimestamp(params, src)

            elif command == 'select':
                src = cc.select(params, src)
                if not src:
                    continue

            elif command == 'unicode_escape':
                src = src.decode('unicode-escape')

            elif command == 'replaceFromDict':
                dictName = str(params.strip('\''))
                path = os.path.join(common.Paths.dictsDir, dictName + '.txt')
                if not (os.path.exists(path)):
                    common.log('Dictionary file not found: ' + path)
                    continue
                src = cc.replaceFromDict(path, src)

            elif command == 'time':
                src = time.time()

            elif command == 'timediff':
                src = dt.timediff(src, params.strip('\''))

            elif command == 'offset':
                src = cc.offset(params, src)

            elif command == 'getSource':
                src = cc.getSource(params, src)

            elif command == 'quote':
                try:
                    src = urllib.quote(
                        params.strip("'").replace('%s', src), '')
                except:
                    cleanParams = params.strip("'")
                    cleanParams = cleanParams.replace("%s", src)
                    src = urllib.quote(cleanParams.encode('utf-8'), '')

            elif command == 'unquote':
                src = urllib.unquote(params.strip("'").replace('%s', src))

            elif command == 'parseText':
                src = cc.parseText(item, params, src)

            elif command == 'getInfo':
                src = cc.getInfo(item, params, src)

            elif command == 'getXML':
                src = cc.getInfo(item, params, src, xml=True)

            elif command == 'getMobile':
                src = cc.getInfo(item, params, src, mobile=True)

            elif command == 'decodeBase64':
                src = cc.decodeBase64(src)

            elif command == 'decodeRawUnicode':
                src = cc.decodeRawUnicode(src)

            elif command == 'resolve':
                src = cc.resolve(src)

            elif command == 'decodeXppod':
                src = cc.decodeXppod(src)

            elif command == 'decodeXppodHLS':
                src = cc.decodeXppod_hls(src)

            elif command == 'decodeMrknow1':
                src = cc.decodeMrknow1(src)

            elif command == 'replace':
                src = cc.replace(params, src)

            elif command == 'replaceRegex':
                src = cc.replaceRegex(params, src)

            elif command == 'ifEmpty':
                src = cc.ifEmpty(item, params, src)

            elif command == 'isEqual':
                src = cc.isEqual(item, params, src)

            elif command == 'ifFileExists':
                src = cc.ifFileExists(item, params, src)

            elif command == 'ifExists':
                src = cc.ifExists(item, params, src)

            elif command == 'encryptJimey':
                src = crypt.encryptJimey(params.strip("'").replace('%s', src))

            elif command == 'gAesDec':
                src = crypt.gAesDec(src, item.infos[params])

            elif command == 'aesDec':
                src = crypt.aesDec(src, item.infos[params])

            elif command == 'getCookies':
                src = cc.getCookies(params, src)

            elif command == 'destreamer':
                src = crypt.destreamer(params.strip("'").replace('%s', src))

            elif command == 'unixTimestamp':
                src = dt.getUnixTimestamp()

            elif command == 'rowbalance':
                src = rb.get()

            elif command == 'urlMerge':
                src = cc.urlMerge(params, src)

            elif command == 'translate':
                try:
                    src = common.translate(int(src))
                except:
                    pass

            elif command == 'camelcase':
                src = string.capwords(string.capwords(src, '-'))

            elif command == 'lowercase':
                src = string.lower(src)

            elif command == 'reverse':
                src = src[::-1]

            elif command == 'demystify':
                print 'demystify'
                src = crypt.doDemystify(src)
                print 'after demystify', src

            elif command == 'random':
                paramArr = params.split(',')
                minimum = int(paramArr[0])
                maximum = int(paramArr[1])
                src = str(random.randrange(minimum, maximum))

            elif command == 'debug':
                common.log('--------------debug ------------------------')
                common.log('Debug from cfg file: ' + src)

            elif command == 'divide':
                paramArr = params.split(',')
                a = paramArr[0].strip().strip("'").replace('%s', src)
                a = resolveVariable(a, item)
                b = paramArr[1].strip().strip("'").replace('%s', src)
                b = resolveVariable(b, item)

                if not a or not b:
                    continue

                a = int(a)
                b = int(b)
                try:
                    src = str(a / b)
                except:
                    pass

        return src