Пример #1
0
def solve(url, cj, user_agent=None, wait=True):
    rslog.logDebug("CJ=%s" % cj)
    if user_agent is None:
        user_agent = util.UA
    headers = {'User-Agent': user_agent, 'Referer': url}
    if cj is not None:
        try:
            cj.load(ignore_discard=True)
        except:
            pass
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
        urllib2.install_opener(opener)

    request = urllib2.Request(url)
    for key in headers:
        request.add_header(key, headers[key])
    try:
        response = urllib2.urlopen(request)
        html = response.read()
    except urllib2.HTTPError, e:
        html = e.read()
Пример #2
0
 def run(self, params):
     rslog.logDebug("XBMC run params=%s" % params)
     if params == {} or params == self.params():
         return self.root()
     elif 'list' in params.keys():
         self.list(self.provider.list(params['list']))
     elif 'play' in params.keys():
         return self.play(params)
     elif 'search-list' in params.keys():
         return self.search_list()
     elif 'search' in params.keys():
         return self.do_search2(params['search'], params)
     elif 'search-remove' in params.keys():
         return self.search_remove(params['search-remove'])
     elif 'search-edit' in params.keys():
         return self.search_edit(params['search-edit'])
     elif 'stats' in params.keys():
         if 'stats' in self.provider.capabilities():
             itm = None
             if 'item' in params.keys():
                 itm = params['item']
             rslog.logDebug("XBMC run stats '%s'" % params['stats'])
             self.provider.stats(itm, params['stats'])
         else:
             rslog.logDebug("'%s' dont have capability 'stats'" %
                            self.provider)
     elif 'trakt' in params.keys():
         if 'trakt' in self.provider.capabilities():
             itm = None
             if 'item' in params.keys():
                 itm = params['item']
             rslog.logDebug("XBMC run trakt '%s'" % params['trakt'])
             # @TODO how to return data to plugin ??? i dont know how for now
             return self.provider.trakt(itm, params['trakt'])
         else:
             rslog.logDebug("'%s' dont have capability 'trakt'" %
                            self.provider)
             return None
     elif self.run_custom:
         return self.run_custom(params)
Пример #3
0
 def run(self, params):
     rslog.logDebug("XBMC run params=%s" % params)
     if params == {} or params == self.params():
         return self.root()
     elif 'list' in params.keys():
         self.list(self.provider.list(params['list']))
     elif 'play' in params.keys():
         return self.play(params)
     elif 'search-list' in params.keys():
         return self.search_list()
     elif 'search' in params.keys():
         return self.do_search(params['search'])
     elif 'search-remove' in params.keys():
         return self.search_remove(params['search-remove'])
     elif 'search-edit' in params.keys():
         return self.search_edit(params['search-edit'])
     elif 'stats' in params.keys():
         if 'stats' in self.provider.capabilities():
             itm = None
             if 'item' in params.keys():
                 itm = params['item']
             rslog.logDebug("XBMC run stats '%s'" % params['stats'])
             self.provider.stats(itm, params['stats'])
         else:
             rslog.logDebug("'%s' dont have capability 'stats'" %
                            self.provider)
     elif self.run_custom:
         return self.run_custom(params)
Пример #4
0
 def run(self, params):
     rslog.logDebug("XBMC run params=%s"%params)
     if params == {} or params == self.params():
         return self.root()
     elif 'list' in params.keys():
         self.list(self.provider.list(params['list']))
     elif 'play' in params.keys():
         return self.play(params)
     elif 'search-list' in params.keys():
         return self.search_list()
     elif 'search' in params.keys():
         return self.do_search2(params['search'], params)
     elif 'search-remove' in params.keys():
         return self.search_remove(params['search-remove'])
     elif 'search-edit' in params.keys():
         return self.search_edit(params['search-edit'])
     elif 'stats' in params.keys():
         if 'stats' in self.provider.capabilities():
             itm = None
             if 'item' in params.keys():
                 itm = params['item']
             rslog.logDebug("XBMC run stats '%s'"%params['stats'])
             self.provider.stats(itm, params['stats'])
         else:
             rslog.logDebug("'%s' dont have capability 'stats'"%self.provider)
     elif 'trakt' in params.keys():
         if 'trakt' in self.provider.capabilities():
             itm = None
             if 'item' in params.keys():
                 itm = params['item']
             rslog.logDebug("XBMC run trakt '%s'"%params['trakt'])
             # @TODO how to return data to plugin ??? i dont know how for now
             return self.provider.trakt(itm, params['trakt'])
         else:
             rslog.logDebug("'%s' dont have capability 'trakt'"%self.provider)
             return None
     elif self.run_custom:
         return self.run_custom(params)
Пример #5
0
def debug(text):
    text = "xbmc_doplnky: debug " + (str([text]))
    rslog.logDebug(text)
    client.log.debug(text)
Пример #6
0
def solve(url, cj, user_agent=None, wait=True):
    rslog.logDebug("CJ=%s"%cj)
    if user_agent is None:
        user_agent = util.UA
    headers = {'User-Agent': user_agent, 'Referer': url}
    if cj is not None:
        try:
            cj.load(ignore_discard=True)
        except:
            pass
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
        urllib2.install_opener(opener)

    scheme = urlparse.urlparse(url).scheme
    domain = urlparse.urlparse(url).hostname
    request = urllib2.Request(url)
    for key in headers:
        request.add_header(key, headers[key])
    try:
        response = urllib2.urlopen(request)
        html = response.read()
    except urllib2.HTTPError as e:
        html = e.read()

    tries = 0
    while tries < MAX_TRIES:
        solver_pattern = \
            'var (?:s,t,o,p,b,r,e,a,k,i,n,g|t,r,a),f,\s*([^=]+)'
        solver_pattern += \
            '={"([^"]+)":([^}]+)};.+challenge-form\'\);'
        vc_pattern = \
            'input type="hidden" name="jschl_vc" value="([^"]+)'
        pass_pattern = 'input type="hidden" name="pass" value="([^"]+)'
        s_pattern = 'input type="hidden" name="s" value="([^"]+)'
        init_match = re.search(solver_pattern, html, re.DOTALL)
        vc_match = re.search(vc_pattern, html)
        pass_match = re.search(pass_pattern, html)
        s_match = re.search(s_pattern, html)

        if not init_match or not vc_match or not pass_match or not s_match:
            msg = \
                "[CF] Couldn't find attribute: init: |%s| vc: |%s| pass: |%s| No cloudflare check?"
            rslog.logDebug(msg % (init_match, vc_match, pass_match))
            return False

        (init_dict, init_var, init_equation) = \
            init_match.groups()
        vc = vc_match.group(1)
        password = pass_match.group(1)
        s = s_match.group(1)

        equations = re.compile(r"challenge-form\'\);\s*(.*)a.v").findall(html)[0]
        varname = (init_dict, init_var)
        result = float(solve_equation(init_equation.rstrip()))
        rslog.logDebug('[CF] Initial value: |%s| Result: |%s|' % (init_equation, result))

        for equation in equations.split(';'):
            equation = equation.rstrip()
            if len(equation) > len('.'.join(varname)):
                if equation[:len('.'.join(varname))] != '.'.join(varname):
                    rslog.logDebug('[CF] Equation does not start with varname |%s|' % equation)
                else:
                    equation = equation[len('.'.join(varname)):]

                expression = equation[2:]
                operator = equation[0]
                if operator not in ['+', '-', '*', '/']:
                    rslog.logDebug('[CF] Unknown operator: |%s|' % equation)
                    continue

                result = float(str(eval(str(result) + operator + str(solve_equation(expression)))))
                rslog.logDebug('[CF] intermediate: %s = %s' % (equation, result))
        
        result = '{0:.10f}'.format(eval('float({0} + {1})'.format(result, len(domain))))
        rslog.logDebug('[CF] Final Result: |%s|' % result)

        if wait:
            rslog.logDebug('Sleeping for 5 Seconds')
            sleep(5.1)

        url = \
            '%s://%s/cdn-cgi/l/chk_jschl?s=%s&jschl_vc=%s&pass=%s&jschl_answer=%s' \
            % (scheme, domain, urllib.quote(s), urllib.quote(vc), urllib.quote(password), urllib.quote(result))
        #rslog.logDebug('[CF] url: %s' % url)
        request = urllib2.Request(url)
        for key in headers:
            request.add_header(key, headers[key])
        try:
            opener = urllib2.build_opener(NoRedirection)
            urllib2.install_opener(opener)
            response = urllib2.urlopen(request)
            while response.getcode() in [301, 302, 303, 307]:
                if cj is not None:
                    cj.extract_cookies(response, request)

                redir_url = response.info().getheader('location')
                rslog.logDebug("redirect_url=%s"%redir_url)
                if not redir_url.startswith('http'):
                    base_url = '%s://%s' % (scheme, domain)
                    redir_url = urlparse.urljoin(base_url, redir_url)
                    rslog.logDebug("redirect_url=%s"%redir_url)

                request = urllib2.Request(redir_url)
                for key in headers:
                    request.add_header(key, headers[key])
                if cj is not None:
                    cj.add_cookie_header(request)

                response = urllib2.urlopen(request)
                rslog.logDebug("RESPONSE=\n%s"%response)
            final = response.read()
            
            if 'cf-browser-verification' in final:
                rslog.logDebug('[CF] Failure: html: %s url: %s' % (html, url))
                tries += 1
                html = final
            else:
                break
        except urllib2.HTTPError as e:
            rslog.logDebug('[CF] HTTP Error: %s on url: %s' % (e.code, url))
            return False
        except urllib2.URLError, e:
            rslog.logDebug('[CF] URLError Error: %s on url: %s' % (e, url))
            return False
Пример #7
0
 def http_response(self, request, response):
     rslog.logDebug('Stopping Redirect')
     return response
Пример #8
0
                    redir_url = urlparse.urljoin(base_url, redir_url)
                    rslog.logDebug("redirect_url=%s"%redir_url)

                request = urllib2.Request(redir_url)
                for key in headers:
                    request.add_header(key, headers[key])
                if cj is not None:
                    cj.add_cookie_header(request)

                response = urllib2.urlopen(request)
                rslog.logDebug("RESPONSE=\n%s"%response)
            final = response.read()
            
            if 'cf-browser-verification' in final:
                rslog.logDebug('[CF] Failure: html: %s url: %s' % (html, url))
                tries += 1
                html = final
            else:
                break
        except urllib2.HTTPError as e:
            rslog.logDebug('[CF] HTTP Error: %s on url: %s' % (e.code, url))
            return False
        except urllib2.URLError, e:
            rslog.logDebug('[CF] URLError Error: %s on url: %s' % (e, url))
            return False

    # cant call without param cache
    #if cj is not None:
    #    util.cache_cookies()
    rslog.logDebug("FINAL=\n%s"%final)
    return final
Пример #9
0
def debug(text):
        text = "xbmc_doplnky: debug " + (str([text]))
        rslog.logDebug(text)
        client.log.debug(text)
Пример #10
0
    while tries < MAX_TRIES:
        solver_pattern = \
            'var (?:s,t,o,p,b,r,e,a,k,i,n,g|t,r,a),f,\s*([^=]+)'
        solver_pattern += \
            '={"([^"]+)":([^}]+)};.+challenge-form\'\);.*?\n.*?;(.*?);a\.value'
        vc_pattern = \
            'input type="hidden" name="jschl_vc" value="([^"]+)'
        pass_pattern = 'input type="hidden" name="pass" value="([^"]+)'
        init_match = re.search(solver_pattern, html, re.DOTALL)
        vc_match = re.search(vc_pattern, html)
        pass_match = re.search(pass_pattern, html)

        if not init_match or not vc_match or not pass_match:
            msg = \
                "Couldn't find attribute: init: |%s| vc: |%s| pass: |%s| No cloudflare check?"
            rslog.logDebug(msg % (init_match, vc_match, pass_match))
            return False

        (init_dict, init_var, init_equation, equations) = \
            init_match.groups()
        vc = vc_match.group(1)
        password = pass_match.group(1)

        varname = (init_dict, init_var)
        result = int(solve_equation(init_equation.rstrip()))
        rslog.logDebug('Initial value: |%s| Result: |%s|' %
                       (init_equation, result))

        for equation in equations.split(';'):
            equation = equation.rstrip()
            if equation[:len('.'.join(varname))] != '.'.join(varname):