📄 plugin.py
字号:
from atexit import register
import uriopener
import xbmcplugin, xbmc, xbmcgui
import sys, os, traceback
import string
from string import*
import urllib
from string import *
import sys, traceback
import pickle
#sys.path.append(os.path.join(os.getcwd().replace(";",""),'libs'))
#===============================================================================
# Import XOT stuff
#===============================================================================
try:
import config
import common
logFile = sys.modules['__main__'].globalLogFile
uriHandler = sys.modules['__main__'].globalUriHandler
#register for channels
channelRegister = []
except:
globalLogFile.critical("Error initializing %s", config.appName, exc_info=True)
#===============================================================================
# Main Plugin Class
#===============================================================================
class XotPlugin:
"""
Main Plugin Class
"""
def __init__(self, *args, **kwargs):
logFile.info("*********** Starting %s plugin version v%s ***********", config.appName, config.version)
logFile.debug(sys.argv)
self.pluginName = sys.argv[0]
self.handle = int(sys.argv[1])
self.params = sys.argv[2].strip('?')
# channel objects
self.channelObject = ""
self.channelFile = ""
self.channelCode = ""
self.channelObject = ""
#logFile.debug(self.params)
#===============================================================================
# Start the plugin version of progwindow
#===============================================================================
if self.params=='':
# check for updates
import update
try:
update.CheckVersion(config.version, config.updateUrl)
logFile.CleanUpLog()
except:
logFile.critical("Error checking for updates", exc_info=True)
# now show the list
self.ShowProgramList()
#===============================================================================
# Start the plugin verion of the episode window
#===============================================================================
else:
try:
# determine what stage we are in. Therefore we split the
# params and check the number of different ones.
self.params = self.params.split('|')
logFile.debug(self.params)
# Check that there are more than 2 Parameters
if len(self.params)>1:
# retrieve channel characteristics
self.channelFile = os.path.splitext(self.params[0])[0]
self.channelCode = self.params[1]
#logFile.debug(self.channelCode)
# import the channel
self.channelDir = os.path.join(config.rootDir, "channels", self.channelFile.replace('chn_', ''))
sys.path.append(self.channelDir)
logFile.info("Importing %s from %s", self.channelFile, self.channelDir)
exec("import %s" % self.channelFile)
logFile.debug(channelRegister)
if len(channelRegister)==1:
logFile.info("Only one channel present. Intialising it.")
self.channelObject = eval(channelRegister[0])
else:
#determine from channelCode
for channel in channelRegister:
#logFile.debug("%s (%s)", channel,string.count(channel, 'channelCode="%s"' % (self.channelCode))>0)
if string.count(channel, "channelCode=\"%s" % self.channelCode)>0:
logFile.debug("caught: %s", channel)
self.channelObject = eval(channel)
break
if self.channelObject == "":
logFile.critical("No channel found to be loaded!")
return
# init the channel as plugin
self.channelObject.initPlugin()
logFile.info("Loaded: %s", self.channelObject.channelName)
else:
logFile.critical("Error determining Plugin action")
return
#===============================================================================
# See what needs to be done.
#===============================================================================
if len(self.params)==2:
# only the channelName and code is present, so ParseMainList is needed
self.ParseMainList()
elif len(self.params)==3:
# channelName and URL is present, Parse the folder
self.ProcessFolderList()
elif len(self.params)>3 and self.params[2]=='processVideo':
# a videoitem was given with an additional paramters
self.ProcessVideoItem()
elif len(self.params)>3 and self.params[2]=='downloadVideo':
# download the item
self.DownloadVideoItem()
#if self.handle > -1:
# xbmcplugin.endOfDirectory(self.handle)
except:
logFile.critical("Error parsing for plugin", exc_info=True)
#xbmcplugin.endOfDirectory(self.handle)
#==============================================================================
def ShowProgramList(self):
logFile.info("Plugin::ShowProgramList")
try:
# import ProgWindow
import progwindow
ok = False
# first start of plugin! Show channels only!
if len(self.params)<=2:
#only display channels
progWindowLib = progwindow.GUI(config.appSkin ,config.rootDir, config.skinFolder)
for channelGUI in progWindowLib.channelGUIs:
item = xbmcgui.ListItem(channelGUI.channelName,channelGUI.channelDescription, channelGUI.icon , channelGUI.iconLarge)
item.setInfo("video", {"tracknumber": str(channelGUI.sortOrder), "Tagline":channelGUI.channelDescription})
logFile.debug(channelGUI.sortOrder)
ok = xbmcplugin.addDirectoryItem(self.handle, "%s?%s|%s" % (self.pluginName, channelGUI.moduleName, channelGUI.channelCode), item, isFolder=True)
#xbmcplugin.addDirectoryItem(self.handle, "%s?%s|%s" % (self.pluginName, channelGUI.moduleName, channelGUI.channelCode), item, isFolder=False)
if (not ok): break
xbmcplugin.addSortMethod(handle=self.handle, sortMethod=xbmcplugin.SORT_METHOD_TRACKNUM)
#xbmcplugin.setContent(handle=self.handle, content="video")
#xbmcplugin.addSortMethod(handle=self.handle, sortMethod=xbmcplugin.SORT_METHOD_FILE)
xbmcplugin.endOfDirectory(self.handle, ok)
except:
xbmcplugin.endOfDirectory(self.handle, False)
logFile.critical("Error fetching channels for plugin", exc_info=True)
#==============================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -