def listItems(self, cItem, nextCategory): printDBG("MaxtvGO.listItems [%s]" % cItem) sts, data = self.getPage(cItem['url']) if not sts: return article = self.getArticleContent(cItem, data) if len(article): title = article[0]['title'] icon = article[0]['images'][0]['url'] params = dict(cItem) params.update({'good_for_fav': True, 'title': title, 'icon': icon}) self.addVideo(params) cookieHeader = self.cm.getCookieHeader(self.COOKIE_FILE) catsTitle = '' data = self.cm.ph.getDataBeetwenNodes(data, ('<div', '>', 'slajder_film'), ('<div', '>', 'chat_round'))[1] data = re.compile('(<h3[^>]*?>[^>]*?</[^>]*?>)').split(data) for catData in data: if catData.startswith('<h3'): catsTitle = self.cleanHtmlStr(catData) tmp = self.cm.ph.getAllItemsBeetwenMarkers(catData, '<a', '</a>') for item in tmp: url = self.getFullUrl( self.cm.ph.getSearchGroups( item, '''href=['"]([^'^"]+?)['"]''')[0]) icon = self.getFullIconUrl( self.cm.ph.getSearchGroups( item, '''src=['"]([^'^"]+?)['"]''')[0]) icon = strwithmeta( icon, { 'Cookie': cookieHeader, 'User-Agent': self.USER_AGENT, 'Referer': cItem['url'] }) title = self.cleanHtmlStr( self.cm.ph.getSearchGroups( item, '''alt=['"]([^'^"]+?)['"]''')[0]) if title == '': title = catsTitle + ' ' + self.cleanHtmlStr( icon.split('/')[-1].split('.', 1)[0].replace( 'small', '')) # 'category':nextCategory, params = dict(cItem) params.update({ 'good_for_fav': True, 'title': title, 'url': url, 'icon': icon }) self.addVideo(params) if self.loggedIn != True and 0 == len(self.currList): msg = _( 'The host %s requires registration. \nPlease fill your login and password in the host configuration. Available under blue button.' % self.getMainUrl()) GetIPTVNotify().push(msg, 'error', 10) SetIPTVPlayerLastHostError(msg)
def getPage(self, url, params={}, post_data=None): if params == {}: params = dict(self.defaultParams) sts, data = self.cm.getPage(url, params, post_data) if sts and data.meta.get('status_code', 0) in [410, 404] and 'captcha' in data: errorMsg = [_('Link protected with google recaptcha v2.')] errorMsg.append(_("Please visit \"%s\" and confirm that you are human." % self.getMainUrl())) if not self.loggedIn: errorMsg.append(_('Please register and set login and password in the host configuration, to solve this problems permanently.')) errorMsg = '\n'.join(errorMsg) GetIPTVNotify().push(errorMsg, 'info', 10) SetIPTVPlayerLastHostError(errorMsg) return sts, data
def informAboutGeoBlockingIfNeeded(self, country, onlyOnce=True): try: if onlyOnce and self.isGeoBlockingChecked: return except Exception: self.isGeoBlockingChecked = False sts, data = self.cm.getPage( 'https://dcinfos.abtasty.com/geolocAndWeather.php') if not sts: return try: data = byteify(json.loads(data.strip()[1:-1]), '', True) if data['country'] != country: message = _( '%s uses "geo-blocking" measures to prevent you from accessing the services from outside the %s Territory.' ) GetIPTVNotify().push(message % (self.getMainUrl(), country), 'info', 5) self.isGeoBlockingChecked = True except Exception: printExc()
def exploreItem(self, cItem, nextCategory): printDBG("SerijeOnline.exploreItem [%s]" % cItem) self.cm.clearCookie(self.COOKIE_FILE, ['PHPSESSID', '__cfduid', 'cf_clearance']) sts, data = self.getPage(cItem['url']) if not sts: return desc = '' #desc = self.cleanHtmlStr(self.cm.ph.getDataBeetwenNodes(data, ('<h2', '>', 'upper-blue'), ('</div', '>'))[1]) if desc == '': desc = cItem.get('desc', '') tmp = self.cm.ph.getDataBeetwenNodes(data, ('<div', '>', 'pm-submit-data'), ('</div', '>'))[1] tmp = self.cm.ph.getAllItemsBeetwenMarkers(tmp, '<a', '</a>') if len(tmp) > 1: catUrl = self.getFullUrl( self.cm.ph.getSearchGroups(tmp[-1], '''href=['"]([^'^"]+?)['"]''')[0]) catTitle = self.cleanHtmlStr(tmp[-1]) else: catUrl = '' catTitle = '' printDBG("################# catUrl[%s] catTitle[%s]" % (catUrl, catTitle)) num = 0 tmp = self.cm.ph.getDataBeetwenNodes(data, ('<div', '>', 'Playerholder'), ('</div', '>'))[1] if tmp == '': printDBG("#################") data = self.cm.ph.getAllItemsBeetwenMarkers( data, 'data:', '}', False) printDBG(data) for item in data: if 'getplayer' in item: try: query = byteify(json.loads(item + '}'), '', True) query = urllib.urlencode(query) url = self.getFullUrl("/ajax.php") + '?' + query sts, data = self.getPage(url) printDBG("---------------") printDBG(data) if sts: if 'Playerholder' in data: tmp = data else: msg = self.cleanHtmlStr( self.cm.ph.getDataBeetwenNodes( data, ('<div', '>', 'restricted-video'), ('</h2', '>'))[1]) if msg != '': GetIPTVNotify().push(msg, 'error', 10) except Exception: printExc() break printDBG(tmp) data = re.compile('''<iframe[^>]+?src=['"]([^"^']+?)['"]''', re.IGNORECASE).findall(tmp) for url in data: url = self.getFullUrl(url) #if 1 != self.up.checkHostSupport(url): continue if not self.cm.isValidUrl(url): continue num += 1 if len(data) > 1: title = '%s. %s' % (num, cItem['title']) else: title = cItem['title'] params = dict(cItem) params.update({ 'good_for_fav': False, 'title': title, 'desc': desc, 'url': url }) self.addVideo(params) if self.cm.isValidUrl( catUrl) and catUrl != cItem['url'] and catUrl != cItem.get( 'cat_url', ''): params = dict(cItem) params.update({ 'good_for_fav': True, 'category': nextCategory, 'title': catTitle, 'url': catUrl, 'cat_url': catUrl, 'desc': '' }) self.addDir(params)
def tryTologin(self): printDBG('EuroSportPlayer.tryTologin start') errorMsg = _('Error communicating with the server.') if None == self.loggedIn or self.login != config.plugins.iptvplayer.eurosportplayer_login.value or\ self.password != config.plugins.iptvplayer.eurosportplayer_password.value: self.login = config.plugins.iptvplayer.eurosportplayer_login.value self.password = config.plugins.iptvplayer.eurosportplayer_password.value rm(self.COOKIE_FILE) self.loggedIn = False self.loginMessage = '' if '' == self.login.strip() or '' == self.password.strip(): msg = '' sts, data = self.getPage(self.getMainUrl()) if sts and '/subscribe' not in data: msg = self.cleanHtmlStr(self.cm.ph.getDataBeetwenNodes(data, ('<div', '>', '"message"'), ('</div', '>'))[1]) if msg == '': msg = _('The host %s requires subscription.\nPlease fill your login and password in the host configuration - available under blue button.') % self.getMainUrl() GetIPTVNotify().push(msg, 'info', 10) return False if not self.getToken('init'): msg = _(errorMsg) + _('\nError[1].') GetIPTVNotify().push(msg, 'error', 10) return False try: baseUrl = self.serverApiData['server_path']['server'] + '/' url = self.getFullUrl('/login', baseUrl) sts, data = self.getPage(url) if not sts: return False getParams = dict(self.defaultParams) getParams['raw_post_data'] = True getParams['header'] = dict(self.AJAX_HEADER) clientData = self.serverApiData['prod']['authentication']['client'] url = clientData['links'][0]['href'] getParams['header'].update(clientData['links'][0]['headers']) getParams['header']['Authorization'] = getParams['header']['Authorization'].replace('{encodedUserToken}', self.tokenData['access_token']) post_data = '{"type":"email-password","email":{"address":"%s"},"password":{"value":"%s"}}' % (self.login, self.password) sts, data = self.getPage(url, getParams, post_data) if not sts and '401' in str(data): msg = _('Login failed. Invalid email or password.') GetIPTVNotify().push(msg, 'error', 10) return False else: data = byteify(json.loads(data)) printDBG(data) self.tokenData['access_code'] = data['code'] self.tokenData['access_timeout'] = time.time() + (data['exp'] - data['iat']) / 1000.0 if not self.getToken('code'): msg = _(errorMsg) + _('\nError[2].') GetIPTVNotify().push(msg, 'error', 10) return False self.loggedIn = True except Exception: printExc() printDBG('EuroSportPlayer.tryTologin end loggedIn[%s]' % self.loggedIn) return self.loggedIn
def tryTologin(self): printDBG('BBCSport.tryTologin start') netErrorMsg = _('Error communicating with the server.') datErrorMsg = _('Data mismatch.') if config.plugins.iptvplayer.bbc_use_web_proxy.value: if False != self.loggedIn: rm(self.COOKIE_FILE) self.loggedIn = False return False if None == self.loggedIn or self.login != config.plugins.iptvplayer.bbc_login.value or\ self.password != config.plugins.iptvplayer.bbc_password.value: self.login = config.plugins.iptvplayer.bbc_login.value self.password = config.plugins.iptvplayer.bbc_password.value rm(self.COOKIE_FILE) self.loggedIn = False self.loginMessage = '' if '' == self.login.strip() or '' == self.password.strip(): #msg = _('You now need to sign in to watch.\nPlease fill your login and password in the host configuration - available under blue button.') #GetIPTVNotify().push(msg, 'info', 10) return False sts, data = self.getPage(self.getFullUrl('/sport')) if not sts: msg = _(netErrorMsg) + _('\nError[1].') GetIPTVNotify().push(msg, 'error', 10) return False cUrl = data.meta['url'] self.setMainUrl(cUrl) try: url = self.sessionUrl + '?ptrt=' + urllib.quote( cUrl.split('?', 1)[0]) + '&userOrigin=sport&context=sport' sts, data = self.getPage(url) if not sts: msg = _(netErrorMsg) + _('\nError[2].') GetIPTVNotify().push(msg, 'error', 10) return False cUrl = data.meta['url'] sts, data = self.cm.ph.getDataBeetwenNodes( data, ('<form', '>'), ('</form', '>')) if not sts: msg = _(datErrorMsg) + _('\nError[3].') GetIPTVNotify().push(msg, 'error', 10) return False actionUrl = self.cm.getFullUrl( self.cm.ph.getSearchGroups( data, '''action=['"]([^'^"]+?)['"]''')[0].replace( '&', '&'), self.cm.getBaseUrl(cUrl)) if actionUrl == '': actionUrl = cUrl formData = self.cm.ph.getAllItemsBeetwenMarkers( data, '<input', '>') post_data = {} for item in formData: name = self.cm.ph.getSearchGroups( item, '''name=['"]([^'^"]+?)['"]''')[0] value = self.cm.ph.getSearchGroups( item, '''value=['"]([^'^"]+?)['"]''')[0] post_data[name] = value post_data.update({ 'username': self.login, 'password': self.password }) httpParams = dict(self.defaultParams) httpParams['header'] = dict(httpParams['header']) httpParams['header']['Referer'] = self.getMainUrl() sts, data = self.cm.getPage(actionUrl, httpParams, post_data) if sts: printDBG('tryTologin OK') if '/signin' in data.meta['url']: msg = self.cleanHtmlStr( self.cm.ph.getDataBeetwenNodes( data, ('<p', '>', 'form-message'), ('</p', '>'))[1]) GetIPTVNotify().push( _('Login failed.') + '\n' + msg, 'error', 10) return False self.loggedIn = True msg = _( "A TV License is required to watch BBC iPlayer streams, see the BBC website for more information: https://www.bbc.co.uk/iplayer/help/tvlicence" ) GetIPTVNotify().push(msg, 'info', 5) self.loginMessage = msg else: msg = _(netErrorMsg) + _('\nError[4].') GetIPTVNotify().push(msg, 'error', 10) return False except Exception: printExc() printDBG('EuroSportPlayer.tryTologin end loggedIn[%s]' % self.loggedIn) return self.loggedIn
def getURLRequestData(self, params = {}, post_data = None): def urlOpen(req, customOpeners, timeout): if len(customOpeners) > 0: opener = urllib2.build_opener( *customOpeners ) if timeout != None: response = opener.open(req, timeout=timeout) else: response = opener.open(req) else: if timeout != None: response = urllib2.urlopen(req, timeout=timeout) else: response = urllib2.urlopen(req) return response if IsMainThread(): msg1 = _('It is not allowed to call getURLRequestData from main thread.') msg2 = _('You should never perform block I/O operations in the __init__.') msg3 = _('In next release exception will be thrown instead of this message!') GetIPTVNotify().push('%s\n\n%s\n\n%s' % (msg1, msg2, msg3), 'error', 40) if not self.useMozillaCookieJar: cj = cookielib.LWPCookieJar() else: cj = cookielib.MozillaCookieJar() response = None req = None out_data = None opener = None metadata = None timeout = params.get('timeout', None) if 'host' in params: host = params['host'] else: host = self.HOST if 'header' in params: headers = params['header'] elif None != self.HEADER: headers = self.HEADER else: headers = { 'User-Agent' : host } if 'User-Agent' not in headers: headers['User-Agent'] = host metadata = {} printDBG('pCommon - getURLRequestData() -> params: ' + str(params)) printDBG('pCommon - getURLRequestData() -> headers: ' + str(headers)) customOpeners = [] #cookie support if 'use_cookie' not in params and 'cookiefile' in params and ('load_cookie' in params or 'save_cookie' in params): params['use_cookie'] = True if params.get('use_cookie', False): if params.get('load_cookie', False): try: cj.load(params['cookiefile'], ignore_discard = True) except IOError: printDBG('Cookie file [%s] not exists' % params['cookiefile']) except Exception: printExc() try: for cookieKey in params.get('cookie_items', {}).keys(): printDBG("cookie_item[%s=%s]" % (cookieKey, params['cookie_items'][cookieKey])) cookieItem = cookielib.Cookie(version=0, name=cookieKey, value=params['cookie_items'][cookieKey], port=None, port_specified=False, domain='', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False) cj.set_cookie(cookieItem) except Exception: printExc() customOpeners.append( urllib2.HTTPCookieProcessor(cj) ) if params.get('no_redirection', False): customOpeners.append( NoRedirection() ) # debug #customOpeners.append(urllib2.HTTPSHandler(debuglevel=1)) #customOpeners.append(urllib2.HTTPHandler(debuglevel=1)) if not IsHttpsCertValidationEnabled(): try: if params.get('ssl_protocol', None) != None: ctx = ssl._create_unverified_context(params['ssl_protocol']) else: ctx = ssl._create_unverified_context() customOpeners.append(urllib2.HTTPSHandler(context=ctx)) except Exception: pass elif params.get('ssl_protocol', None) != None: ctx = ssl.SSLContext(params['ssl_protocol']) customOpeners.append(urllib2.HTTPSHandler(context=ctx)) #proxy support if self.useProxy: http_proxy = self.proxyURL else: http_proxy = '' #proxy from parameters (if available) overwrite default one if 'http_proxy' in params: http_proxy = params['http_proxy'] if '' != http_proxy: printDBG('getURLRequestData USE PROXY') customOpeners.append( urllib2.ProxyHandler({"http":http_proxy}) ) customOpeners.append( urllib2.ProxyHandler({"https":http_proxy}) ) pageUrl = params['url'] proxy_gateway = params.get('proxy_gateway', '') if proxy_gateway != '': pageUrl = proxy_gateway.format(urllib.quote_plus(pageUrl, '')) printDBG("pageUrl: [%s]" % pageUrl) if None != post_data: printDBG('pCommon - getURLRequestData() -> post data: ' + str(post_data)) if params.get('raw_post_data', False): dataPost = post_data elif params.get('multipart_post_data', False): customOpeners.append( MultipartPostHandler() ) dataPost = post_data else: dataPost = urllib.urlencode(post_data) req = urllib2.Request(pageUrl, dataPost, headers) else: req = urllib2.Request(pageUrl, None, headers) if not params.get('return_data', False): out_data = urlOpen(req, customOpeners, timeout) else: gzip_encoding = False try: response = urlOpen(req, customOpeners, timeout) if response.info().get('Content-Encoding') == 'gzip': gzip_encoding = True try: metadata['url'] = response.geturl() metadata['status_code'] = response.getcode() if 'Content-Type' in response.info(): metadata['content-type'] = response.info()['Content-Type'] except Exception: pass data = response.read() response.close() except urllib2.HTTPError, e: ignoreCodeRanges = params.get('ignore_http_code_ranges', [(404, 404), (500, 500)]) ignoreCode = False metadata['status_code'] = e.code for ignoreCodeRange in ignoreCodeRanges: if e.code >= ignoreCodeRange[0] and e.code <= ignoreCodeRange[1]: ignoreCode = True break if ignoreCode: printDBG('!!!!!!!! %s: getURLRequestData - handled' % e.code) if e.fp.info().get('Content-Encoding', '') == 'gzip': gzip_encoding = True try: metadata['url'] = e.fp.geturl() if 'Content-Type' in e.fp.info(): metadata['content-type'] = e.fp.info()['Content-Type'] except Exception: pass data = e.fp.read() #e.msg #e.headers elif e.code == 503: if params.get('use_cookie', False): new_cookie = e.fp.info().get('Set-Cookie', '') printDBG("> new_cookie[%s]" % new_cookie) cj.save(params['cookiefile'], ignore_discard = True) raise e else: if e.code in [300, 302, 303, 307] and params.get('use_cookie', False) and params.get('save_cookie', False): new_cookie = e.fp.info().get('Set-Cookie', '') printDBG("> new_cookie[%s]" % new_cookie) #for cookieKey in params.get('cookie_items', {}).keys(): # cj.clear('', '/', cookieKey) cj.save(params['cookiefile'], ignore_discard = True) raise e try: if gzip_encoding: printDBG('Content-Encoding == gzip') buf = StringIO(data) f = gzip.GzipFile(fileobj=buf) out_data = f.read() else: out_data = data except Exception as e: printExc() msg1 = _("Critical Error – Content-Encoding gzip cannot be handled!") msg2 = _("Last error:\n%s" % str(e)) GetIPTVNotify().push('%s\n\n%s' % (msg1, msg2), 'error', 20) out_data = data
except Exception as e: printExc() msg1 = _("Critical Error – Content-Encoding gzip cannot be handled!") msg2 = _("Last error:\n%s" % str(e)) GetIPTVNotify().push('%s\n\n%s' % (msg1, msg2), 'error', 20) out_data = data if params.get('use_cookie', False) and params.get('save_cookie', False): try: cj.save(params['cookiefile'], ignore_discard = True) except Exception as e: printExc() msg1 = _("Critical Error – cookie can't be saved!") msg2 = _("Last error:\n%s" % str(e)) msg3 = _("Please make sure that the folder for cache data (set in the configuration) is writable.") GetIPTVNotify().push('%s\n\n%s\n\n%s' % (msg1, msg2, msg3), 'error', 20) SetTmpCookieDir() raise e if params.get('return_data', False) and params.get('convert_charset', True) : encoding = '' if 'content-type' in metadata: encoding = self.ph.getSearchGroups(metadata['content-type'], '''charset=([A-Za-z0-9\-]+)''', 1, True)[0].strip().upper() if encoding == '' and params.get('search_charset', False): encoding = self.ph.getSearchGroups(out_data, '''(<meta[^>]+?Content-Type[^>]+?>)''', ignoreCase=True)[0] encoding = self.ph.getSearchGroups(encoding, '''charset=([A-Za-z0-9\-]+)''', 1, True)[0].strip().upper() if encoding not in ['', 'UTF-8']: printDBG(">> encoding[%s]" % encoding) try:
def tryTologin(self): printDBG('tryTologin start') if None == self.loggedIn or self.login != config.plugins.iptvplayer.allboxtv_login.value or\ self.password != config.plugins.iptvplayer.allboxtv_password.value: self.login = config.plugins.iptvplayer.allboxtv_login.value self.password = config.plugins.iptvplayer.allboxtv_password.value rm(self.COOKIE_FILE) self.loggedIn = False self.loginMessage = '' if '' == self.login.strip() or '' == self.password.strip(): msg = _('The host %s requires registration. \nPlease fill your login and password in the host configuration. Available under blue button.' % self.getMainUrl()) GetIPTVNotify().push(msg, 'info', 10) return False sts, data = self.getPage(self.getMainUrl()) if not sts: return False url = self.getFullUrl('/logowanie') sts, data = self.getPage(url) if not sts: return False sts, data = self.cm.ph.getDataBeetwenNodes(data, ('<form', '>', 'loginForm'), ('</form', '>')) if not sts: return False actionUrl = self.getFullUrl(self.cm.ph.getSearchGroups(data, '''action=['"]([^'^"]+?)['"]''')[0]) if actionUrl == '': actionUrl = url data = self.cm.ph.getAllItemsBeetwenMarkers(data, '<input', '>') post_data = {} for item in data: name = self.cm.ph.getSearchGroups(item, '''name=['"]([^'^"]+?)['"]''')[0] value = self.cm.ph.getSearchGroups(item, '''value=['"]([^'^"]+?)['"]''')[0] post_data[name] = value post_data.update({'email':self.login, 'password':self.password, 'form_login_rememberme':'on'}) httpParams = dict(self.defaultParams) httpParams['header'] = dict(httpParams['header']) httpParams['header']['Referer'] = url sts, data = self.cm.getPage(actionUrl, httpParams, post_data) if sts and '/wyloguj' in data: printDBG('tryTologin OK') self.loggedIn = True data = self.cm.ph.getDataBeetwenNodes(data, ('<', '>', 'mobile-header'), ('</ul', '>'))[1] data = self.cm.ph.getAllItemsBeetwenMarkers(data, '<li', '</li>') self.loginMessage = [] for item in data: item = self.cleanHtmlStr(item) if item == '': continue self.loginMessage.append(item) self.loginMessage = '[/br]'.join(self.loginMessage) else: if sts: errMsg = [] tmp = self.cm.ph.getAllItemsBeetwenNodes(data, ('<span', '>', 'required'), ('</span', '>'), False) for it in tmp: errMsg.append(self.cleanHtmlStr(it)) else: errMsg = [_('Connection error.')] self.sessionEx.open(MessageBox, _('Login failed.') + '\n' + '\n'.join(errMsg), type = MessageBox.TYPE_ERROR, timeout = 10) printDBG('tryTologin failed') return self.loggedIn