本文整理汇总了Python中pulsar.addon.ADDON类的典型用法代码示例。如果您正苦于以下问题:Python ADDON类的具体用法?Python ADDON怎么用?Python ADDON使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ADDON类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_pulsar_binary
def get_pulsar_binary():
binary = "pulsar" + (PLATFORM["os"] == "windows" and ".exe" or "")
platform = PLATFORM.copy()
if platform["os"] == "darwin": # 64 bits anyway on Darwin
platform["arch"] = "x64"
elif platform["os"] == "windows": # 32 bits anyway on Windows
platform["arch"] = "x86"
binary_dir = os.path.join(ADDON.getAddonInfo("path"), "resources", "bin", "%(os)s_%(arch)s" % platform)
if platform["os"] == "android":
app_id = android_get_current_appid()
xbmc_data_path = os.path.join("/data", "data", app_id)
if os.path.exists(xbmc_data_path) and uid == os.stat(xbmc_data_path).st_uid:
binary_dir = os.path.join(xbmc_data_path, "files", ADDON_ID)
else:
dest_binary_dir = os.path.join(xbmc.translatePath(ADDON.getAddonInfo("profile")), "bin", "%(os)s_%(arch)s" % platform)
binary_path = os.path.join(binary_dir, binary)
dest_binary_path = os.path.join(dest_binary_dir, binary)
# Testing for size to see if update is needed. This is a poor test indeed, but it's sufficient.
if not os.path.exists(dest_binary_path) or os.path.getsize(dest_binary_path) != os.path.getsize(binary_path):
log.info("pulsar daemon is outdated, updating...")
import shutil
try:
os.makedirs(dest_binary_dir)
except OSError:
pass
shutil.rmtree(dest_binary_dir)
shutil.copytree(binary_dir, dest_binary_dir)
return dest_binary_dir, ensure_exec_perms(dest_binary_path)
示例2: get_pulsar_binary
def get_pulsar_binary():
binary = "pulsar" + (PLATFORM["os"] == "windows" and ".exe" or "")
platform = PLATFORM.copy()
if platform["os"] == "darwin": # 64 bits anyway on Darwin
platform["arch"] = "x64"
elif platform["os"] == "windows": # 32 bits anyway on Windows
platform["arch"] = "x86"
binary_dir = os.path.join(ADDON.getAddonInfo("path"), "resources", "bin", "%(os)s_%(arch)s" % platform)
if platform["os"] == "android":
app_id = android_get_current_appid()
xbmc_data_path = os.path.join("/data", "data", app_id)
dest_binary_dir = os.path.join(xbmc_data_path, "files", ADDON_ID, "bin", "%(os)s_%(arch)s" % platform)
else:
dest_binary_dir = os.path.join(xbmc.translatePath(ADDON.getAddonInfo("profile")), "bin", "%(os)s_%(arch)s" % platform)
binary_path = os.path.join(binary_dir, binary)
dest_binary_path = os.path.join(dest_binary_dir, binary)
if not os.path.exists(dest_binary_path) or get_pulsard_checksum(dest_binary_path) != get_pulsard_checksum(binary_path):
log.info("Updating pulsar daemon...")
import shutil
try:
os.makedirs(dest_binary_dir)
except OSError:
pass
try:
shutil.rmtree(dest_binary_dir)
except:
pass
shutil.copytree(binary_dir, dest_binary_dir)
return dest_binary_dir, ensure_exec_perms(dest_binary_path)
示例3: run
def run(url_suffix=""):
if not os.path.exists(os.path.join(xbmc.translatePath(ADDON.getAddonInfo("path")), ".firstrun")):
notify(ADDON.getLocalizedString(30101).encode('utf-8'))
return
socket.setdefaulttimeout(300)
urllib2.install_opener(urllib2.build_opener(NoRedirectHandler()))
url = sys.argv[0].replace("plugin://%s" % ADDON_ID, PULSARD_HOST + url_suffix) + sys.argv[2]
xbmc.log(url)
try:
data = _json(url)
except:
return
if not data:
return
if data["content_type"]:
xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_DATE)
xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_GENRE)
xbmcplugin.setContent(HANDLE, data["content_type"])
listitems = range(len(data["items"]))
for i, item in enumerate(data["items"]):
# Translate labels
if item["label"][0:8] == "LOCALIZE":
item["label"] = GetLocalizedString(item["label"])
if item["label2"][0:8] == "LOCALIZE":
item["label2"] = GetLocalizedString(item["label2"])
listItem = xbmcgui.ListItem(label=item["label"], label2=item["label2"], iconImage=item["icon"], thumbnailImage=item["thumbnail"])
if item.get("info"):
listItem.setInfo("video", item["info"])
if item.get("stream_info"):
for type_, values in item["stream_info"].items():
listItem.addStreamInfo(type_, values)
if item.get("art"):
listItem.setArt(item["art"])
if item.get("context_menu"):
# Translate context menus
print "Before: %s" % item["context_menu"]
for m, menu in enumerate(item["context_menu"]):
if menu[0][0:8] == "LOCALIZE":
menu[0] = GetLocalizedString(menu[0])
print "After: %s" % item["context_menu"]
listItem.addContextMenuItems(item["context_menu"])
listItem.setProperty("isPlayable", item["is_playable"] and "true" or "false")
if item.get("properties"):
for k, v in item["properties"].items():
listItem.setProperty(k, v)
listitems[i] = (item["path"], listItem, not item["is_playable"])
xbmcplugin.addDirectoryItems(HANDLE, listitems, totalItems=len(listitems))
xbmcplugin.endOfDirectory(HANDLE, succeeded=True, updateListing=False, cacheToDisc=True)
示例4: GetLocalizedStrings
def GetLocalizedStrings(label):
ids = re.compile('LOCALIZE\[(\d+)\]').findall(label)
if ids:
if label == 'LOCALIZE[%s]' % ids[0]:
return ADDON.getLocalizedString(int(ids[0])).encode('utf-8')
for id in ids:
LocalizedString = ADDON.getLocalizedString(int(id)).encode('utf-8')
label = label.replace('LOCALIZE[%s]' % id, LocalizedString)
return label
示例5: get_pulsar_binary
def get_pulsar_binary():
binary = "pulsar" + (PLATFORM["os"] == "windows" and ".exe" or "")
platform = PLATFORM.copy()
if platform["os"] == "darwin": # 64 bits anyway on Darwin
platform["arch"] = "x64"
elif platform["os"] == "windows": # 32 bits anyway on Windows
platform["arch"] = "x86"
binary_dir = os.path.join(ADDON.getAddonInfo("path"), "resources", "bin", "%(os)s_%(arch)s" % platform)
if platform["os"] == "android":
binary_dir = binary_dir.replace("/storage/emulated/0", "/storage/emulated/legacy")
app_id = android_get_current_appid()
xbmc_data_path = os.path.join("/data", "data", app_id)
dest_binary_dir = os.path.join(xbmc_data_path, "files", ADDON_ID, "bin", "%(os)s_%(arch)s" % platform)
else:
dest_binary_dir = os.path.join(xbmc.translatePath(ADDON.getAddonInfo("profile")), "bin", "%(os)s_%(arch)s" % platform)
try:
binary_dir = binary_dir.decode("latin1")
dest_binary_dir = dest_binary_dir.decode("latin1")
except UnicodeEncodeError:
log.info("Unable to decode: binary_dir=%s dest_binary_dir=%s" % (repr(binary_dir), repr(dest_binary_dir)))
binary_path = os.path.join(binary_dir, binary)
dest_binary_path = os.path.join(dest_binary_dir, binary)
if not os.path.exists(dest_binary_path) or get_pulsard_checksum(dest_binary_path) != get_pulsard_checksum(binary_path):
log.info("Updating pulsar daemon...")
try:
os.makedirs(dest_binary_dir)
except OSError:
pass
try:
shutil.rmtree(dest_binary_dir)
except:
pass
shutil.copytree(binary_dir, dest_binary_dir)
# Clean stale files in the directory, as this can cause headaches on
# Android when they are unreachable
dest_files = set(os.listdir(dest_binary_dir))
orig_files = set(os.listdir(binary_dir))
log.info("Deleting stale files %s" % (dest_files - orig_files))
for file_ in (dest_files - orig_files):
path = os.path.join(dest_binary_dir, file_)
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.remove(path)
return dest_binary_dir, ensure_exec_perms(dest_binary_path)
示例6: run
def run(url_suffix=""):
if not os.path.exists(os.path.join(xbmc.translatePath(ADDON.getAddonInfo("path")), ".firstrun")):
notify(ADDON.getLocalizedString(30101).encode('utf-8'))
return
socket.setdefaulttimeout(300)
urllib2.install_opener(urllib2.build_opener(NoRedirectHandler()))
url = sys.argv[0].replace("plugin://%s" % ADDON_ID, PULSARD_HOST + url_suffix) + sys.argv[2]
xbmc.log(url)
try:
data = _json(url)
except urllib2.HTTPError, e:
return
示例7: GetAddonInfo
def GetAddonInfo(self):
info = {}
for key in ("author", "changelog", "description", "disclaimer",
"fanart", "icon", "id", "name", "path", "profile", "stars",
"summary", "type", "version"):
info[key] = ADDON.getAddonInfo(key)
return info
示例8: register
def register(search, search_movie, search_episode):
import base64
import json
import sys
try:
payload = json.loads(base64.b64decode(sys.argv[1]))
except:
notify(ADDON.getLocalizedString(30102).encode('utf-8'), time=1000)
return
results = ()
method = {
"search": search,
"search_movie": search_movie,
"search_episode": search_episode,
}.get(payload["method"]) or (lambda *a, **kw: [])
try:
results = ()
objects = method(payload["search_object"])
if objects is not None:
results = tuple(objects)
finally:
urllib2.urlopen(
payload["callback_url"],
data=json.dumps(results)
)
示例9: pulsard_thread
def pulsard_thread(monitor):
try:
import xbmc
while not xbmc.abortRequested:
log.info("pulsard: starting pulsard")
proc = start_pulsard(stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
threading.Thread(target=wait_for_abortRequested, args=[proc, monitor]).start()
if PLATFORM["os"] == "windows":
while proc.poll() is None:
log.info(proc.stdout.readline())
else:
# Kodi hangs on some Android (sigh...) systems when doing a blocking
# read. We count on the fact that Pulsar daemon flushes its log
# output on \n, creating a pretty clean output
import fcntl
fd = proc.stdout.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
while proc.poll() is None:
try:
log.info(proc.stdout.readline())
continue
except IOError:
time.sleep(1) # nothing to read, sleep
if proc.returncode == 0 or xbmc.abortRequested:
break
notify(ADDON.getLocalizedString(30100).encode('utf-8'), time=1000)
time.sleep(3)
except Exception:
import xbmc
import traceback
map(xbmc.log, traceback.format_exc().split("\n"))
raise
示例10: run
def run(url_suffix=""):
if ("%(os)s_%(arch)s" % PLATFORM) not in [
"windows_x86",
"darwin_x64",
"linux_x86", "linux_x64", "linux_arm",
]:
from pulsar.util import notify
notify("Pulsar is compatible only with Windows, Linux and OS X")
return
if not os.path.exists(os.path.join(xbmc.translatePath(ADDON.getAddonInfo("path")), ".firstrun")):
from pulsar.util import notify
notify("You must restart XBMC before using Pulsar")
return
if PLATFORM["os"] not in ["windows", "linux", "darwin"]:
from pulsar.util import notify
notify("Pulsar is compatible only with Windows, Linux and OS X")
return
socket.setdefaulttimeout(300)
urllib2.install_opener(urllib2.build_opener(NoRedirectHandler()))
url = sys.argv[0].replace("plugin://%s" % ADDON_ID, PULSARD_HOST + url_suffix) + sys.argv[2]
xbmc.log(url)
data = _json(url)
if not data:
return
if data["content_type"]:
xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_DATE)
xbmcplugin.addSortMethod(HANDLE, xbmcplugin.SORT_METHOD_GENRE)
xbmcplugin.setContent(HANDLE, data["content_type"])
listitems = range(len(data["items"]))
for i, item in enumerate(data["items"]):
listItem = xbmcgui.ListItem(label=item["label"], label2=item["label2"], iconImage=item["icon"], thumbnailImage=item["thumbnail"])
if item.get("info"):
listItem.setInfo("video", item["info"])
if item.get("stream_info"):
for type_, values in item["stream_info"].items():
listItem.addStreamInfo(type_, values)
if item.get("art"):
listItem.setArt(item["art"])
if item.get("context_menu"):
listItem.addContextMenuItems(item["context_menu"])
listItem.setProperty("isPlayable", item["is_playable"] and "true" or "false")
if item.get("properties"):
for k, v in item["properties"].items():
listItem.setProperty(k, v)
listitems[i] = (item["path"], listItem, not item["is_playable"])
xbmcplugin.addDirectoryItems(HANDLE, listitems, totalItems=len(listitems))
xbmcplugin.endOfDirectory(HANDLE, succeeded=True, updateListing=False, cacheToDisc=True)
示例11: get_setting
def get_setting(key, converter=str, choices=None):
value = ADDON.getSetting(id=key)
if converter is str:
return value
elif converter is unicode:
return value.decode('utf-8')
elif converter is bool:
return value == 'true'
elif converter is int:
return int(value)
elif isinstance(choices, (list, tuple)):
return choices[int(value)]
else:
raise TypeError('Acceptable converters are str, unicode, bool and '
'int. Acceptable choices are instances of list '
' or tuple.')
示例12: SetSetting
def SetSetting(self, *args, **kwargs):
return ADDON.setSetting(*args, **kwargs)
示例13: GetSetting
def GetSetting(self, *args, **kwargs):
return ADDON.getSetting(*args, **kwargs)
示例14: GetLocalizedString
def GetLocalizedString(self, *args, **kwargs):
return ADDON.getLocalizedString(*args, **kwargs).encode('utf-8')
示例15: notify
def notify(message='', header=None, time=5000, image=''):
if header is None:
header = ADDON.getAddonInfo("name")
xbmc.executebuiltin('Notification("%s", "%s", "%d", "%s")' %
(header, message, time, image))