📄 common.py
字号:
import os, re, string, sys, time
from string import *
import htmlentitydefs
import xbmc
#===============================================================================
# Make global object available
#===============================================================================
import config
logFile = sys.modules['__main__'].globalLogFile
uriHandler = sys.modules['__main__'].globalUriHandler
#===============================================================================
class clistItem:
def __init__(self, title, url, type="folder", parent=None):
self.name = ConvertHTMLEntities(title)
self.url = url
self.mediaurl = ""
self.description = ""
self.thumb = "" # image of episode
self.thumbUrl = ""
self.icon = "" # icon for list
self.date = ""
self.type = type
self.parent = parent
self.complete = False
self.downloaded = False
self.downloadable = False
self.channels = [] # only needed for Kanalenkiezer
self.items = []
# GUID used for identifcation of the object. Do not set from script
self.guid = ("%s-%s" % (title,url)).replace(" ","")
def Equals(self, item):
return self.guid == item.guid
#===============================================================================
def HTMLEntityConverter(entity):
#logFile.debug("1:%s, 2:%s", entity.group(1), entity.group(2))
try:
if entity.group(1)=='#':
#logFile.debug("%s: %s", entity.group(2), chr(int(entity.group(2))))
return chr(int(entity.group(2)))
return chr(int(tmpHex, 16))
else:
#logFile.debug("%s: %s", entity.group(2), htmlentitydefs.entitydefs[entity.group(2)])
return htmlentitydefs.entitydefs[entity.group(2)]
except:
logFile.error("error converting HTMLEntities", exc_info=True)
return '&%s%s;' % (entity.group(1),entity.group(2))
return entity
#==============================================================================
def ConvertHTMLEntities(html):
"""
Convert the entities in HTML using the HTMLEntityConverter
"""
newHtml = re.sub("&(#?)(.+?);", HTMLEntityConverter, html)
return newHtml
#==============================================================================
def UrlEntityConverter(entity):
"""
Substitutes an HTML/URL entity with the correct character
"""
#logFile.debug("1:%s, 2:%s", entity.group(1), entity.group(2))
try:
tmpHex = '0x%s' % (entity.group(2))
#logFile.debug(int(tmpHex, 16))
return chr(int(tmpHex, 16))
except:
logFile.error("error converting URLEntities", exc_info=True)
return '%s%s' % (entity.group(1),entity.group(2))
#==============================================================================
def ConvertURLEntities(url):
"""
Convert the entities in an URL using the UrlEntityConverter
"""
newUrl = re.sub("(%)([1234567890ABCDEF]{2})", UrlEntityConverter, url)
return newUrl
#===============================================================================
def StripAmp (data):
return replace(data, "&","&")
#===============================================================================
def DoRegexFindAll(regex, data):
try:
result = re.compile(regex, re.DOTALL + re.IGNORECASE)
return result.findall(data)
except:
logFile.critical('error regexing', exc_info=True)
return []
#===============================================================================
def GetSkinFolder():
skinName = xbmc.getSkinDir()
if (os.path.exists(os.path.join(config.rootDir,"skins",skinName))):
skinFolder = skinName
else:
skinFolder = "Default"
logFile.info("Setting Skin to: " + skinFolder)
return skinFolder
#===============================================================================
def DirectoryPrinter(dir):
try:
dirWalker = os.walk(dir)
dirPrint = "Folder Structure of %s" % (config.appName)
for dirWalk in dirWalker:
if dirWalk[0].count("\\.") == 0:
for fileWalk in dirWalk[2]:
if not fileWalk.startswith(".") and not fileWalk.endswith(".pyo"):
dirPrint = "%s\n%s\\%s" % (dirPrint,dirWalk[0],fileWalk)
logFile.debug("%s" % (dirPrint))
except:
logFile.critical("Error printing folder %s", dir)
#===============================================================================
def CacheCleanUp():
try:
deleteCount = 0
fileCount = 0
for item in os.listdir(config.cacheDir):
fileName = os.path.join(config.cacheDir, item)
if os.path.isfile(fileName):
fileCount = fileCount + 1
createTime = os.path.getctime(fileName)
if createTime + config.cacheValidTime < time.time():
os.remove(fileName)
deleteCount = deleteCount + 1
logFile.info("Removed %s of %s files from cache.", deleteCount, fileCount)
except:
logFile.critical("Error cleaning the cachefolder", exc_info=True)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -