def search(query): global __key__ if len(__key__)< 1: __addon__.openSettings() __key__ = getkey() params = {"key": __key__} if "imdb_id" in query: params["imdb"] = query['imdb_id'].replace("tt","") if "season" in query: params["search_str"] = "%(title)s [Season %(season)2d/Episode%(episode)2d]" % query if getsettings() != ",": params['categtags'] = getsettings() if "title" in query: title = query["title"] else: title = query params["search_str"] = query.encode("utf8") response = provider.GET("http://87.248.186.252/rss.php", params) notify("Total files:" + str(len(re.findall(r'magnet:\?[^\'"\s<>\[\]]+', response.data))), title.encode("utf8") ,10000, __addon__.getAddonInfo('icon')) return provider.extract_magnets(response.data)
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("Pulsar has crashed, restarting...", time=1000) 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 reset_rpc(): try: data = [{"method": "Reset", "params": [{}], "jsonrpc": "2.0"}] req = urllib2.Request(PULSARD_EXT_HOST, json.dumps(data), {"Content-type": "application/json"}) urllib2.urlopen(req) except Exception as e: notify("%s" % e)
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 pulsard_thread(): 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]).start() while proc.poll() is None: log.info(proc.stdout.readline()) if proc.returncode == 0 or xbmc.abortRequested: break notify("Pulsar has crashed, restarting...", time=1000)
def reset_rpc(): try: data = [{ "method": "Reset", "params": [{}], "jsonrpc": "2.0" }] req = urllib2.Request(PULSARD_EXT_HOST, json.dumps(data), {"Content-type": "application/json"}) urllib2.urlopen(req) except Exception as e: notify("%s" % e)
def run(url_suffix=""): 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 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)
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() while proc.poll() is None: log.info(proc.stdout.readline()) if proc.returncode == 0 or xbmc.abortRequested: break notify("Pulsar has crashed, restarting...", time=1000) except Exception, e: import xbmc import traceback map(xbmc.log, traceback.format_exc().split("\n")) raise
def getkey(): user = __addon__.getSetting("user") password = __addon__.getSetting("password") postData = {'username': user, 'password' : password, 'autologin' : '1'} response = provider.POST("http://87.248.186.252/takelogin.php", postData) if response.data.find('user_box') > 0: response = provider.GET("http://87.248.186.252/browse.php") data = response.data.decode("utf-8") for key in re.findall(r'rss\.php\?key=[^\'"\s<>\[\]]+', data): notify("Successfully logged in", "User: "******"utf8") , 10000, __addon__.getAddonInfo('icon')) __addon__.setSetting(id='key', value=key.replace('rss.php?key=','')) return key.replace('rss.php?key=','') else: notify("", "Login failed " + user.encode("utf8") ,10000) __addon__.setSetting(id='key', value="")
def run(url_suffix=""): 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 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)
def register(search, search_movie, search_episode): import base64 import json import sys try: payload = json.loads(base64.b64decode(sys.argv[1])) except: notify("This addon can only be run from within Pulsar", time=1000) return results = () method = { "search": search, "search_movie": search_movie, "search_episode": search_episode, }.get(payload["method"]) or (lambda *a, **kw: []) try: results = tuple(method(payload["search_object"])) finally: urllib2.urlopen(payload["callback_url"], data=json.dumps(results))
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 main(): 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(os.path.dirname(__file__), ".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) + sys.argv[2] 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"], 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)
def Notify(self, header, message, image): return notify(GetLocalizedStrings(message), header, 3000, image)
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"): context = item["context_menu"] context.append([ 'Trailers', 'XBMC.PlayMedia("plugin://plugin.video.youtube/kodion/search/query/?q=\"%s\" trailer",isdir)' % item["label"] ]) listItem.addContextMenuItems(context) 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)