コード例 #1
0
 def searchepisodes(self, keyw, cache=False, **kwargs):
     for _ in self.getscrapers(mtd="searchepisodes", args=[keyw], **kwargs):
         numitems = len(self.chan.items)
         if numitems:
             gui.notify(self.chan.title, "Found %d" % numitems, False)
         for i, [name, arg, info, art] in enumerate(self.chan.items):
             percent = (i + 1) * 100 / numitems
             info, art = self._cachemeta(arg, info, art, "episode", cache,
                                         percent)
             self.cacheresolve(arg, info, art)
             lname = "[%s] %s" % (self.chan.title, name)
             li = self.item(lname, info, art, method="geturls")
             select = self.item("Select Source",
                                info,
                                art,
                                method="selecturl")
             if self._isimp(showextension, "cacheepisodes") and not cache:
                 context = self.item("Query Meta Information",
                                     method="_context")
                 args = [arg, info, art, "episode"]
                 li.context(context, False, "meta", *args,
                            **self.chan._tinyxbmc)
             li.context(select, True, arg, **self.chan._tinyxbmc)
             li.resolve(arg, False, **self.chan._tinyxbmc)
     return tinyconst.CT_EPISODES
コード例 #2
0
 def searchshows(self, keyw, cache=False, **kwargs):
     for _ in self.getscrapers(mtd="searchshows", args=[keyw], **kwargs):
         numitems = len(self.chan.items)
         if numitems:
             gui.notify(self.chan.title, "Found %d" % numitems, False)
         for i, [name, arg, info, art] in enumerate(self.chan.items):
             percent = (i + 1) * 100 / numitems
             info, art = self._cachemeta(arg, info, art, "show", cache,
                                         percent)
             lname = "[%s] %s" % (self.chan.title, name)
             canseason = self._isimp(showextension, "getseasons")
             if canseason:
                 li = self.item(lname, info, art, method="getseasons")
             else:
                 li = self.item(lname, info, art, method="getepisodes")
             if self._isimp(showextension, "cacheshows") and not cache:
                 context = self.item("Query Meta Information",
                                     method="_context")
                 args = [arg, info, art, "show"]
                 li.context(context, False, "meta", *args,
                            **self.chan._tinyxbmc)
             if canseason:
                 li.dir(None, arg, **self.chan._tinyxbmc)
             else:
                 li.dir(None, arg, None, **self.chan._tinyxbmc)
     return tinyconst.CT_TVSHOWS
コード例 #3
0
 def _setview(self, ct):
     stack = self.hay(const.OPTIONHAY, common=True)
     data = stack.find("views").data
     current = data.get(ct, {})
     spath = xbmc.getSkinDir().decode("utf-8")
     current[spath] = tools.getskinview()
     data[ct] = current
     stack.throw("views", data)
     gui.notify(ct.upper(), "Default view is updated")
コード例 #4
0
 def getplayer(priority):
     target, hasinit, pcls = playerins[priority]
     if hasinit:
         return target, hasinit
     else:
         print "VODS is initializing %s" % target
         try:
             ins = pcls(self)
             playerins[target] = (target, ins, pcls)
             makenameart(ins)
             gui.notify("Initialized", ins.title, False)
             return target, ins
         except Exception:
             print traceback.format_exc()
             return target, None
コード例 #5
0
 def _recorder_thread(timerid, url, fname, startts, endts):
     segmentsdone = []
     hasstarted = False
     stopflag = False
     manifest = re.findall("(http\:\/\/localhost.+)", net.http(url, cache=None))[0]
     fnamenorm = re.sub("[^0-9a-zA-Z]+", "_", fname) + ".ts"
     fullname = os.path.join(cfg.pvrtemp, fnamenorm)
     while True:
         if time.time() > endts or stopflag:
             if fname in iptv.activerecords:
                 iptv.activerecords.pop(fname)
                 tools.copy(fullname, cfg.pvrlocation + "/" + fnamenorm)
                 os.remove(fullname)
                 gui.notify("Recording Finished", "%s is recorded" % fname)
             break
         if not hasstarted:
             gui.notify("Recording Started", "%s is being recorded" % fname)
             hasstarted = True
             iptv.activerecords[fname] = timerid
         lastmanifest = time.time()
         parsed = parser.parse(net.http(manifest, cache=None))
         targetduration = parsed.get("targetduration", 1)
         for segment in parsed.get("segments", []):
             if segment["uri"] not in segmentsdone:  # TO-DO: this can be faster
                 segmentsdone.append(segment["uri"])
                 segmentts = segment.get("current_program_date_time")
                 if segmentts:
                     segmentts = datetime.timestamp(segmentts)  # TO-DO: make sure this is UTC
                     if segmentts < startts:
                         continue
                     elif segmentts > endts:
                         stopflag = True
                         break
                 try:
                     segdata = net.http(segment["uri"], text=False, cache=None).content
                     with open(fullname, "ab") as f:  # TO-do: Windows?
                         f.write(segdata)
                 except Exception:
                     # shit segment, skip it
                     print(traceback.format_exc())
             while True:
                 if (time.time() - lastmanifest) > targetduration:
                     break
                 time.sleep(0.5)
コード例 #6
0
 def getcache(self, arg, typ="movie"):
     mname = self.__class__.__module__
     cname = self.__class__.__name__
     path = ".".join([self.addonid, mname, cname, "metacache"])
     mname = "cache%ss" % typ
     stack = self.hay(path)
     info = stack.find("%s%sinfo" % (repr(arg), typ)).data
     art = stack.find("%s%sart" % (repr(arg), typ)).data
     isimp = hasattr(self, mname)
     if info == {} and art == {} and isimp:
         cache = getattr(self, mname)
         info, art = cache(arg)
         name = info.get("title")
         if not name:
             name = info.get("tvshowtitle", "media")
         stack.throw("%s%sinfo" % (repr(arg), typ), info)
         stack.throw("%s%sart" % (repr(arg), typ), art)
         gui.notify(self.__class__.__name__, "Cached %s" % name, False)
     return info, art
コード例 #7
0
 def start(self):
     if self.checkreq() is None:
         steps = ((self.platform.start_tor, (), "TOR can't start"),
                  (self.platform.set_dns, ("127.0.0.1",), "DNS can't be anonymized"),
                  (self.platform.start_ovpn, (), "OPENVPN can't start"),
                  (self.platform.anonymize, (), "TCP/UDP can't be anonimized")
                  )
         self._stop(True)
         for step, args, msg in steps:
             try:
                 ret = step(*args)
             except Exception, e:
                 gui.ok("ANON", "ERROR: %s" % str(e))
                 self._stop(True)
                 return
             if not ret:
                 self._stop(True)
                 gui.error("ANON", msg, True)
                 return
         gui.notify("ANON", "Anonimization started successfully !", True)
コード例 #8
0
ファイル: net.py プロジェクト: ATi1907/repository.biyik
def cloudflare(response, **kwargs):
    def __extract_js(body):
        js = re.search(r"(var s,t,o,p,b,r,e,a,k,i,n,g,f,.+?;)", body).group(1)
        js += re.search(r";(.+?)\s?\+\s?t\.length", body).group(1)
        js = re.sub(r'a\.value\s?\=\s?\+', '', js)
        return js + ";"

    def __redirect_clf(redirect, **kwargs):
        redirect_url = redirect.headers.get("Location")
        if redirect_url is None:
            return redirect
        elif redirect_url.startswith("/"):
            redirect_url = "%s://%s%s" % (parsed_url.scheme, domain,
                                          redirect_url)
        kwargs["method"] = method
        kwargs["text"] = False
        return http(redirect_url, **kwargs)

    if (response.status_code == 503
            and "cloudflare" in response.headers.get("Server")
            and b"jschl_vc" in response.content
            and b"jschl_answer" in response.content):
        import js2py
        body = response.text
        parsed_url = urlparse.urlparse(response.url)
        domain = parsed_url.netloc
        submit_url = "%s://%s/cdn-cgi/l/chk_jschl" % (parsed_url.scheme,
                                                      domain)
        cfkwargs = copy.deepcopy(kwargs)
        for key in ["headers", "params"]:
            if not isinstance(cfkwargs[key], dict):
                cfkwargs[key] = {}
        cfkwargs["headers"]["Referer"] = response.url
        cfkwargs["params"]["jschl_vc"] = re.search(
            r'name="jschl_vc" value="(\w+)"', body).group(1)
        cfkwargs["params"]["pass"] = re.search(r'name="pass" value="(.+?)"',
                                               body).group(1)
        js = __extract_js(body)
        jseval = float(js2py.eval_js(js))
        cfkwargs["params"]["jschl_answer"] = str(jseval + len(domain))
        method = response.request.method
        cfkwargs["allow_redirects"] = False
        t = 5
        from tinyxbmc import gui
        gui.notify("CloudFlare", "Waiting %d seconds" % t, False)
        time.sleep(t)
        return __redirect_clf(
            getsession(0)("GET", submit_url, **cfkwargs), **kwargs)

    elif response.status_code == 403 and "cloudflare" in response.headers.get(
            "Server"):
        formaddr = re.search('<form.+?id="challenge-form".+?action="(.+?)"',
                             response.content)
        if formaddr:
            import recaptcha
            body = response.text
            r = re.search('input type="hidden" name="r" value="(.+?)"',
                          body).group(1)
            page_url = response.url
            method = response.request.method
            parsed_url = urlparse.urlparse(page_url)
            domain = parsed_url.netloc
            sitekey = re.search('data-sitekey="(.*?)"', body).group(1)
            ua = response.request.headers["user-agent"]
            headers = {
                'Referer': page_url,
                "User-agent": ua,
                "Accept-Language": tools.language()
            }
            resp = getsession(0).request(
                "GET",
                'http://www.google.com/recaptcha/api/fallback?k=%s' % sitekey,
                headers=headers)
            html = resp.text
            token = ''
            iteration = 0
            while True:
                payload = re.findall('"(/recaptcha/api2/payload[^"]+)', html)
                iteration += 1
                message = re.findall(
                    '<label[^>]+class="fbc-imageselect-message-text"[^>]*>(.*?)</label>',
                    html)
                if not message:
                    message = re.findall(
                        '<div[^>]+class="fbc-imageselect-message-error">(.*?)</div>',
                        html)
                if not message:
                    token = re.findall(
                        'div class="fbc-verification-token"><textarea.+?>(.*?)<\/textarea>',
                        html)[0]
                    if token:
                        print 'Captcha Success: %s' % token
                    else:
                        print 'Captcha Failed'
                    break
                else:
                    message = tools.strip(message[0], True)
                    payload = payload[0]
                cval = re.findall('name="c"\s+value="([^"]+)', html)[0]
                captcha_imgurl = 'https://www.google.com%s' % (payload.replace(
                    '&amp;', '&'))
                message = re.sub('</?strong>', '', message)
                if tools.isstub():
                    print captcha_imgurl
                    print message
                    print iteration
                    print page_url
                    captcha_response = [int(x) for x in raw_input("").split()]
                else:
                    oSolver = recaptcha.cInputWindow(captcha=captcha_imgurl,
                                                     msg=message,
                                                     iteration=iteration,
                                                     sitemsg=page_url)
                    captcha_response = oSolver.get()
                if not captcha_response:
                    break
                postdata = {"c": str(cval), "response": []}
                for captcha in captcha_response:
                    postdata["response"].append(str(captcha))
                headers = {'Referer': resp.url, "User-agent": ua}
                resp = getsession(0).request(
                    "POST",
                    'http://www.google.com/recaptcha/api/fallback?k=%s' %
                    sitekey,
                    headers=headers,
                    data=postdata)
                html = resp.text
            if token == "":
                return response
            submit_url = "%s://%s%s" % (parsed_url.scheme, domain,
                                        formaddr.group(1))
            query = {"r": r, "g-recaptcha-response": token}
            headers = {"Referer": page_url, "User-agent": ua}
            return __redirect_clf(
                getsession(0).request("POST",
                                      submit_url,
                                      data=query,
                                      headers=headers,
                                      allow_redirects=False), **kwargs)
    return response
コード例 #9
0
                  "Error during setting DNS"),
                 (self.platform.reset, (), "Error during clearing TCP/UDP routing"),
                 (self.platform.stop_tor, (), "TOR can't be stooped"),
                 (self.platform.stop_ovpn, (), "OPENVPN can't be stopped")
                 )
        for step, args, msg in steps:
            try:
                ret = step(*args)
            except Exception, e:
                gui.ok("ANON", "ERROR: %s" % str(e))
                return
            if not ret:
                gui.error("ANON", msg, True)
                return
        if not silent:
            gui.notify("ANON", "Anonimization stopped successfully !", True)

    def stop(self):
        if self.checkreq() is None:
            self._stop()

    def index(self):
        self.item("Settings", method="settings").dir()

        vconnected = "[COLOR red]Disconnected[/COLOR]"
        for _ in self.platform.findpids("openvpn"):
            vconnected = "[COLOR green]Connected[/COLOR]"
            break
        self.item("VPN Status: %s" % vconnected).call()

        try:
コード例 #10
0
    def geturls(self, url, direct, **kwargs):
        key = json.dumps(url)
        info = self.hay(_resolvehay).find(key + "_info").data
        art = self.hay(_resolvehay).find(key + "_art").data
        playerins = {}

        def getplayer(priority):
            target, hasinit, pcls = playerins[priority]
            if hasinit:
                return target, hasinit
            else:
                print "VODS is initializing %s" % target
                try:
                    ins = pcls(self)
                    playerins[target] = (target, ins, pcls)
                    makenameart(ins)
                    gui.notify("Initialized", ins.title, False)
                    return target, ins
                except Exception:
                    print traceback.format_exc()
                    return target, None

        def prepareplayers(priority, entrypoint):
            for player in extension.getplugins(entrypoint):
                priority += 1
                target = ":".join([str(x) for x in player._tinyxbmc.values()])
                playerins[priority] = (target, False, player)
            return priority

        if not direct:
            try:
                links = self.getscrapers(mtd="geturls", args=[url],
                                         **kwargs).next()
            except Exception:
                print traceback.format_exc()
        else:
            try:
                self.getscrapers(**kwargs).next()
            except Exception:
                print traceback.format_exc()
            links = iter([url])
        priority = 0
        if self.chan.useaddonplayers:
            priority = prepareplayers(priority, _extaddonplayer)
        if self.chan.usedirect:
            priority += 1
            playerins[priority] = ("direct", linkplayerextension(self), None)
        if self.chan.uselinkplayers:
            priority = prepareplayers(priority, _extlinkplayer)
        for k in sorted(playerins, reverse=True):
            print "VODS found player(%s): %s" % (k, playerins[k][0])
        for kodilink in tools.safeiter(links):
            link, headers = net.fromkodiurl(kodilink)
            if not isinstance(link, (str, unicode)):
                print "VODS received broken link, skipping...: %s" % repr(link)
                continue
            gui.notify("Scraping", link, False)
            print "VODS is scraping link: %s" % link.encode("ascii", "replace")
            for priority in sorted(playerins, reverse=True):
                target, pcls = getplayer(priority)
                print "VODS is trying player: %s" % target
                if not pcls:
                    print "VODS received broken player, skipping...: %s" % repr(
                        target)
                    continue
                found = False
                isaddon = False
                for url in tools.safeiter(pcls.geturls(link, headers)):
                    if not url:
                        print "VODS received broken url, skipping...: %s" % repr(
                            url)
                        break
                    found = True
                    if url.startswith("plugin://"):
                        try:
                            url = pcls.builtin % url
                        except Exception:
                            print traceback.format_exc()
                            continue
                        isaddon = True
                    yield url, info, art
                if found and not isaddon:
                    while True:
                        if not self._isplaying == 1:
                            break
                    if self._isplaying == 2:
                        print "VODS started playback : %s" % repr(url)
                        break