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
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) )
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
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)
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
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) reset_rpc() time.sleep(3) except Exception, e: import xbmc import traceback map(xbmc.log, traceback.format_exc().split("\n")) raise
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))
def GetLocalizedString(self, *args, **kwargs): return ADDON.getLocalizedString(*args, **kwargs).encode('utf-8')
def GetLocalizedString(label): try: return ADDON.getLocalizedString(int(label[9:-1])).encode('utf-8') except: return label