示例#1
0
    def getfile(self):
        location = gui.select("Location", ["Local", "Remote"], multi=False)
        if location == 0:
            path = gui.browse(1, "Select File")
            try:
                with open(path, "r") as f:
                    return f.read()
            except Exception:
                pass
        elif location == 1:
            conf, url = gui.keyboard()
            if conf:
                try:
                    cfg = net.http(url)
                except Exception, e:
                    gui.warn(str(e), "%s url can't be reached" % url)
                    return
示例#2
0
    def edit_playlist(self, add=False, rename=False, delete=False, addto=False, removefrom=False, oldname=None, index=None):
        update = False

        if add or rename:
            confirmed, text = gui.keyboard()
            if confirmed:
                if add:
                    result = self.config.add_playlist(text)
                if rename:
                    result = self.config.rename_playlist(oldname, text)
                if not result:
                    gui.warn("ERROR", "Can not edit playlist %s. Either there is already a playlist or a category with the same name" % text)
                else:
                    update = True

        if delete:
            result = self.config.delete_playlist(oldname)
            if not result:
                gui.warn("ERROR", "Can not delete playlist %s. No such playlist" % oldname)
            else:
                update = True

        if addto:
            playlists = self.config.playlists.keys()
            playlist = gui.select("Select Playlist", playlists)
            if playlist >= 0:
                playlist = playlists[playlist]
                result = self.config.add_to_playlist(playlist, index)
                if not result:
                    gui.warn("ERROR", "Can not add channel to playlist %s. Channel is already in the list" % playlist)

        if removefrom:
            result = self.config.remove_from_playlist(oldname, index)
            if not result:
                gui.warn("ERROR", "Can not remove channel from playlist %s" % oldname)
            else:
                update = True

        if update:
            self.config.update_pvr = True
            container.refresh()
示例#3
0
    def geturls(self, id):
        fansubxpath = ".//div[@class='panel-body']/div[1]/button"
        mirrorxpath = ".//div[@class='panel-body']/div[4]/button"

        with Browser() as browser:
            page = browser.navigate(id, domain, self.ispagevalid)
        xpage = htmlement.fromstring(page)

        fansubs = {}

        for fansub, fansublink in tools.safeiter(
                self.iterajaxlink(xpage, fansubxpath)):
            fansubs[fansub] = fansublink

        if not fansubs:
            for _, mirrorlink in tools.safeiter(
                    self.iterajaxlink(xpage, mirrorxpath)):
                mirror = self.getlink(mirrorlink)
                if mirror:
                    yield mirror
        else:
            fansubselect = gui.select("Select Fansub", list(fansubs.keys()))
            i = -1
            for _fansub, fansublink in fansubs.items():
                i += 1
                if fansubselect == -1 or fansubselect == i:
                    with Browser(None, 0) as browser:
                        page = browser.navigate(
                            fansublink,
                            id,
                            headers={"x-requested-with": "XMLHttpRequest"})
                    xfansubpage = htmlement.fromstring(page)
                    mirror = self.getlink(None, xfansubpage)
                    if mirror:
                        yield mirror
                    for _, mirrorlink in tools.safeiter(
                            self.iterajaxlink(xfansubpage, mirrorxpath)):
                        mirror = self.getlink(mirrorlink)
                        if mirror:
                            yield mirror
示例#4
0
    def select_best_exit(self, showgui=True):
        if showgui:
            ctry = gui.select("Select Country", defs.tor_countries)
            if ctry:
                ctry = defs.tor_countries[ctry]
                nodes = json.loads(self.download("https://onionoo.torproject.org/details?search=flag:exit country:%s" % ctry))
                if not len(nodes["relays"]):
                    gui.ok(ctry, "Can't find any exit nodes in %s" % ctry)
                    return
        else:
            nodes = json.loads(self.download("https://onionoo.torproject.org/details?search=flag:exit"))
        relay = sorted(nodes["relays"], key=lambda i: i.get("exit_probability", 0), reverse=True)[0]
        guistr = "%s\n%s: %s \n%s: %s Mbps\n%s" % (relay["fingerprint"],
                                                   relay.get("nickname", ""),
                                                   relay.get("as_name", ""),
                                                   relay.get("country_name", ""),
                                                   int(relay.get("observed_bandwidth", 0) / 1000000),
                                                   " ".join(relay.get("exit_addresses", []))
                                                   )

        gui.ok("Exit Node Selected", guistr)
示例#5
0
 def __init__(self, useragent=None, httptimeout=None, *iargs, **ikwargs):
     self.__inittime = time.time()
     self.sysaddon = sys.argv[0]
     self.syshandle = int(sys.argv[1])
     serial = sys.argv[2][1:]
     try:
         data = json.loads(urllib.unquote_plus(serial))
     except Exception:
         data = {}
     self._items = []
     self._playlist = []
     self._hays = {}
     self._container = data.get("container", self.__class__.__name__)
     self._module = data.get("module", self.__class__.__module__)
     self._method = data.get("method", _default_method)
     self._media = data.get("media", None)
     args = data.get("args", [])
     kwargs = data.get("kwargs", {})
     self._disp_container = self._container
     self._disp_module = self._module
     self._disp_method = self._method
     self._isplaying = 0  # 0 stopped, 1: trying, 2: started
     self.ondispatch()
     if self._disp_module == self.__class__.__module__:
         if self._disp_container == self.__class__.__name__:
             self._container = self
         else:
             self._module = sys.modules[self._disp_module]
             self._container = getattr(self._module, self._disp_container)()
             return
     else:
         self._module = importlib.import_module(self._disp_module)
         self._container = getattr(self._module, self._disp_container)()
         return
     self.__itime = (time.time() - _startt) * 1000
     xbmc.log("****** TinyXBMC is Dispatching ******")
     xbmc.log("MODULE    : %s" % self._disp_module)
     xbmc.log("CONTAINER : %s" % self._disp_container)
     xbmc.log("METHOD    : %s" % self._disp_method)
     xbmc.log("ARGUMENTS : %s" % repr(args))
     xbmc.log("KW ARGS   : %s" % repr(kwargs))
     xbmc.log("MEDIA     : %s" % repr(self._media))
     xbmc.log("*************************************")
     self._container.useragent = const.USERAGENT
     self._container.httptimeout = const.HTTPTIMEOUT
     self._container.autoupdate = False
     self._container.init(*iargs, **ikwargs)
     self._method = getattr(self._container, self._disp_method)
     if self._container._media == "resolver":
         p = player()
         redirects = []
         for u, finfo, fart in tools.dynamicret(
                 tools.safeiter(self._method(*args, **kwargs))):
             if p.dlg.iscanceled():
                 break
             p.fallbackinfo = finfo
             p.fallbackart = fart
             self._container._isplaying = 1
             if "plugin://" in u:
                 redirects.append(u)
                 continue
             item = xbmcgui.ListItem(path=u)
             state = p.stream(u, item)
             if state:
                 self._container._isplaying = 2
                 self._close()
                 return
             else:
                 self._container._isplaying = 0
                 p.dlg.update(100, "Skipping broken url: %s" % u)
         if not self._container._isplaying == 2 and len(redirects):
             redirects = list(set(redirects))
             if len(redirects) == 1:
                 u = redirects[0]
             else:
                 u = gui.select("Select Addon", *redirects)
             if p.canresolve:
                 p.stream("", xbmcgui.ListItem())
             tools.builtin(u)
             state = p.waitplayback(u)
             self._close()
             self._container._isplaying = 2
             return
     elif self._container._media == "player":
         p = xbmc.PlayList(1)
         try:
             ret = self._method(*args, **kwargs)
         except Exception:
             print traceback.format_exc()
             self._close()
             sys.exit()
         iterable = tools.safeiter(ret)
         for u in iterable:
             item = xbmcgui.ListItem(path=u)
             p.add(u, item)
         xbmc.Player().play(p)
     else:
         try:
             cnttyp = self._method(*args, **kwargs)
         except Exception:
             print traceback.format_exc()
             self._close()
             sys.exit()
         itemlen = len(self._container._items)
         if cnttyp in const.CT_ALL:
             xbmcplugin.setContent(self.syshandle, cnttyp)
         if itemlen:
             for url, item, isfolder in self._container._items:
                 if cnttyp in const.CT_ALL:
                     setview = self.item("Set view default for %s" %
                                         cnttyp.upper())
                     setview.method = "_setview"
                     item.context(setview, False, cnttyp)
                     item.docontext()
                 xbmcplugin.addDirectoryItem(self.syshandle, url, item.item,
                                             isfolder, itemlen)
             xbmcplugin.endOfDirectory(self.syshandle, cacheToDisc=False)
             if self._container.autoupdate:
                 d = self.item("Auto Update", method="_update")
                 d.run(self._container.autoupdate)
         if cnttyp in const.CT_ALL:
             views = self.hay(const.OPTIONHAY).find("views").data
             if cnttyp in views:
                 spath = xbmc.getSkinDir().decode("utf-8")
                 view = views[cnttyp].get(spath, None)
                 if view:
                     for i in range(0, 10 * 20):
                         if xbmc.getCondVisibility('Container.Content(%s)' %
                                                   cnttyp):
                             xbmc.executebuiltin(
                                 "Container.SetSortMethod(27)")
                             xbmc.executebuiltin(
                                 'Container.SetViewMode(%d)' % view)
                             break
                         xbmc.sleep(100)
     self._close()
示例#6
0
    def selectcountry(self, key):
        current = self.platform.getsetting(key)
        ncurrent = gui.select("Allowed Countries", defs.tor_countries, False, current, False, True)
        if ncurrent: