Esempio n. 1
0
    def tryTologin(self):
        printDBG('tryTologin start')
        connFailed = _('Connection to server failed!')

        sts, data = self.getPage(self.getMainUrl())
        if not sts:
            return False, connFailed

        if 'logout.php' in data:
            return True, 'OK'

        login = config.plugins.iptvplayer.mrpiracy_login.value
        passwd = config.plugins.iptvplayer.mrpiracy_password.value

        post_data = {
            'email': login,
            'password': passwd,
            'lembrar_senha': 'lembrar'
        }

        sitekey = self.cm.ph.getSearchGroups(data, 'fallback\?k=([^"]+?)"')[0]
        if sitekey != '':
            recaptcha = UnCaptchaReCaptcha_fallback(lang=GetDefaultLang())
            recaptcha.HTTP_HEADER['Referer'] = self.getMainUrl()
            recaptcha.HTTP_HEADER['User-Agent'] = self.USER_AGENT
            token = recaptcha.processCaptcha(sitekey)
            if token == '':
                return False, 'NOT OK'
            post_data.update({
                'g-recaptcha-response': token,
                'g-recaptcha-response2': token,
                'url': '/'
            })

        data = self.cm.ph.getDataBeetwenMarkers(data, '<form', '</form>',
                                                False)[1]
        url = self.getFullUrl(
            self.cm.ph.getSearchGroups(data,
                                       '''action=['"]([^'^"]+?)['"]''')[0])

        params = dict(self.defaultParams)
        params['header'] = dict(self.HEADER)
        params['header']['Referer'] = self.getMainUrl()

        # login
        sts, data = self.cm.getPage(url, params, post_data)
        if not sts:
            return False, connFailed

        if 'logout.php' in data:
            return True, 'OK'
        else:
            return False, 'NOT OK'
Esempio n. 2
0
 def processCaptcha(self, sitekey, refUrl, bypassCaptchaService=None, userAgent=None, baseErrMsgTab=None, beQuaiet=False):
     if isinstance(baseErrMsgTab, list):
         errorMsgTab = list(baseErrMsgTab)
     else:
         errorMsgTab = [_('Link protected with Google ReCaptcha v2')]
     
     if userAgent == None:
         try:
             userAgent = self.USER_AGENT
         except Exception:
             pass
     
     if userAgent == None:
         try:
             userAgent = self.defaultParams['header']['User-Agent']
         except Exception:
             pass
     
     recaptcha = UnCaptchaReCaptcha_fallback(lang=GetDefaultLang())
     recaptcha.HTTP_HEADER['Referer'] = refUrl
     if userAgent != None:
         recaptcha.HTTP_HEADER['User-Agent'] = userAgent
     token = recaptcha.processCaptcha(sitekey)
     
     if token == '':
         recaptcha = None
         if config.plugins.iptvplayer.captcha_bypass.value != '' and bypassCaptchaService == None:
             bypassCaptchaService = config.plugins.iptvplayer.captcha_bypass.value
         if bypassCaptchaService == '9kw.eu':
             recaptcha = UnCaptchaReCaptcha_9kw()
         elif bypassCaptchaService == '2captcha.com':
             recaptcha = UnCaptchaReCaptcha_2captcha()
         elif config.plugins.iptvplayer.myjd_login.value != '' and config.plugins.iptvplayer.myjd_password.value != '':
             recaptcha = UnCaptchaReCaptcha_myjd()
         
         if recaptcha != None:
             token = recaptcha.processCaptcha(sitekey, refUrl)
         else:
             errorMsgTab.append(_('Please visit %s to learn how to redirect this task to the external device.') % 'http://zadmario.gitlab.io/captcha.html')
             if not beQuaiet:
                 self.sessionEx.waitForFinishOpen(MessageBox, '\n'.join(errorMsgTab), type=MessageBox.TYPE_ERROR, timeout=20)
             if bypassCaptchaService != None:
                 errorMsgTab.append(_(' or '))
                 errorMsgTab.append(_('You can use \"%s\" or \"%s\" services for automatic solution.') % ("http://2captcha.com/", "https://9kw.eu/", ) + ' ' + _('Go to the host configuration available under blue button.'))
     return token, errorMsgTab
Esempio n. 3
0
    def getVideoLinks(self, baseUrl):
        printDBG("EkinoTv.getVideoLinks [%s]" % baseUrl)
        urlTab = []
        meta = strwithmeta(baseUrl).meta
        urlParams = dict(self.defaultParams)
        urlParams['header'] = dict(urlParams['header'])
        urlParams['header']['Referer'] = meta.get('Referer', baseUrl)
        urlParams['handle_recaptcha'] = True
        urlParams['with_metadata'] = True

        url = baseUrl
        tries = 0
        while self.up.getDomain(
                self.getMainUrl()) in self.up.getDomain(url) and tries < 4:
            tries += 1

            sts, data = self.getPage(url, urlParams)
            if not sts: return []

            url = data.meta.get('url', url)

            if self.up.getDomain(
                    self.getMainUrl()) not in self.up.getDomain(url):
                break

            if 'recaptcha' in data:
                SetIPTVPlayerLastHostError(
                    _('Link protected with google recaptcha v2.'))
                sitekey = self.cm.ph.getSearchGroups(
                    data, 'data-sitekey="([^"]+?)"')[0]
                if sitekey == '':
                    sitekey = self.cm.ph.getSearchGroups(
                        data,
                        '''['"]?sitekey['"]?\s*:\s*['"]([^"^']+?)['"]''')[0]
                if sitekey != '':
                    recaptcha = UnCaptchaReCaptcha(lang=GetDefaultLang())
                    recaptcha.HTTP_HEADER['Referer'] = baseUrl
                    token = recaptcha.processCaptcha(sitekey)
                    if token != '':
                        vUrl = self.getFullUrl('/watch/verify.php')
                        urlParams['header']['Referer'] = baseUrl
                        sts, data = self.getPage(vUrl, urlParams,
                                                 {'verify': token})
                    else:
                        break

            sts, data = self.getPage(url, urlParams)
            if not sts: return urlTab

            if 'recaptcha' in data:
                SetIPTVPlayerLastHostError(
                    _('Link protected with google recaptcha v2.'))
                continue

            url = self.getFullUrl(
                self.cm.ph.getSearchGroups(data,
                                           '<iframe[^>]+?src="([^"]+?)"')[0])
            if not self.cm.isValidUrl(url):
                url = self.getFullUrl(
                    self.cm.ph.getSearchGroups(
                        data, '''var\s+url\s*=\s*['"]([^'^"]+?)['"]''')[0])

            if not self.cm.isValidUrl(url):
                url = data.meta.get('url', '')

            if meta.get('is_premium', False) and 'video-player' in data:
                vidUrl = self.cm.ph.getSearchGroups(
                    data,
                    '''var\s+[^=]+?\s*=\s*['"](https?://[^'^"]+?\.mp4(:?\?[^'^"]*?)?)['"]''',
                    ignoreCase=True)[0]
                if self.cm.isValidUrl(vidUrl):
                    urlTab.append({'name': 'direct', 'url': vidUrl})
                    return urlTab

            printDBG("|||" + url)
            printDBG(
                "#################################################################"
            )
            printDBG(data)
            printDBG(
                "#################################################################"
            )

        if self.cm.isValidUrl(url):
            urlTab = self.up.getVideoLinkExt(url)
        return urlTab
Esempio n. 4
0
    def request(self, method, url, *args, **kwargs):
        resp = super(CloudflareScraper, self).request(method, url, *args,
                                                      **kwargs)

        # Check if Cloudflare captcha challenge is presented
        if self.is_cloudflare_captcha_challenge(resp):
            #self.handle_captcha_challenge(resp, url)*
            sitekey_data = re.findall('data-sitekey="([^"]+?)"', resp.content,
                                      re.S)
            if sitekey_data:
                sitekey = sitekey_data[0]
            else:
                sitekey = ''

            id_data = re.findall('data-ray="([^"]+?)"', resp.content, re.S)
            if id_data:
                id = id_data[0]
            else:
                id = ''

            if sitekey != '':
                from Plugins.Extensions.IPTVPlayer.libs.pCommon import common
                cm = common()
                sts, tmp = cm.ph.getDataBeetwenMarkers(resp.content,
                                                       '<form',
                                                       '</form>',
                                                       caseSensitive=False)
                actionType = cm.ph.getSearchGroups(tmp, 'method="([^"]+?)"', 1,
                                                   True)[0].lower()
                url5 = cm.ph.getSearchGroups(tmp, 'action="([^"]+?)"')[0]
                url5 = getFullUrl(url5, url)
                post_data2 = dict(
                    re.findall(
                        r'<input[^>]*name="([^"]*)"[^>]*value="([^"]*)"[^>]*>',
                        tmp))

                from Plugins.Extensions.IPTVPlayer.libs.recaptcha_v2 import UnCaptchaReCaptcha
                # google captcha
                recaptcha = UnCaptchaReCaptcha(lang=GetDefaultLang())
                recaptcha.HTTP_HEADER['Referer'] = url
                recaptcha.HTTP_HEADER['User-Agent'] = DEFAULT_USER_AGENT
                token = recaptcha.processCaptcha(sitekey)
                printDBG('tttttttttttttttttttttt' + str(token))
                if '' != token:
                    post_data2['g-recaptcha-response'] = token

                USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36'
                MAIN_URL = 'https://www.planet-streaming.net'
                HTTP_HEADER = {
                    'User-Agent': USER_AGENT,
                    'DNT': '1',
                    'Connection': 'close',
                    'Cache-Control': 'no-cache',
                    'Pragma': 'no-cache',
                    'Accept':
                    'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                    'Accept-Language': 'en-US,en;q=0.5',
                    'Referer': url
                }
                defaultParams = {
                    'with_metadata': True,
                    'no_redirection': False,
                    'header': HTTP_HEADER
                }

                if actionType == 'get':
                    if '?' in url5:
                        url5 += '&'
                    else:
                        url5 += '?'
                    url5 += urllib.urlencode(post_data2)
                    post_data2 = None

                sts, data = cm.getPage(url5, defaultParams, post_data2)

                #if token != '': resp = super(CloudflareScraper, self).request(method, url5, *args, **kwargs)
                printDBG('rrrrrrrrrrrrrrrrrrrrrrrrrrrr' + data)
        # Check if Cloudflare anti-bot "I'm Under Attack Mode" is enabled
        elif self.is_cloudflare_iuam_challenge(resp):
            resp = self.solve_cf_challenge(resp, **kwargs)

        return resp
Esempio n. 5
0
    def tryTologin(self):
        printDBG('tryTologin start')
        connFailed = _('Connection to server failed!')

        # try to log on using user and password fields
        if 'simple' == config.plugins.iptvplayer.mrpiracy_loginmode.value:
            sts, data = self.getPage(self.getMainUrl())
            if not sts: return False, connFailed

            if 'logout.php' in data:
                return True, 'OK'

            login = config.plugins.iptvplayer.mrpiracy_login.value
            passwd = config.plugins.iptvplayer.mrpiracy_password.value

            post_data = {
                'email': login,
                'password': passwd,
                'lembrar_senha': 'lembrar'
            }

            sitekey = self.cm.ph.getSearchGroups(data,
                                                 'fallback\?k=([^"]+?)"')[0]
            if sitekey != '':
                recaptcha = UnCaptchaReCaptcha(lang=GetDefaultLang())
                recaptcha.HTTP_HEADER['Referer'] = self.getMainUrl()
                recaptcha.HTTP_HEADER['User-Agent'] = self.USER_AGENT
                token = recaptcha.processCaptcha(sitekey)
                if token == '':
                    return False, 'NOT OK'
                post_data.update({
                    'g-recaptcha-response': token,
                    'g-recaptcha-response2': token,
                    'url': '/'
                })

            data = self.cm.ph.getDataBeetwenMarkers(data, '<form', '</form>',
                                                    False)[1]
            url = self.getFullUrl(
                self.cm.ph.getSearchGroups(data,
                                           '''action=['"]([^'^"]+?)['"]''')[0])

            params = dict(self.defaultParams)
            params['header'] = dict(self.HEADER)
            params['header']['Referer'] = self.getMainUrl()

            # login
            sts, data = self.cm.getPage(url, params, post_data)
            if not sts: return False, connFailed
        else:
            cookie = {}
            try:
                cookie[
                    config.plugins.iptvplayer.mrpiracy_cookiename.
                    value] = urllib.unquote(
                        config.plugins.iptvplayer.mrpiracy_cookievalue.value)
            except Exception:
                cookie[
                    config.plugins.iptvplayer.mrpiracy_cookiename.
                    value] = config.plugins.iptvplayer.mrpiracy_cookievalue.value
            cookie['nome'] = config.plugins.iptvplayer.mrpiracy_username.value
            cookie[
                'id_utilizador'] = config.plugins.iptvplayer.mrpiracy_userid.value
            cookie['admin'] = config.plugins.iptvplayer.mrpiracy_userid.value
            self.defaultParams['cookie_items'] = cookie

            #rm(self.COOKIE_FILE)
            sts, data = self.getPage(self.getMainUrl())
            if not sts: return False, connFailed

        if 'logout.php' in data:
            return True, 'OK'
        else:
            return False, 'NOT OK'
Esempio n. 6
0
    def getPageCFProtection(self, baseUrl, params={}, post_data=None):
        cfParams = params.get('cloudflare_params', {})

        def _getFullUrlEmpty(url):
            return url

        _getFullUrl = cfParams.get('full_url_handle', _getFullUrlEmpty)
        _getFullUrl2 = cfParams.get('full_url_handle2', _getFullUrlEmpty)

        url = baseUrl
        header = {
            'Referer': url,
            'User-Agent': cfParams.get('User-Agent', ''),
            'Accept-Encoding': 'text'
        }
        header.update(params.get('header', {}))
        params.update({
            'use_cookie': True,
            'save_cookie': True,
            'load_cookie': True,
            'cookiefile': cfParams.get('cookie_file', ''),
            'header': header
        })
        sts, data = self.getPage(url, params, post_data)

        current = 0
        while current < 3:
            if not sts and None != data:
                start_time = time.time()
                current += 1
                doRefresh = False
                try:
                    verData = data.fp.read()
                    printDBG(
                        "==============================================================="
                    )
                    printDBG(verData)
                    printDBG(
                        "==============================================================="
                    )

                    sitekey = self.ph.getSearchGroups(
                        verData, 'data-sitekey="([^"]+?)"')[0]
                    id = self.ph.getSearchGroups(verData,
                                                 'data-ray="([^"]+?)"')[0]
                    if sitekey != '':
                        from Plugins.Extensions.IPTVPlayer.libs.recaptcha_v2 import UnCaptchaReCaptcha
                        # google captcha
                        token = UnCaptchaReCaptcha(
                            lang=GetDefaultLang()).processCaptcha(sitekey)
                        if token == '': return False, None

                        sts, tmp = self.ph.getDataBeetwenMarkers(
                            verData, '<form', '</form>', caseSensitive=False)
                        if not sts: return False, None

                        url = _getFullUrl(
                            self.ph.getSearchGroups(tmp,
                                                    'action="([^"]+?)"')[0])
                        actionType = self.ph.getSearchGroups(
                            tmp, 'method="([^"]+?)"', 1, True)[0].lower()
                        post_data2 = dict(
                            re.findall(
                                r'<input[^>]*name="([^"]*)"[^>]*value="([^"]*)"[^>]*>',
                                tmp))
                        #post_data2['id'] = id
                        if '' != token:
                            post_data2['g-recaptcha-response'] = token
                        else:
                            continue
                        params2 = dict(params)
                        params2['header'] = dict(params['header'])
                        params2['header']['Referer'] = baseUrl
                        if actionType == 'get':
                            if '?' in url:
                                url += '&'
                            else:
                                url += '?'
                            url += urllib.urlencode(post_data2)
                            post_data2 = None
                        sts, data = self.getPage(url, params2)
                    else:
                        dat = self.ph.getDataBeetwenMarkers(
                            verData, 'setTimeout', 'submit()', False)[1]
                        tmp = self.ph.getSearchGroups(
                            dat, '={"([^"]+?)"\:([^}]+?)};', 2)
                        varName = tmp[0]
                        expresion = ['a=%s' % tmp[1]]
                        e = re.compile('%s([-+*])=([^;]+?);' %
                                       varName).findall(dat)
                        for item in e:
                            expresion.append('a%s=%s' % (item[0], item[1]))

                        for idx in range(len(expresion)):
                            e = expresion[idx]
                            e = e.replace('!+[]', '1')
                            e = e.replace('!![]', '1')
                            e = e.replace('=+(', '=int(')
                            if '+[]' in e:
                                e = e.replace(')+(', ')+str(')
                                e = e.replace('int((', 'int(str(')
                                e = e.replace('(+[])', '(0)')
                                e = e.replace('+[]', '')
                            expresion[idx] = e

                        answer = self.calcAnswer('\n'.join(expresion)) + len(
                            cfParams['domain'])
                        refreshData = data.fp.info().get('Refresh', '')

                        verData = self.ph.getDataBeetwenReMarkers(
                            verData,
                            re.compile('<form[^>]+?id="challenge-form"'),
                            re.compile('</form>'), False)[1]
                        printDBG(
                            "==============================================================="
                        )
                        printDBG(verData)
                        printDBG(
                            "==============================================================="
                        )
                        verUrl = _getFullUrl(
                            self.ph.getSearchGroups(verData,
                                                    'action="([^"]+?)"')[0])
                        get_data = dict(
                            re.findall(
                                r'<input[^>]*name="([^"]*)"[^>]*value="([^"]*)"[^>]*>',
                                verData))
                        get_data['jschl_answer'] = answer
                        verUrl += '?'
                        for key in get_data:
                            verUrl += '%s=%s&' % (key, get_data[key])
                        verUrl = _getFullUrl(
                            self.ph.getSearchGroups(verData,
                                                    'action="([^"]+?)"')
                            [0]) + '?jschl_vc=%s&pass=%s&jschl_answer=%s' % (
                                get_data['jschl_vc'], get_data['pass'],
                                get_data['jschl_answer'])
                        verUrl = _getFullUrl2(verUrl)
                        params2 = dict(params)
                        params2['load_cookie'] = True
                        params2['save_cookie'] = True
                        params2['header'] = {
                            'Referer': url,
                            'User-Agent': cfParams.get('User-Agent', ''),
                            'Accept-Encoding': 'text'
                        }
                        printDBG("Time spent: [%s]" %
                                 (time.time() - start_time))
                        time.sleep(5 - (time.time() - start_time))
                        printDBG("Time spent: [%s]" %
                                 (time.time() - start_time))
                        sts, data = self.getPage(verUrl, params2, post_data)
                except Exception:
                    printExc()
            else:
                break
        return sts, data
Esempio n. 7
0
 def getPageCFProtection(self, baseUrl, params={}, post_data=None):
     cfParams = params.get('cloudflare_params', {})
     
     def _getFullUrlEmpty(url):
         return url
     _getFullUrl  = cfParams.get('full_url_handle', _getFullUrlEmpty)
     _getFullUrl2 = cfParams.get('full_url_handle2', _getFullUrlEmpty)
     
     url = baseUrl
     header = {'Referer':url, 'User-Agent':cfParams.get('User-Agent', ''), 'Accept-Encoding':'text'}
     header.update(params.get('header', {}))
     params.update({'with_metadata':True, 'use_cookie': True, 'save_cookie': True, 'load_cookie': True, 'cookiefile': cfParams.get('cookie_file', ''), 'header':header})
     sts, data = self.getPage(url, params, post_data)
     
     current = 0
     while current < 5:
         #if True:
         if not sts and None != data:
             start_time = time.time()
             current += 1
             doRefresh = False
             try:
                 domain = self.getBaseUrl(data.fp.geturl())
                 verData = data.fp.read() 
                 if data.fp.info().get('Content-Encoding', '') == 'gzip':
                     verData = DecodeGzipped(verData)
                 printDBG("------------------")
                 printDBG(verData)
                 printDBG("------------------")
                 if 'sitekey' not in verData and 'challenge' not in verData: break
                 
                 printDBG(">>")
                 printDBG(verData)
                 printDBG("<<")
                 
                 sitekey = self.ph.getSearchGroups(verData, 'data-sitekey="([^"]+?)"')[0]
                 id = self.ph.getSearchGroups(verData, 'data-ray="([^"]+?)"')[0]
                 if sitekey != '':
                     from Plugins.Extensions.IPTVPlayer.libs.recaptcha_v2 import UnCaptchaReCaptcha
                     # google captcha
                     recaptcha = UnCaptchaReCaptcha(lang=GetDefaultLang())
                     recaptcha.HTTP_HEADER['Referer'] = baseUrl
                     if '' != cfParams.get('User-Agent', ''): recaptcha.HTTP_HEADER['User-Agent'] = cfParams['User-Agent']
                     token = recaptcha.processCaptcha(sitekey)
                     if token == '': return False, None
                     
                     sts, tmp = self.ph.getDataBeetwenMarkers(verData, '<form', '</form>', caseSensitive=False)
                     if not sts: return False, None
                     
                     url = self.ph.getSearchGroups(tmp, 'action="([^"]+?)"')[0]
                     if url != '': url = _getFullUrl( url )
                     else: url = data.fp.geturl()
                     actionType = self.ph.getSearchGroups(tmp, 'method="([^"]+?)"', 1, True)[0].lower()
                     post_data2 = dict(re.findall(r'<input[^>]*name="([^"]*)"[^>]*value="([^"]*)"[^>]*>', tmp))
                     #post_data2['id'] = id
                     if '' != token:
                         post_data2['g-recaptcha-response'] = token
                     else:
                         continue
                     params2 = dict(params)
                     params2['header']= dict(params['header'])
                     params2['header']['Referer'] = baseUrl
                     if actionType == 'get':
                         if '?' in url:
                             url += '&'
                         else:
                             url += '?'
                         url += urllib.urlencode(post_data2)
                         post_data2 = None
                         
                     sts, data = self.getPage(url, params2, post_data2)
                     printDBG("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
                     printDBG(sts)
                     printDBG("------------------------------------------------------------------")
                     printDBG(data)
                     printDBG("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
                 else:
                     dat = self.ph.getAllItemsBeetwenNodes(verData, ('<script', '>'), ('</script', '>'), False)
                     for item in dat:
                         if 'setTimeout' in item and 'submit()' in item:
                             dat = item
                             break
                     decoded = ''
                     jscode = base64.b64decode('''ZnVuY3Rpb24gc2V0VGltZW91dCh0LGUpe2lwdHZfcmV0LnRpbWVvdXQ9ZSx0KCl9dmFyIGlwdHZfcmV0PXt9LGlwdHZfZnVuPW51bGwsZG9jdW1lbnQ9e30sd2luZG93PXRoaXMsZWxlbWVudD1mdW5jdGlvbih0KXt0aGlzLl9uYW1lPXQsdGhpcy5fc3JjPSIiLHRoaXMuX2lubmVySFRNTD0iIix0aGlzLl9wYXJlbnRFbGVtZW50PSIiLHRoaXMuc2hvdz1mdW5jdGlvbigpe30sdGhpcy5hdHRyPWZ1bmN0aW9uKHQsZSl7cmV0dXJuInNyYyI9PXQmJiIjdmlkZW8iPT10aGlzLl9uYW1lJiZpcHR2X3NyY2VzLnB1c2goZSksdGhpc30sdGhpcy5maXJzdENoaWxkPXtocmVmOmlwdHZfZG9tYWlufSx0aGlzLnN0eWxlPXtkaXNwbGF5OiIifSx0aGlzLnN1Ym1pdD1mdW5jdGlvbigpe3ByaW50KEpTT04uc3RyaW5naWZ5KGlwdHZfcmV0KSl9LE9iamVjdC5kZWZpbmVQcm9wZXJ0eSh0aGlzLCJzcmMiLHtnZXQ6ZnVuY3Rpb24oKXtyZXR1cm4gdGhpcy5fc3JjfSxzZXQ6ZnVuY3Rpb24odCl7dGhpcy5fc3JjPXR9fSksT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsImlubmVySFRNTCIse2dldDpmdW5jdGlvbigpe3JldHVybiB0aGlzLl9pbm5lckhUTUx9LHNldDpmdW5jdGlvbih0KXt0aGlzLl9pbm5lckhUTUw9dH19KSxPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywidmFsdWUiLHtnZXQ6ZnVuY3Rpb24oKXtyZXR1cm4iIn0sc2V0OmZ1bmN0aW9uKHQpe2lwdHZfcmV0LmFuc3dlcj10fX0pfSwkPWZ1bmN0aW9uKHQpe3JldHVybiBuZXcgZWxlbWVudCh0KX07ZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQ9ZnVuY3Rpb24odCl7cmV0dXJuIG5ldyBlbGVtZW50KHQpfSxkb2N1bWVudC5jcmVhdGVFbGVtZW50PWZ1bmN0aW9uKHQpe3JldHVybiBuZXcgZWxlbWVudCh0KX0sZG9jdW1lbnQuYXR0YWNoRXZlbnQ9ZnVuY3Rpb24oKXtpcHR2X2Z1bj1hcmd1bWVudHNbMV19Ow==''')
                     jscode = "var location = {hash:''}; var iptv_domain='%s';\n%s\n%s\niptv_fun();" % (domain, jscode, dat) #cfParams['domain']
                     printDBG("+ CODE +")
                     printDBG(jscode)
                     printDBG("++++++++")
                     ret = iptv_js_execute( jscode )
                     decoded = byteify(json.loads(ret['data'].strip()))
                     
                     verData = self.ph.getDataBeetwenReMarkers(verData, re.compile('<form[^>]+?id="challenge-form"'), re.compile('</form>'), False)[1]
                     printDBG(">>")
                     printDBG(verData)
                     printDBG("<<")
                     verUrl =  _getFullUrl( self.ph.getSearchGroups(verData, 'action="([^"]+?)"')[0] )
                     get_data = dict(re.findall(r'<input[^>]*name="([^"]*)"[^>]*value="([^"]*)"[^>]*>', verData))
                     get_data['jschl_answer'] = decoded['answer']
                     verUrl += '?'
                     for key in get_data:
                         verUrl += '%s=%s&' % (key, get_data[key])
                     verUrl = _getFullUrl( self.ph.getSearchGroups(verData, 'action="([^"]+?)"')[0] ) + '?jschl_vc=%s&pass=%s&jschl_answer=%s' % (get_data['jschl_vc'], get_data['pass'], get_data['jschl_answer'])
                     verUrl = _getFullUrl2( verUrl )
                     params2 = dict(params)
                     params2['load_cookie'] = True
                     params2['save_cookie'] = True
                     params2['header'] = dict(params.get('header', {}))
                     params2['header'].update({'Referer':url, 'User-Agent':cfParams.get('User-Agent', ''), 'Accept-Encoding':'text'})
                     printDBG("Time spent: [%s]" % (time.time() - start_time))
                     if current == 1:
                         GetIPTVSleep().Sleep(1 + (decoded['timeout'] / 1000.0)-(time.time() - start_time))
                     else:
                         GetIPTVSleep().Sleep((decoded['timeout'] / 1000.0))
                     printDBG("Time spent: [%s]" % (time.time() - start_time))
                     printDBG("Timeout: [%s]" % decoded['timeout'])
                     sts, data = self.getPage(verUrl, params2, post_data)
             except Exception:
                 printExc()
                 break
         else:
             break
     return sts, data
    def getVideoLinks(self, videoUrl):
        printDBG("MRPiracyGQ.getVideoLinks [%s]" % videoUrl)
        errorMsgTab = []
        urlTab = []
        
        # mark requested link as used one
        if len(self.cacheLinks.keys()):
            for key in self.cacheLinks:
                for idx in range(len(self.cacheLinks[key])):
                    if videoUrl in self.cacheLinks[key][idx]['url']:
                        if not self.cacheLinks[key][idx]['name'].startswith('*'):
                            self.cacheLinks[key][idx]['name'] = '*' + self.cacheLinks[key][idx]['name']
                        break

        if self.cm.isValidUrl(videoUrl):
            return self.up.getVideoLinkExt(videoUrl)

        playerData = strwithmeta(videoUrl).meta
        linkId = ''
        imdbId = ''
        try:
            tmp = []
            for it in ['playertype', 'episodio', 'id']:
                tmp.append(playerData.get(it, ''))
            imdbId = self.cm.ph.getSearchGroups(playerData['ref_url'], '''imdb=(tt[0-9]+)''')[0]
            tmp.insert(0, imdbId)
            linkId = '_'.join(tmp)
        except Exception:
            printExc()
        
        printDBG(">>> linkId[%s]" % linkId)
        hostUrl = MRPiracyGQ.LINKS_CACHE.get(linkId, '')
        if hostUrl == '' and config.plugins.iptvplayer.mrpiracy_linkcache.value:
            hostUrl = ReadTextFile(GetCacheSubDir('mrpiracy', linkId))[1]
        
        if hostUrl == '':
            try:
                jscode = playerData.pop('jscode', '')
                jscode += '''var iptv_fake_element={hide:function(){},show:function(){},addClass:function(){},removeClass:function(){}};playertype="iptv_player_data";var iptv_player_data=''' + json.dumps(playerData) + ''';$=function(){return 1==arguments.length&&arguments[0].endsWith(playertype)?{data:function(a){return iptv_player_data[a]}}:iptv_fake_element},$.ajax=function(){print(JSON.stringify(arguments[0]))},''' + playerData['callback'] + '''(iptv_player_data.sitekey);'''
                ret = iptv_js_execute(jscode)
                data = ret['data'].strip()
                data = byteify(json.loads(data))
                
                url = self.getFullUrl(data['url'])
                post_data = data['data']
                urlParams = dict(self.defaultParams)
                urlParams['header'] = dict(self.AJAX_HEADER)
                urlParams['header']['Referer'] = playerData['ref_url']

                if 'sitekey' in playerData:
                    errorMsgTab = [_('Link protected with google recaptcha v2.')]
                    recaptcha = UnCaptchaReCaptcha(lang=GetDefaultLang())
                    recaptcha.HTTP_HEADER['Referer'] = playerData['ref_url']
                    recaptcha.HTTP_HEADER['User-Agent'] = self.USER_AGENT
                    token = recaptcha.processCaptcha(playerData['sitekey'])
                    if token == '':
                        recaptcha = None
                        if config.plugins.iptvplayer.mrpiracy_bypassrecaptcha.value == '9kw.eu':
                            recaptcha = UnCaptchaReCaptcha_9kw()
                        elif config.plugins.iptvplayer.mrpiracy_bypassrecaptcha.value == '2captcha.com':
                            recaptcha = UnCaptchaReCaptcha_2captcha()
                        
                        if recaptcha != None:
                            token = recaptcha.processCaptcha(playerData['sitekey'], playerData['ref_url'])
                        else:
                            errorMsgTab.append(_('You can use \"%s\" or \"%s\" services to workaround this protection.') % ("http://2captcha.com/", "https://9kw.eu/", )) 
                            errorMsgTab.append(_('Go to the host configuration available under blue button.'))
                    
                    printDBG('> token "%s" ' % token)
                    post_data['token'] = token
                    
                sts, data = self.getPage(url, urlParams, post_data)
                printDBG("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
                printDBG(data)
                printDBG("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
                tmp = re.compile('''['"](https?://[^'^"]+?)['"]''').findall(data)
                for item in tmp:
                    if 1 == self.up.checkHostSupport(item):
                        hostUrl = item
                
                if hostUrl == '':
                    url = self.getFullUrl(self.cm.ph.getSearchGroups(data, '<iframe[^>]+?src="([^"]+?)"', 1, ignoreCase=True)[0])
                    if url != '':
                        urlParams = dict(self.defaultParams)
                        urlParams['header'] = dict(urlParams['header'])
                        urlParams['header']['Referer'] = playerData['ref_url']
                        sts, data = self.getPage(url, urlParams)
                        hostUrl = self.cm.ph.getSearchGroups(data, '''location\.href=['"]([^'^"]+?)['"]''')[0]
            except Exception:
                printExc()
    
        if self.cm.isValidUrl(hostUrl):
            if linkId != '':
                if config.plugins.iptvplayer.mrpiracy_linkcache.value and linkId not in MRPiracyGQ.LINKS_CACHE:
                    WriteTextFile(GetCacheSubDir('mrpiracy', linkId), hostUrl)
                MRPiracyGQ.LINKS_CACHE[linkId] = hostUrl
            
            urlTab = self.up.getVideoLinkExt(hostUrl)

        if 0 == len(urlTab):
            SetIPTVPlayerLastHostError('\n'.join(errorMsgTab)) 
        else:
            subUrl = 'https://cdn.mrpiracy.xyz/subs/%s.srt' % imdbId
            sts, data = self.getPage(subUrl)
            if sts and '00:'in data:
                for idx in range(len(urlTab)):
                    urlTab[idx]['url'] = strwithmeta(urlTab[idx]['url'])
                    if 'external_sub_tracks' not in urlTab[idx]['url'].meta: urlTab[idx]['url'].meta['external_sub_tracks'] = []
                    urlTab[idx]['url'].meta['external_sub_tracks'].append({'title':'', 'url':subUrl, 'lang':'pt', 'format':'srt'})
        return urlTab