def downloadAndUnpack(self, url, params={}, post_data=None, unpackToSubDir=False): data, fileName = self.downloadFileData(url, params, post_data) if data == None: return None ext = fileName.rsplit('.', 1)[-1].lower() printDBG("fileName[%s] ext[%s]" % (fileName, ext)) if ext not in ['zip', 'rar']: SetIPTVPlayerLastHostError(_('Unknown file extension "%s".') % ext) return None tmpFile = GetTmpDir( self.TMP_FILE_NAME ) tmpArchFile = tmpFile + '.' + ext tmpDIR = '' if unpackToSubDir: dirName = fileName.rsplit('.', 1)[0].split('filename=', 1)[-1] if dirName != '': tmpDIR = GetSubtitlesDir(dirName) if tmpDIR == '': tmpDIR = GetTmpDir(self.TMP_DIR_NAME) printDBG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") printDBG(fileName) printDBG(tmpFile) printDBG(tmpArchFile) printDBG(tmpDIR) printDBG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") if not self.writeFile(tmpArchFile, data): return None if not self.unpackArchive(tmpArchFile, tmpDIR): rm(tmpArchFile) return None return tmpDIR
def downloadAndUnpack(self, url, params={}, post_data=None): data, fileName = self.downloadFileData(url, params, post_data) if data == None: return None ext = fileName.split('.')[-1].lower() if ext not in ['zip', 'rar']: SetIPTVPlayerLastHostError(_('Unknown file extension "%s".') % ext) return None tmpFile = GetTmpDir(self.TMP_FILE_NAME) tmpArchFile = tmpFile + '.' + ext tmpDIR = GetTmpDir(self.TMP_DIR_NAME) printDBG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") printDBG(fileName) printDBG(tmpFile) printDBG(tmpArchFile) printDBG(tmpDIR) printDBG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") if not self.writeFile(tmpArchFile, data): return None if not self.unpackArchive(tmpArchFile, tmpDIR): rm(tmpArchFile) return None return tmpDIR
def update_now_zip(self,cItem): restart=cItem.get('retstart',True) printDBG('TSIplayer: Start Update' ) tmpDir = GetTmpDir() source = os_path.join(tmpDir, 'archive.zip') dest = os_path.join(tmpDir , '') #_url = 'https://gitlab.com/Rgysoft/iptv-host-e2iplayer/repository/archive.zip' _url = 'https://gitlab.com/Rgysoft/iptv-host-e2iplayer/-/archive/master/iptv-host-e2iplayer-master.zip' try: download_url(_url,source) #output = open(source,'w') #output.write(self.cm.getPage(_url)[1]) #output.close() os_system ('sync') DBG('TSIplayer: Download archive.zip OK' ) except: if os_path.exists(source): os_remove(source) printDBG('TSIplayer: Download Error archive.zip' ) return '' cmd = 'unzip -o "%s" -d "%s"' % ( source, dest ) try: os_system (cmd) os_system ('sync') printDBG('TSIplayer(zip): Unpacking OK' ) except: printDBG( 'TSIplayer(zip): Unpacking Error' ) os_system ('rm -f %s' % source) os_system ('rm -rf /tmp/iptv-host-e2iplayer*/IPTVPlayer') return '' try: os_system ('cp -rf /tmp/iptv-host-e2iplayer*/IPTVPlayer /usr/lib/enigma2/python/Plugins/Extensions') os_system ('sync') printDBG('TSIplayer(Zip): Copy OK') except: printDBG('TSIplayer(Zip): Copy Error') os_system ('rm -f %s' % source) os_system ('rm -rf /tmp/iptv-host-e2iplayer*/IPTVPlayer') return '' printDBG( 'TSIplayer: Deleting temporary files' ) os_system ('rm -f %s' % source) os_system ('rm -rf /tmp/iptv-host-e2iplayer*/IPTVPlayer') if restart: try: from enigma import quitMainloop quitMainloop(3) except Exception as e: printDBG( 'TSIplayer: Erreur='+str(e) ) pass params = {'category' : 'none','title':'Update End. Please manual restart enigma2','name':'update'} self.addDir(params) return ''
def processCaptcha(self, key): post_data = None token = '' iteration = 0 reCaptchaUrl = 'https://www.google.com/recaptcha/api/noscript?k=%s' % (key) while iteration < 20: sts, data = self.cm.getPage(reCaptchaUrl, {'header': self.HTTP_HEADER, 'raw_post_data': True}, post_data=post_data) if not sts: SetIPTVPlayerLastHostError(_('Fail to get "%s".') % reCaptchaUrl) return '' imgUrl = self.cm.ph.getSearchGroups(data, 'src="(image[^"]+?)"')[0] iteration += 1 message = self.cm.ph.getSearchGroups(data, '<p[^>]*>([^<]+?)</p>')[0] token = self.cm.ph.getSearchGroups(data, '<textarea[^>]*>([^<]+?)</textarea>')[0] if '' != token: printDBG('>>>>>>>> Captcha token[%s]' % (token)) break elif message == '': printDBG('>>>>>>>> Captcha Failed') break recaptcha_challenge_field = self.cm.ph.getSearchGroups(data, 'name="recaptcha_challenge_field"[^>]+?value="([^"]+)"')[0] imgUrl = 'https://www.google.com/recaptcha/api/%s' % (imgUrl.replace('&', '&')) message = clean_html(message) accepLabel = clean_html(self.cm.ph.getSearchGroups(data, 'type="submit"[^>]+?value="([^"]+)"')[0]) filePath = GetTmpDir('.iptvplayer_captcha.jpg') printDBG(">>>>>>>> Captcha message[%s]" % (message)) printDBG(">>>>>>>> Captcha accep label[%s]" % (accepLabel)) printDBG(">>>>>>>> Captcha imgUrl[%s] filePath[%s]" % (imgUrl, filePath)) params = {'maintype': 'image', 'subtypes': ['jpeg'], 'check_first_bytes': ['\xFF\xD8', '\xFF\xD9']} ret = self.cm.saveWebFile(filePath, imgUrl, params) if not ret.get('sts'): SetIPTVPlayerLastHostError(_('Fail to get "%s".') % imgUrl) break params = deepcopy(IPTVMultipleInputBox.DEF_PARAMS) params['accep_label'] = _('Send') params['title'] = accepLabel params['list'] = [] item = deepcopy(IPTVMultipleInputBox.DEF_INPUT_PARAMS) item['label_size'] = (300, 57) item['input_size'] = (300, 25) item['icon_path'] = filePath item['input']['text'] = '' params['list'].append(item) ret = 0 retArg = self.sessionEx.waitForFinishOpen(IPTVMultipleInputBox, params) printDBG('>>>>>>>> Captcha response[%s]' % (retArg)) if retArg is not None and len(retArg) and retArg[0]: recaptcha_response_field = retArg[0] printDBG('>>>>>>>> Captcha recaptcha_response_field[%s]' % (recaptcha_response_field)) post_data = urllib.urlencode({'recaptcha_challenge_field': recaptcha_challenge_field, 'recaptcha_response_field': recaptcha_response_field, 'submit': accepLabel}, doseq=True) else: break return token
def __init__(self, session, allowTheSameVersion=False): printDBG("UpdateMainAppImpl.__init__ -------------------------------") self.session = session IUpdateObjectInterface.__init__(self, session) self.cm = common() self.allowTheSameVersion = allowTheSameVersion self.setup_title = _("IPTVPlayer - update") self.tmpDir = GetTmpDir('iptv_update') self.ExtensionPath = resolveFilename(SCOPE_PLUGINS, 'Extensions/') self.ExtensionTmpPath = None self.terminating = False self.status = 'none' self.downloader = None self.cmd = None self.serversList = [] self.currServIdx = 0 self.sourceArchive = None self.destinationArchive = None self.serverIdx = 0 self.messages = {} self.messages['completed'] = _("Completed.") self.messages['problem_removal'] = _( "Problem with the removal of the previous version.\nStatus[%d], outData[%s]." ) self.messages['problem_install'] = _( "Problem with installing the new version.\nStatus[%d], outData[%s]" )
def _startDownloader(self, sts, reason): if sts: self.downloader.subscribeFor_Finish(self.downloadFinished) url,downloaderParams = DMHelper.getDownloaderParamFromUrl(self.currItem.get('url', '')) self.downloader.start(url, GetTmpDir(self._TMP_FILE_NAME), downloaderParams) else: self["console"].setText(_("Download can not be started.\nDownloader %s not working correctly.\nStatus[%s]"))
def doDownloadSubtitle(self, item): self.setListMode(False) self["console"].setText(_('Download subtitle "%s"') % item.name) self["console"].show() tmpDir = GetTmpDir() subDir = GetSubtitlesDir() self.subProvider.doDowanloadSubtitle(self.doDownloadSubtitleCallback, item.privateData, tmpDir, subDir)
def listIso(self, cItem): printDBG("LocalMedia.listIso [%s]" % cItem) # check if iso file is mounted path = cItem['path'] defaultMountPoint = GetTmpDir(self.ISO_MOUNT_POINT_NAME) defaultMountPoint = defaultMountPoint.replace('//', '/') mountPoint = self.getMountPoint(path) if '' == mountPoint: # umount if different image already mounted if self.isMountPoint(defaultMountPoint): cmd = 'umount "{0}"'.format(defaultMountPoint) + ' 2>&1' ret = iptv_execute_wrapper(cmd) if ret['sts'] and 0 != ret['code']: # normal umount failed, so detach filesystem only cmd = 'umount -l "{0}"'.format(defaultMountPoint) + ' 2>&1' ret = iptv_execute_wrapper(cmd) # now mount the iso file if not mkdirs(defaultMountPoint): message = _('Make directory [%s]') % (defaultMountPoint) self.showErrorMessage(message) return else: cmd = 'mount -r "{0}" "{1}"'.format( path, defaultMountPoint) + ' 2>&1' ret = iptv_execute_wrapper(cmd) if ret['sts']: if 0 != ret['code']: message = _( 'Mount ISO file [%s] on [%s] failed.\nReturn code[%s].\nReturn data[%s].' ) % (path, defaultMountPoint, ret['code'], ret['data']) self.showErrorMessage(message) return else: mountPoint = defaultMountPoint if '' != mountPoint: params = dict(cItem) params.update({ 'next_good_for_fav': False, 'path': mountPoint, 'category': 'dir' }) self.listDir(params)
def processCaptcha(self, key, referer=None): post_data = None token = '' iteration = 0 if referer != None: self.HTTP_HEADER['Referer'] = referer reCaptchaUrl = 'http://www.google.com/recaptcha/api/fallback?k=%s' % (key) while iteration < 20: #,'cookiefile':self.COOKIE_FILE, 'use_cookie': True, 'load_cookie': True, 'save_cookie':True sts, data = self.cm.getPage(reCaptchaUrl, {'header':self.HTTP_HEADER, 'raw_post_data':True}, post_data=post_data) if not sts: SetIPTVPlayerLastHostError(_('Fail to get "%s".') % reCaptchaUrl) return '' printDBG("+++++++++++++++++++++++++++++++++++++++++") printDBG(data) printDBG("+++++++++++++++++++++++++++++++++++++++++") imgUrl = ph.search(data, '"(/recaptcha/api2/payload[^"]+?)"')[0] iteration += 1 message = ph.clean_html(ph.find(data, ('<div', '>', 'imageselect-desc'), '</div>', flags=0)[1]) if not message: message = ph.clean_html(ph.find(data, ('<label', '>', 'fbc-imageselect-message-text'), '</label>', flags=0)[1]) if not message: message = ph.clean_html(ph.find(data, ('<div', '>', 'imageselect-message'), '</div>', flags=0)[1]) if '' == message: token = ph.find(data, ('<div', '>', 'verification-token'), '</div>', flags=0)[1] token = ph.find(data, ('<textarea', '>'), '</textarea>', flags=0)[1].strip() if token == '': token = ph.search(data, '"this\.select\(\)">(.*?)</textarea>')[0] if token == '': token = ph.find(data, ('<textarea', '>'), '</textarea>', flags=0)[1].strip() if '' != token: printDBG('>>>>>>>> Captcha token[%s]' % (token)) else: printDBG('>>>>>>>> Captcha Failed\n\n%s\n\n' % data) break cval = ph.search(data, 'name="c"\s+value="([^"]+)')[0] imgUrl = 'https://www.google.com%s' % (imgUrl.replace('&', '&')) message = ph.clean_html(message) accepLabel = ph.clean_html(ph.search(data, 'type="submit"\s+value="([^"]+)')[0]) filePath = GetTmpDir('.iptvplayer_captcha.jpg') printDBG(">>>>>>>> Captcha message[%s]" % (message)) printDBG(">>>>>>>> Captcha accep label[%s]" % (accepLabel)) printDBG(">>>>>>>> Captcha imgUrl[%s] filePath[%s]" % (imgUrl, filePath)) params = {'maintype': 'image', 'subtypes':['jpeg'], 'check_first_bytes':['\xFF\xD8','\xFF\xD9']} ret = self.cm.saveWebFile(filePath, imgUrl, params) if not ret.get('sts'): SetIPTVPlayerLastHostError(_('Fail to get "%s".') % imgUrl) break retArg = self.sessionEx.waitForFinishOpen(UnCaptchaReCaptchaWidget, imgFilePath=filePath, message=message, title="reCAPTCHA v2", additionalParams={'accep_label':accepLabel}) printDBG('>>>>>>>> Captcha response[%s]' % (retArg)) if retArg is not None and len(retArg) and retArg[0]: answer = retArg[0] printDBG('>>>>>>>> Captcha answer[%s]' % (answer)) post_data = urllib.urlencode({'c': cval, 'response':answer}, doseq=True) else: break return token
def stepRemoveUnnecessaryFiles(self): printDBG("stepRemoveUnnecessaryFiles") playerSelectorPath = os_path.join(self.ExtensionTmpPath, 'IPTVPlayer/icons/PlayerSelector/') logosPath = os_path.join(self.ExtensionTmpPath, 'IPTVPlayer/icons/logos/') hostsPath = os_path.join(self.ExtensionTmpPath, 'IPTVPlayer/hosts/') webPath = os_path.join(self.ExtensionTmpPath, 'IPTVPlayer/Web/') cmds = [] iconSize = int(config.plugins.iptvplayer.IconsSize.value) if not config.plugins.iptvplayer.ListaGraficzna.value: iconSize = 0 for size in [135, 120, 100]: if size != iconSize: cmds.append('rm -f %s' % (playerSelectorPath + '*{0}.png'.format(size))) cmds.append( 'rm -f %s' % (playerSelectorPath + 'marker{0}.png'.format(size + 45))) # remove Web iterface module if not needed if not config.plugins.iptvplayer.IPTVWebIterface.value: cmds.append('rm -rf %s' % (webPath)) # removing not needed hosts if config.plugins.iptvplayer.remove_diabled_hosts.value: enabledHostsList = GetEnabledHostsList() hostsFromList = GetHostsList(fromList=True, fromHostFolder=False) hostsFromFolder = GetHostsList(fromList=False, fromHostFolder=True) hostsToRemove = [] for hostItem in hostsFromList: if hostItem not in enabledHostsList and hostItem in hostsFromFolder: cmds.append( 'rm -f %s' % (playerSelectorPath + '{0}*.png'.format(hostItem))) cmds.append('rm -f %s' % (logosPath + '{0}logo.png'.format(hostItem))) cmds.append('rm -f %s' % (hostsPath + 'host{0}.py*'.format(hostItem))) # we need to prepare temporary file with removing cmds because cmd can be to long cmdFilePath = GetTmpDir('.iptv_remove_cmds.sh') cmds.insert(0, '#!/bin/sh') cmds.append('exit 0\n') text = '\n'.join(cmds) WriteTextFile(cmdFilePath, text, 'ascii') cmd = '/bin/sh "{0}" '.format(cmdFilePath) #cmd = '/bin/sh "{0}" && rm -rf "{1}" '.format(cmdFilePath, cmdFilePath) else: cmd = ' && '.join(cmds) printDBG("stepRemoveUnnecessaryFiles cmdp[%s]" % cmd) self.cmd = iptv_system(cmd, self.__removeUnnecessaryFilesCmdFinished)
def listIso(self, cItem): printDBG("LocalMedia.listIso [%s]" % cItem) # check if iso file is mounted path = cItem['path'] defaultMountPoint = GetTmpDir(self.ISO_MOUNT_POINT_NAME) defaultMountPoint = defaultMountPoint.replace('//', '/') mountPoint = self.getMountPoint(path) if '' == mountPoint: # umount if different image already mounted if self.isMountPoint(defaultMountPoint): cmd = 'umount "{0}"'.format(defaultMountPoint) + ' 2>&1' ret = iptv_execute()(cmd) if ret['sts'] and 0 != ret['code']: # normal umount failed, so detach filesystem only cmd = 'umount -l "{0}"'.format(defaultMountPoint) + ' 2>&1' ret = iptv_execute()(cmd) # now mount the iso file if not mkdirs(defaultMountPoint): message = _('Make directory [%s]') % (defaultMountPoint) self.showErrorMessage(message) return else: cmd = 'mount -r "{0}" "{1}"'.format(path, defaultMountPoint) + ' 2>&1' ret = iptv_execute()(cmd) if ret['sts']: if 0 != ret['code']: message = _('Mount ISO file [%s] on [%s] failed.\nReturn code[%s].\nReturn data[%s].') % (path, defaultMountPoint, ret['code'], ret['data']) self.showErrorMessage(message) return else: mountPoint = defaultMountPoint if '' != mountPoint: params = dict(cItem) params.update( {'path':mountPoint, 'category':'dir'} ) self.listDir(params)
def onStart(self): self.onLayoutFinish.remove(self.onStart) for n_img in range(self.numOfImg): self['puzzle_image_%d' % n_img].updateIcon( GetTmpDir('.iptvplayer_hcaptcha_%d.jpg' % n_img)) self['marker'].setPixmap(self.markerPixmap) self['marker'].show() for x in range(self.numOfCol): for y in range(self.numOfRow): strIndex = "cover_%s%s" % (x, y) self[strIndex].setPixmap(self.selectPixmap) self[strIndex].hide()
def captcha(self): self.USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0' self.HTTP_HEADER = {'User-Agent': self.USER_AGENT, 'DNT':'1', 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Accept-Encoding':'gzip, deflate', 'Referer':'https://zalukaj.com/', 'Origin':'https://zalukaj.com/'} self.defaultParams = {'header':self.HTTP_HEADER, 'with_metadata':True, 'use_cookie': True, 'load_cookie': True, 'save_cookie': True, 'cookiefile': self.COOKIE_FILE} httpParams = dict(self.defaultParams) imgUrl = 'https://zalukaj.com/captcha-image' from copy import deepcopy from Plugins.Extensions.IPTVPlayer.components.iptvmultipleinputbox import IPTVMultipleInputBox from Plugins.Extensions.IPTVPlayer.components.asynccall import MainSessionWrapper self.sessionEx = MainSessionWrapper() captchaTitle = '' captchaLabel = _('Captcha') captchaTitle = captchaLabel sendLabel = _('Send') header = dict(self.HTTP_HEADER) header['Accept'] = 'image/png,image/*;q=0.8,*/*;q=0.5' params = dict(self.defaultParams) params.update( {'maintype': 'image', 'subtypes':['jpeg', 'png'], 'check_first_bytes':['\xFF\xD8','\xFF\xD9','\x89\x50\x4E\x47'], 'header':header} ) filePath = GetTmpDir('.iptvplayer_captcha.jpg') rm(filePath) ret = self.cm.saveWebFile(filePath, imgUrl.replace('&', '&'), params) if not ret.get('sts'): SetIPTVPlayerLastHostError(_('Fail to get "%s".') % imgUrl) return [] params = deepcopy(IPTVMultipleInputBox.DEF_PARAMS) params['accep_label'] = sendLabel params['title'] = captchaLabel params['status_text'] = captchaTitle params['status_text_hight'] = 200 params['with_accept_button'] = True params['list'] = [] item = deepcopy(IPTVMultipleInputBox.DEF_INPUT_PARAMS) item['label_size'] = (660,110) item['input_size'] = (680,25) item['icon_path'] = filePath item['title'] = _('Answer') item['input']['text'] = '' params['list'].append(item) params['vk_params'] = {'invert_letters_case':True} ret = 0 retArg = self.sessionEx.waitForFinishOpen(IPTVMultipleInputBox, params) printDBG(retArg) if retArg and len(retArg) and retArg[0]: return retArg[0][0].lower() else: return []
def __init__(self, session): printDBG("UpdateMainAppImpl.__init__ -------------------------------") self.session = session IUpdateObjectInterface.__init__(self, session) self.cm = common() self.setup_title = _("IPTVPlayer - update") self.tmpDir = GetTmpDir('iptv_update') self.ExtensionPath = resolveFilename(SCOPE_PLUGINS, 'Extensions/') self.ExtensionTmpPath = None self.terminating = False self.status = 'none' self.downloader = None self.cmd = None self.serversList = [] self.currServIdx = 0 self.sourceArchive = None self.destinationArchive = None self.serverIdx = 0
def getVideoLink(self, cItem): printDBG("FirstOneTvApi.getVideoLink") urlsTab = [] sts, data = self.cm.getPage(cItem['url'], self.http_params) if not sts: return urlsTab cUrl = self.cm.meta['url'] SRC_URI_RE = re.compile(r'''\s+?src=(['"])([^>]*?)(?:\1)''', re.I) jscode1 = '' # var LOGGEDIN jscode2 = '' # cToken streamJs = '' tmp = ph.findall(data, ('<script', '>'), '</script>', flags=ph.START_S) for idx in range(1, len(tmp), 2): if 'cToken' in tmp[idx]: jscode2 = tmp[idx] elif 'var LOGGEDIN' in tmp[idx]: jscode1 = tmp[idx] elif 'stream:' in tmp[idx-1]: streamJs = ph.search(tmp[idx-1], SRC_URI_RE)[1] country = ph.search(jscode2, '''country\s*?=\s*?['"]([^'^"]+?)['"]''')[0] cToken = ph.search(jscode2, '''cToken\s*?=\s*?['"]([^'^"]+?)['"]''')[0] channelID = ph.search(jscode2, '''channelID\s*?=\s*?['"]([^'^"]+?)['"]''')[0] channel_post_data = {'action':'channel', 'ctoken':cToken, 'c':country, 'id':channelID, 'native_hls':'0', 'unsecure_hls':'0'} url = self.getFullUrl('/api/?cacheFucker=' + str(random.random()), cUrl) post_data = {'action':'tracking', 'act':'get', 'c':country, 'id':channelID} params = dict(self.http_params) params['header'] = MergeDicts(self.HTTP_HEADER, {'Referer':cUrl, 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With':'XMLHttpRequest'}) sts, tmp = self.cm.getPage(url, params, post_data) if not sts: return [] printDBG("+++++tracking+++++") printDBG(tmp) printDBG("++++++++++++++++++") if cToken: ret, links = self._getLinks(cUrl, params, channel_post_data) if links: return links hiroRetry = 0 while hiroRetry < 3: hiroRetry += 1 url = self.getFullUrl('/api/?cacheFucker=' + str(random.random()), cUrl) post_data = {'action':'hiro', 'result':'get'} sts, tmp = self.cm.getPage(url, params, post_data) if not sts: return [] #printDBG("++++++++++++++++++++++++++++++++++") #printDBG(tmp) #printDBG("++++++++++++++++++++++++++++++++++") hiroErrorCode = -1 try: tmp = json_loads(tmp) post_data = {'action':'hiro', 'result':'', 'hash':tmp['hash'], 'time':tmp['time']} streamJsData = None tries = 0 while tries < 5: tries += 1 jscode = list(self.CACHE_VARS.get(streamJs, [])) jscode.append('try {print(eval("%s"));} catch (e) {print(e);}' % tmp['hiro']) ret = js_execute( '\n'.join(jscode) ) if 'identifier' in ret['data'] and 'undefined' in ret['data']: identifier = ph.search(ret['data'], "'([^']+?)'")[0] sts, tmp2 = self.cm.getPage(self.getFullUrl(streamJs, cUrl), self.http_params) if sts: if not streamJsData: jscode2 = ["top={'location':'%s'};self=top;document={'domain':'%s'};window=this;function eval(data){print(data);}" % (cUrl, self.cm.getBaseUrl(cUrl, True)), jscode1] jscode2.append(tmp2) ret = js_execute( '\n'.join(jscode2) ) if 0 != ret['code']: raise Exception('stream script failed') streamJsData = ret['data'] value = ph.search(streamJsData, '[\}\s;](%s=[^;]+?;)' % identifier)[0] if not value: raise Exception('can not find in the "%s" stream script' % identifier) if streamJs not in self.CACHE_VARS: self.CACHE_VARS = {streamJs:[]} self.CACHE_VARS[streamJs].append(value) continue elif ret['code'] == 0: post_data['result'] = ret['data'].strip() url = self.getFullUrl('/api/?cacheFucker=' + str(random.random()), cUrl) sts, tmp = self.cm.getPage(url, params, post_data) if not sts: Exception('can not find in the "%s" stream script' % identifier) tmp = json_loads(tmp) hiroErrorCode = tmp['errorCode'] if tmp['state']: cToken = tmp['ctoken'] channel_post_data['ctoken'] = cToken printDBG("$$$$ hiro $$$") printDBG(tmp) printDBG("$$$$$$$$$$$$$") hiroWorks = True # {'errorCode': 801, 'msg': 'Wrong captcha.', 'state': False, 'ctoken': 'suckmydick'} break except Exception: printExc() if hiroErrorCode == 801: continue break if 0 != hiroErrorCode: # add support for picture capcha statusText = 'Please solve the following captcha to verify that you are human.' while True: url = self.getFullUrl('/src/captcha/?cacheFucker=' + str(random.random()), cUrl) sts, data = self.cm.getPage(url, params) if not sts: return [] try: data = json_loads(data) post_data = {'action':'captcha', 'response':'', 'hash':data['hash'], 'time':data['time']} pictureMarker = 'data:image/png;base64,' if not data['image'].startswith(pictureMarker): SetIPTVPlayerLastHostError(_('Wrong captcha image data!')) raise Exception('Wrong image data!') image = base64.b64decode(data['image'][len(pictureMarker):]) filePath = GetTmpDir('.iptvplayer_captcha.jpg') with open(filePath, 'wb') as f: f.write(image) except Exception: printExc() return [] params = deepcopy(IPTVMultipleInputBox.DEF_PARAMS) #params['accep_label'] = sendLabel params['title'] = 'Are you Human?' params['status_text'] = statusText params['status_text_hight'] = 200 params['with_accept_button'] = True params['list'] = [] item = deepcopy(IPTVMultipleInputBox.DEF_INPUT_PARAMS) item['label_size'] = (660,110) item['input_size'] = (680,25) item['icon_path'] = filePath item['title'] = _('Answer') item['input']['text'] = '' params['list'].append(item) params['vk_params'] = {'invert_letters_case':True} ret = 0 retArg = self.sessionEx.waitForFinishOpen(IPTVMultipleInputBox, params) printDBG(retArg) if retArg and len(retArg) and retArg[0]: printDBG(retArg[0]) post_data['response'] = retArg[0][0] else: return [] url = self.getFullUrl('/api/?cacheFucker=' + str(random.random()), cUrl) sts, data = self.cm.getPage(url, params, post_data) if sts: try: data = json_loads(data) printDBG("$$$$ captcha $$$") printDBG(data) printDBG("$$$$$$$$$$$$$$$$") hiroErrorCode = data['errorCode'] if data['state']: cToken = data['ctoken'] channel_post_data['ctoken'] = cToken break statusText = data['msg'] + '\n' + 'Please try again.' except Exception: printExc() break return self._getLinks(cUrl, params, channel_post_data)[1]
def getPage(self, baseUrl, addParams = {}, post_data = None): images = [] errorMessages = [] if addParams == {}: addParams = dict(self.defaultParams) baseUrl = self.cm.iriToUri(baseUrl) proxy = config.plugins.iptvplayer.kissanime_proxy.value printDBG(">> " + proxy) if proxy != 'None': if proxy == 'proxy_1': proxy = config.plugins.iptvplayer.alternative_proxy1.value else: proxy = config.plugins.iptvplayer.alternative_proxy2.value addParams = dict(addParams) addParams.update({'http_proxy':proxy}) addParams['cloudflare_params'] = {'domain':self.up.getDomain(baseUrl), 'cookie_file':self.COOKIE_FILE, 'User-Agent':self.USER_AGENT, 'full_url_handle':self.getFullUrl} while True: sts, data = self.cm.getPageCFProtection(baseUrl, addParams, post_data) if sts and 'areyouhuman' in self.cm.meta['url'].lower(): errorMessages = [] formData = '' tmp = self.cm.ph.getAllItemsBeetwenMarkers(data, '<form', '</form>', withMarkers=False, caseSensitive=False) for item in tmp: if 'answerCap' in item: formData = item break messages = [] tmp = self.cm.ph.getAllItemsBeetwenMarkers(formData, '<p', '</p>') for item in tmp: item = self.cleanHtmlStr(item) if item != '': messages.append(item) if len(messages) < 2: errorMessages.append(_('Unknown captcha form! Data: "%s"') % messages) break action = self.cm.ph.getSearchGroups(formData, '''action=['"]([^'^"]+?)['"]''', ignoreCase=True)[0] if action == '': action = '/' action = self.getFullUrl(action) tmp = self.cm.ph.getAllItemsBeetwenMarkers(formData, '<input', '>', False, False) post_data2 = {} for item in tmp: name = self.cm.ph.getSearchGroups(item, '''name=['"]([^'^"]+?)['"]''', ignoreCase=True)[0] value = self.cm.ph.getSearchGroups(item, '''value=['"]([^'^"]+?)['"]''', ignoreCase=True)[0] if name != '': post_data2[name] = value header = dict(self.HTTP_HEADER) header['Accept'] = 'image/png,image/*;q=0.8,*/*;q=0.5' params = dict(self.defaultParams) params.update( {'maintype': 'image', 'subtypes':['jpeg', 'jpg', 'png'], 'check_first_bytes':['\xFF\xD8','\xFF\xD9','\x89\x50\x4E\x47'], 'header':header} ) prevMeta = self.cm.meta images = [] tmp = self.cm.ph.getAllItemsBeetwenMarkers(formData, '<img', '>', False, False) for item in tmp: index = self.cm.ph.getSearchGroups(item, '''indexValue=['"]([^'^"]+?)['"]''', ignoreCase=True)[0] imgUrl = self.getFullIconUrl(self.cm.ph.getSearchGroups(item, '''src=['"]([^'^"]+?)['"]''', ignoreCase=True)[0]) if index != '' and imgUrl != '': filePath = GetTmpDir('.iptvplayer_captcha_picture_%s.jpg' % index) rm(filePath) ret = self.cm.saveWebFile(filePath, imgUrl.replace('&', '&'), params) if ret.get('sts'): images.append({'path':filePath, 'id':index}) continue errorMessages.append(_('Download "%s" in to "%s" failed!') % (imgUrl, filePath)) else: errorMessages.append(_('Unknow data in the captcha item!')) errorMessages.append('item: "%s"' % item) break self.cm.meta = prevMeta if 0 == len(errorMessages): printDBG("++++++++++++++++++++++++++++++++++") printDBG('action: %s' % action) printDBG('post_data: %s' % post_data2) printDBG('images: %s' % images) printDBG("++++++++++++++++++++++++++++++++++") message = '\n'.join(messages[1:]) if ' TWO ' in message: maxSelItems = 2 acceptLabel = None else: maxSelItems = None acceptLabel = _('-- OK --') retArg = self.sessionEx.waitForFinishOpen(IPTVMultipleImageSelectorWidget, title='Captcha', message=message, message_height=100, images=images, image_width=160, image_height=160, accep_label=acceptLabel, max_sel_items=maxSelItems) printDBG(retArg) if retArg and len(retArg) and isinstance(retArg[0], list): printDBG(retArg[0]) post_data2['answerCap'] = ','.join(retArg[0]) + ',' addParams2 = dict(addParams) addParams2['header'] = dict(addParams2['header']) addParams2['header']['Referer'] = prevMeta['url'] sts2, data2 = self.cm.getPageCFProtection(action, addParams, post_data2) #printDBG("++++++++++++++++++++++++++++++++++") #printDBG(data2) #printDBG("++++++++++++++++++++++++++++++++++") if sts2: if 'areyouhuman' in self.cm.meta['url'].lower(): printDBG(">>> TRY AGAIN") continue else: sts, data = sts2, data2 else: self.cm.meta = prevMeta break if len(errorMessages): GetIPTVNotify().push('\n'.join(errorMessages), 'error', 10) #printDBG("++++++++++++++++++++++++++++++++++") #printDBG(data) #printDBG("++++++++++++++++++++++++++++++++++") for item in images: rm(item['path']) return sts, data
def downloadSubtitleFile(self, cItem): printDBG("downloadSubtitleFile") retData = {} title = cItem['title'] lang = cItem['lang'] subId = cItem.get('sub_id', '0') imdbid = cItem['imdbid'] fileName = self._getFileName(title, lang, subId, imdbid) fileName = GetSubtitlesDir(fileName) tmpFile = GetTmpDir(self.TMP_FILE_NAME) urlParams = dict(self.defaultParams) sts, data = self.cm.getPage(cItem['url'], urlParams) if not sts: SetIPTVPlayerLastHostError(_('Failed to page with subtitle link.')) return retData url = self.cm.ph.getSearchGroups( data, '''<meta[^>]+?refresh[^>]+?(https?://[^"^']+?)['"]''')[0] urlParams['max_data_size'] = self.getMaxFileSize() sts, data = self.cm.getPage(url, urlParams) if not sts: SetIPTVPlayerLastHostError(_('Failed to download subtitle.')) return retData try: with open(tmpFile, 'w') as f: f.write(data) except Exception: printExc() SetIPTVPlayerLastHostError( _('Failed to write file "%s".') % tmpFile) return retData printDBG(">>") printDBG(tmpFile) printDBG(fileName) printDBG("<<") def __cleanFiles(all=False): if all: rm(fileName) rm(tmpFile) # detect encoding cmd = '%s "%s"' % (config.plugins.iptvplayer.uchardetpath.value, tmpFile) ret = self.iptv_execute(cmd) if ret['sts'] and 0 == ret['code']: encoding = MapUcharEncoding(ret['data']) if 0 != ret['code'] or 'unknown' in encoding: encoding = '' else: encoding = encoding.strip() else: encoding = '' # convert file to UTF-8 try: with open(tmpFile) as f: data = f.read() try: data = data.decode(encoding).encode('UTF-8') try: with open(fileName, 'w') as f: f.write(data) retData = { 'title': title, 'path': fileName, 'lang': lang, 'imdbid': imdbid, 'sub_id': subId } except Exception: printExc() SetIPTVPlayerLastHostError( _('Failed to write the file "%s".') % fileName) except Exception: printExc() SetIPTVPlayerLastHostError( _('Failed to convert the file "%s" to UTF-8.') % tmpFile) except Exception: printExc() SetIPTVPlayerLastHostError( _('Failed to open the file "%s".') % tmpFile) __cleanFiles() return retData
def tryTologin(self): printDBG('tryTologin start') if PlusDEDE.login == None and PlusDEDE.password == None: if self.readLoginMarker() == self.calcLoginMarker( config.plugins.iptvplayer.plusdede_login.value, config.plugins.iptvplayer.plusdede_password.value): PlusDEDE.login = config.plugins.iptvplayer.plusdede_login.value PlusDEDE.password = config.plugins.iptvplayer.plusdede_password.value else: PlusDEDE.password = '' PlusDEDE.login = '' rm(self.COOKIE_FILE) if True != self.loggedIn or PlusDEDE.login != config.plugins.iptvplayer.plusdede_login.value or\ PlusDEDE.password != config.plugins.iptvplayer.plusdede_password.value: if True != self.loggedIn and PlusDEDE.login == config.plugins.iptvplayer.plusdede_login.value and\ PlusDEDE.password == config.plugins.iptvplayer.plusdede_password.value: sts, data = self.getPage(self.getMainUrl()) if sts: token = self.cm.ph.getSearchGroups( data, '''(<meta[^>]+?_token[^>]+?/>)''')[0] token = self.cm.ph.getSearchGroups( token, '''content=['"]([^"^']+?)['"]''')[0] if '' != token and '/logout' in data: self.HTTP_HEADER['X-CSRF-TOKEN'] = token self.AJAX_HEADER['X-CSRF-TOKEN'] = token self.loggedIn = True return True PlusDEDE.login = config.plugins.iptvplayer.plusdede_login.value PlusDEDE.password = config.plugins.iptvplayer.plusdede_password.value self.saveLoginMarker() rm(self.COOKIE_FILE) self.loggedIn = False if '' == PlusDEDE.login.strip() or '' == PlusDEDE.password.strip(): self.sessionEx.open( MessageBox, _('The host %s requires registration. \nPlease fill your login and password in the host configuration. Available under blue button.' % self.getMainUrl()), type=MessageBox.TYPE_ERROR, timeout=10) return False url = self.getFullUrl('/login?popup=1') sts, data = self.getPage(url) if not sts: return False sts, tmp = self.cm.ph.getDataBeetwenNodes(data, ('<form', '>'), ('</form', '>')) if not sts: return False actionUrl = self.getFullUrl( self.cm.ph.getSearchGroups(tmp, '''action=['"]([^'^"]+?)['"]''')[0]) tmp = self.cm.ph.getAllItemsBeetwenMarkers(tmp, '<input', '>') post_data = {} for item in tmp: name = self.cm.ph.getSearchGroups( item, '''name=['"]([^'^"]+?)['"]''')[0] value = self.cm.ph.getSearchGroups( item, '''value=['"]([^'^"]+?)['"]''')[0] post_data[name] = value post_data.update({ 'email': PlusDEDE.login, 'password': PlusDEDE.password }) # fill captcha ############################################################################################# imgUrl = self.getFullUrl( self.cm.ph.getSearchGroups( data, '''<img[^>]+?src=['"]([^"^']+?)['"]''')[0]) if self.cm.isValidUrl(imgUrl): header = dict(self.HTTP_HEADER) header['Accept'] = 'image/png,image/*;q=0.8,*/*;q=0.5' params = dict(self.defaultParams) params.update({ 'maintype': 'image', 'subtypes': ['jpeg', 'png'], 'check_first_bytes': ['\xFF\xD8', '\xFF\xD9', '\x89\x50\x4E\x47'], 'header': header }) filePath = GetTmpDir('.iptvplayer_captcha.jpg') ret = self.cm.saveWebFile(filePath, imgUrl.replace('&', '&'), params) if not ret.get('sts'): SetIPTVPlayerLastHostError(_('Fail to get "%s".') % imgUrl) return False params = deepcopy(IPTVMultipleInputBox.DEF_PARAMS) params['accep_label'] = self.cleanHtmlStr( self.cm.ph.getDataBeetwenNodes(data, ('<button', '>', 'submit'), ('</button', '>'))[1]) params['title'] = _('Captcha') params['status_text'] = self.cleanHtmlStr( self.cm.ph.getDataBeetwenNodes(data, ('<label', '>', 'captcha'), ('</label', '>'))[1]) params['with_accept_button'] = True params['list'] = [] item = deepcopy(IPTVMultipleInputBox.DEF_INPUT_PARAMS) item['label_size'] = (300, 80) item['input_size'] = (480, 25) item['icon_path'] = filePath item['title'] = _('Answer') item['input']['text'] = '' params['list'].append(item) ret = 0 retArg = self.sessionEx.waitForFinishOpen( IPTVMultipleInputBox, params) printDBG(retArg) if retArg and len(retArg) and retArg[0]: printDBG(retArg[0]) name = self.cm.ph.getDataBeetwenNodes( data, ('<input', '>', 'captcha'), ('</input', '>'))[1] printDBG(name) name = self.cm.ph.getSearchGroups( name, '''name=['"]([^"^']+?)['"]''')[0] printDBG(name) post_data['captcha'] = retArg[0][0] ############################################################################################# httpParams = dict(self.defaultParams) httpParams['header'] = dict(self.AJAX_HEADER) httpParams['header']['Referer'] = url httpParams['header']['X-CSRF-TOKEN'] = self.cm.ph.getSearchGroups( data, '''(<meta[^>]+?_token[^>]+?/>)''')[0] httpParams['header']['X-CSRF-TOKEN'] = self.cm.ph.getSearchGroups( httpParams['header']['X-CSRF-TOKEN'], '''content=['"]([^"^']+?)['"]''')[0] error = '' sts, data = self.cm.getPage(actionUrl, httpParams, post_data) try: tmp = json_loads(data)['content'] printDBG(tmp) tmp = self.cm.ph.getAllItemsBeetwenNodes( tmp, ('<div', '>', 'alert'), ('</div', '>')) tab = [] for t in tmp: t = self.cleanHtmlStr(t) if t == '': continue tab.append(t) error = ', '.join(tab) except Exception: printExc() sts, data = self.getPage(self.getMainUrl()) if sts and '/logout' in data: self.HTTP_HEADER['X-CSRF-TOKEN'] = httpParams['header'][ 'X-CSRF-TOKEN'] self.AJAX_HEADER['X-CSRF-TOKEN'] = httpParams['header'][ 'X-CSRF-TOKEN'] self.loggedIn = True else: if error == '': error = _('Login failed.') SetIPTVPlayerLastHostError(error) printDBG('tryTologin failed') return self.loggedIn
def getVideoLinks(self, videoUrl): printDBG("EFilmyTv.getVideoLinks [%s]" % videoUrl) self.tryTologin() videoUrl = strwithmeta(videoUrl) 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 paramsUrl = dict(self.defaultParams) paramsUrl['header'] = dict(paramsUrl['header']) paramsUrl['header']['Referer'] = videoUrl.meta.get( 'Referer', self.getMainUrl()) sts, data = self.getPage(videoUrl, paramsUrl) if not sts: return urlTab cUrl = data.meta['url'] ############################################################################################## while sts and 'generate_captcha' in data: captchaTitle = self.cm.ph.getAllItemsBeetwenMarkers( data, '<p', '</p>') if len(captchaTitle): captchaTitle = self.cleanHtmlStr(captchaTitle[-1]) # parse form data data = self.cm.ph.getDataBeetwenMarkers(data, '<form', '</form>')[1] imgUrl = self.getFullUrl( '/mirrory.php?cmd=generate_captcha&time=%s' % time.time(), cUrl) actionUrl = self.getFullUrl( self.cm.ph.getSearchGroups(data, 'action="([^"]+?)"')[0], cUrl) tmp = re.compile('''<input[^>]+?>''').findall(data) printDBG(tmp) captcha_post_data = {} for it in tmp: val = self.cm.ph.getSearchGroups( it, '''\svalue=['"]?([^'^"^\s]+?)['"\s]''')[0].strip() name = self.cm.ph.getSearchGroups( it, '''\sname=['"]([^'^"]+?)['"]''')[0] captcha_post_data[name] = val header = dict(self.HTTP_HEADER) header['Accept'] = 'image/png,image/*;q=0.8,*/*;q=0.5' params = dict(self.defaultParams) params.update({ 'maintype': 'image', 'subtypes': ['jpeg', 'png'], 'check_first_bytes': ['\xFF\xD8', '\xFF\xD9', '\x89\x50\x4E\x47'], 'header': header }) filePath = GetTmpDir('.iptvplayer_captcha.jpg') rm(filePath) ret = self.cm.saveWebFile(filePath, imgUrl.replace('&', '&'), params) if not ret.get('sts'): SetIPTVPlayerLastHostError(_('Fail to get "%s".') % imgUrl) return urlTab params = deepcopy(IPTVMultipleInputBox.DEF_PARAMS) params['accep_label'] = _('Send') params['title'] = _('Captcha') params['status_text'] = captchaTitle params['with_accept_button'] = True params['list'] = [] item = deepcopy(IPTVMultipleInputBox.DEF_INPUT_PARAMS) item['label_size'] = (160, 75) item['input_size'] = (480, 25) item['icon_path'] = filePath item['title'] = _('Answer') item['input']['text'] = '' params['list'].append(item) ret = 0 retArg = self.sessionEx.waitForFinishOpen(IPTVMultipleInputBox, params) printDBG(retArg) if retArg and len(retArg) and retArg[0]: printDBG(retArg[0]) captcha_post_data['captcha'] = retArg[0][0] paramsUrl['header']['Referer'] = cUrl sts, data = self.cm.getPage(actionUrl, paramsUrl, captcha_post_data) if sts: cUrl = data.meta['url'] else: return urlTab else: return urlTab ############################################################################################## jscode = [] tmp = self.cm.ph.getAllItemsBeetwenNodes(data, ('<script', '>'), ('</script', '>'), False) for item in tmp: if 'eval(' in item: jscode.append(item) if len(jscode) > 0: jscode.insert( 0, 'var document={write:function(e){print(e)}};Base64={},Base64.decode=function(e){e.length%4==3&&(e+="="),e.length%4==2&&(e+="=="),e=Duktape.dec("base64",e),decText="";for(var t=0;t<e.byteLength;t++)decText+=String.fromCharCode(e[t]);return decText};' ) ret = js_execute('\n'.join(jscode)) if ret['sts'] and 0 == ret['code']: data = ret['data'].strip() if 'premium' in videoUrl.meta['f_type']: printDBG(data) errorMessage = self.cleanHtmlStr( self.cm.ph.getDataBeetwenNodes(data, ('<div', '>', 'toomany'), ('</div', '>'))[1].replace( '<br>', '\n')) SetIPTVPlayerLastHostError(errorMessage) data = self.cm.ph.getDataBeetwenMarkers(data, 'clip:', '}')[1] videoUrl = self.cm.ph.getSearchGroups( data, '''\surl\s*?:\s*?['"](https?://[^'^"]+?)['"]''', 1, True)[0] if videoUrl != '': urlTab.append({ 'name': 'direct_link', 'url': strwithmeta(videoUrl, {'Referer': cUrl}) }) else: videoUrl = self.getFullUrl( self.cm.ph.getSearchGroups(data, '''href=['"]([^'^"]+?)['"]''', 1, True)[0], cUrl) if 'clipwatching' in videoUrl: videoUrl = self.getFullUrl( self.cm.ph.getSearchGroups( data, '''<iframe[^>]+?src=['"]([^"^']+?)['"]''', 1, True)[0], cUrl) urlTab = self.up.getVideoLinkExt( strwithmeta(videoUrl, {'Referer': cUrl})) return urlTab
def getLinksForVideo(self, cItem): printDBG("NaszeKinoTv.getLinksForVideo [%s]" % cItem) self.tryTologin() if 1 == self.up.checkHostSupport(cItem.get('url', '')): videoUrl = cItem['url'].replace('youtu.be/', 'youtube.com/watch?v=') return self.up.getVideoLinkExt(videoUrl) cacheKey = cItem['url'] cacheTab = self.cacheLinks.get(cacheKey, []) if len(cacheTab): return cacheTab self.cacheLinks = {} sts, data = self.getPage(cItem['url']) if not sts: return cUrl = data.meta['url'] self.setMainUrl(cUrl) paramsUrl = dict(self.defaultParams) paramsUrl['header'] = dict(paramsUrl['header']) ############################################################################################## while sts and 'captcha-info' in data: # parse form data data = self.cm.ph.getDataBeetwenMarkers(data, 'captcha-info', '</form>')[1] captchaTitle = self.cm.ph.getAllItemsBeetwenMarkers( data, '<p', '</p>') if len(captchaTitle): captchaTitle = self.cleanHtmlStr(captchaTitle[-1]) else: captchaTitle = '' sendLabel = self.cleanHtmlStr( self.cm.ph.getDataBeetwenMarkers(data, '<button', '</button>')[1]) captchaLabel = self.cleanHtmlStr( self.cm.ph.getSearchGroups( data, '''\splaceholder=['"]([^'^"]+?)['"]''')[0]) captchaLabel = '%s %s' % (sendLabel, captchaLabel) if captchaLabel.strip() == '': captchaLabel = _('Captcha') if captchaTitle == '': captchaTitle = captchaLabel sendLabel = _('Send') imgUrl = self.getFullIconUrl( self.cm.ph.getSearchGroups( data, '<img[^>]+?src="([^"]+?\.(:?jpe?g|png)(:?\?[^"]+?)?)"')[0], cUrl) actionUrl = self.getFullUrl( self.cm.ph.getSearchGroups(data, 'action="([^"]+?)"')[0], cUrl) if actionUrl == '': actionUrl = cUrl tmp = re.compile('''<input[^>]+?>''').findall(data) printDBG(tmp) captcha_post_data = {} for it in tmp: val = self.cm.ph.getSearchGroups( it, '''\svalue=['"]?([^'^"^\s]+?)['"\s]''')[0].strip() name = self.cm.ph.getSearchGroups( it, '''\sname=['"]([^'^"]+?)['"]''')[0] captcha_post_data[name] = val header = dict(self.HTTP_HEADER) header['Accept'] = 'image/png,image/*;q=0.8,*/*;q=0.5' params = dict(self.defaultParams) params.update({ 'maintype': 'image', 'subtypes': ['jpeg', 'png'], 'check_first_bytes': ['\xFF\xD8', '\xFF\xD9', '\x89\x50\x4E\x47'], 'header': header }) filePath = GetTmpDir('.iptvplayer_captcha.jpg') rm(filePath) ret = self.cm.saveWebFile(filePath, imgUrl.replace('&', '&'), params) if not ret.get('sts'): SetIPTVPlayerLastHostError(_('Fail to get "%s".') % imgUrl) return [] params = deepcopy(IPTVMultipleInputBox.DEF_PARAMS) params['accep_label'] = sendLabel params['title'] = captchaLabel params['status_text'] = captchaTitle params['status_text_hight'] = 200 params['with_accept_button'] = True params['list'] = [] item = deepcopy(IPTVMultipleInputBox.DEF_INPUT_PARAMS) item['label_size'] = (660, 110) item['input_size'] = (680, 25) item['icon_path'] = filePath item['title'] = _('Answer') item['input']['text'] = '' params['list'].append(item) params['vk_params'] = {'invert_letters_case': True} ret = 0 retArg = self.sessionEx.waitForFinishOpen(IPTVMultipleInputBox, params) printDBG(retArg) if retArg and len(retArg) and retArg[0]: printDBG(retArg[0]) captcha_post_data['captcha'] = retArg[0][0] paramsUrl['header']['Referer'] = cUrl sts, data = self.cm.getPage(actionUrl, paramsUrl, captcha_post_data) if sts: cUrl = data.meta['url'] else: return [] else: return [] ############################################################################################## msg = self.cm.ph.getDataBeetwenNodes(data, ('', '>', 'alert-info'), ('</div', '>'), False)[1] SetIPTVPlayerLastHostError(msg) retTab = [] data = self.cm.ph.getDataBeetwenNodes(data, ('<tbody', '>'), ('</tbody', '>'), False)[1] data = self.cm.ph.getAllItemsBeetwenMarkers(data, '<tr', '</tr>', False) for item in data: url = '' tmp = ph.getattr(item, 'data-iframe') try: tmp = json_loads(base64.b64decode(tmp))['src'] url = self.getFullUrl(tmp) except Exception: printExc() url = self.getFullUrl( self.cm.ph.getSearchGroups(item, '''href=['"]([^"^']+?)['"]''', 1, True)[0]) if url == '': continue item = self.cm.ph.getAllItemsBeetwenMarkers(item, '<td', '</td>') name = [] for t in item: t = self.cleanHtmlStr(t) if t != '': name.append(t) name = ' | '.join(name) retTab.append({ 'name': name, 'url': strwithmeta(url, {'Referer': cUrl}), 'need_resolve': 1 }) if len(retTab): self.cacheLinks[cacheKey] = retTab return retTab
def getPage(self, url, params={}, post_data=None): mainParamsUrl = params if mainParamsUrl == {}: mainParamsUrl = dict(self.defaultParams) while True: sts, data = self.cm.getPage(url, mainParamsUrl, post_data) if sts and data.meta.get('status_code', 0) in [410, 404]: tmp = re.sub("<!--[\s\S]*?-->", "", data) if 'sitekey' in tmp: 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) break elif 'captcha' in tmp: paramsUrl = dict(self.defaultParams) paramsUrl['header'] = dict(paramsUrl['header']) cUrl = self.cm.meta['url'] tmp = ph.find(tmp, ('<div', '>', 'footer-404'), '</form>')[1] captchaTitle = self.cleanHtmlStr(tmp.split('<form', 1)[0]) sendLabel = self.cleanHtmlStr( ph.getattr( ph.find(tmp, ('<input', '>', 'Button'), flags=(ph.IGNORECASE | ph.START_E))[1], 'value')) captchaLabel = self.cleanHtmlStr( ph.getattr(tmp, 'placeholder')) captchaLabel = '%s %s' % (sendLabel, captchaLabel) if captchaLabel.strip() == '': captchaLabel = _('Captcha') if captchaTitle == '': captchaTitle = captchaLabel else: captchaTitle = '%s\n\n%s' % (captchaTitle, captchaLabel) sendLabel = _('Send') imgUrl = self.getFullIconUrl( ph.search(tmp, ph.IMAGE_SRC_URI_RE)[1], cUrl) actionUrl = self.getFullUrl(ph.getattr(tmp, 'action'), cUrl) if actionUrl == '': actionUrl = cUrl raw_post = ph.findall(tmp, '<input', '>', flags=ph.IGNORECASE) printDBG(tmp) captcha_post_data = {} for it in raw_post: val = ph.getattr(it, 'value').strip() name = ph.getattr(it, 'name') if name == '': continue captcha_post_data[name] = val header = dict(self.HTTP_HEADER) header['Accept'] = 'image/png,image/*;q=0.8,*/*;q=0.5' params = dict(self.defaultParams) params.update({ 'maintype': 'image', 'subtypes': ['jpeg', 'png'], 'check_first_bytes': ['\xFF\xD8', '\xFF\xD9', '\x89\x50\x4E\x47'], 'header': header }) filePath = GetTmpDir('.iptvplayer_captcha.jpg') rm(filePath) ret = self.cm.saveWebFile(filePath, imgUrl.replace('&', '&'), params) if not ret.get('sts'): errorMsg = _('Fail to get "%s".') % imgUrl SetIPTVPlayerLastHostError(errorMsg) GetIPTVNotify().push(errorMsg, 'error', 10) break params = deepcopy(IPTVMultipleInputBox.DEF_PARAMS) params['accep_label'] = sendLabel params['title'] = captchaLabel params['status_text'] = captchaTitle params['status_text_hight'] = 200 params['with_accept_button'] = True params['list'] = [] item = deepcopy(IPTVMultipleInputBox.DEF_INPUT_PARAMS) item['label_size'] = (660, 110) item['input_size'] = (680, 25) item['icon_path'] = filePath item['title'] = _('Answer') item['input']['text'] = '' params['list'].append(item) params['vk_params'] = {'invert_letters_case': True} ret = 0 retArg = self.sessionEx.waitForFinishOpen( IPTVMultipleInputBox, params) printDBG(retArg) if retArg and len(retArg) and retArg[0]: printDBG(retArg[0]) captcha_post_data['captcha'] = retArg[0][0] paramsUrl['header']['Referer'] = cUrl sts, tmp = self.cm.getPage(actionUrl, paramsUrl, captcha_post_data) printDBG(tmp) else: break break return sts, data
def update_now_tar(self, cItem): restart = cItem.get('retstart', True) printDBG('TSIplayer: Start Update') #crc='' #_url = 'https://gitlab.com/Rgysoft/iptv-host-e2iplayer' #try: # crc_data = re.findall('/Rgysoft/iptv-host-e2iplayer/commit/([^"^\']+?)[\'"]',self.cm.getPage(_url)[1], re.S) # if crc_data: # crc=crc_data[0] # printDBG('TSIplayer: crc = '+crc) # else: printDBG('TSIplayer: crc not found') #except: # printDBG('TSIplayer: Get Main URL Error') # return '' crc = '' _url = 'https://gitlab.com/Rgysoft/iptv-host-e2iplayer/-/refs/master/logs_tree/?format=json&o' try: crc_data = re.findall('commit.*?id":"(.*?)"', self.cm.getPage(_url)[1], re.S) if crc_data: crc = crc_data[0] printDBG('TSIplayer: crc = ' + crc) else: printDBG('TSIplayer: crc not found') except: printDBG('TSIplayer: Get Main URL Error') return '' tmpDir = GetTmpDir() source = os_path.join(tmpDir, 'iptv-host-e2iplayer.tar.gz') dest = os_path.join(tmpDir, '') _url = 'https://gitlab.com/Rgysoft/iptv-host-e2iplayer/repository/archive.tar.gz?ref=master' try: output = open(source, 'wb') output.write(self.getPage(_url)[1]) output.close() os_system('sync') printDBG('TSIplayer: Download iptv-host-e2iplayer.tar.gz OK') except: if os_path.exists(source): os_remove(source) printDBG('TSIplayer: Download Error iptv-host-e2iplayer.tar.gz') return '' cmd = 'tar -xzf "%s" -C "%s" 2>&1' % (source, dest) try: os_system(cmd) os_system('sync') printDBG('TSIplayer: Unpacking OK') except: printDBG('TSIplayer: Unpacking Error') os_system('rm -f %s' % source) os_system('rm -rf %siptv-host-e2iplayer-%s' % (dest, crc)) return '' try: od = '%siptv-host-e2iplayer-master-%s/' % (dest, crc) do = resolveFilename(SCOPE_PLUGINS, 'Extensions/') cmd = 'cp -rf "%s"/* "%s"/ 2>&1' % (os_path.join( od, 'IPTVPlayer'), os_path.join(do, 'IPTVPlayer')) printDBG('<<<<<<<<<<<<<<<<<<<<<<<<<<cmd=' + cmd) os_system(cmd) os_system('sync') printDBG('TSIplayer: Copy OK') except: printDBG('TSIplayer: Copy Error') os_system('rm -f %s' % source) os_system('rm -rf %siptv-host-e2iplayer-master-%s' % (dest, crc)) return '' printDBG('TSIplayer: Deleting temporary files') os_system('rm -f %s' % source) os_system('rm -rf %siptv-host-e2iplayer-master-%s' % (dest, crc)) if restart: try: from enigma import quitMainloop quitMainloop(3) except Exception as e: printDBG('TSIplayer: Erreur=' + str(e)) pass params = { 'category': 'none', 'title': 'Update End. Please manual restart enigma2', 'name': 'update' } self.addDir(params) return ''
def listGetFreeCredits(self): printDBG("StreamLiveTo.listGetFreeCredits") baseUrl = self._getFullUrl('get_free_credits') httpParams = dict(self.defaultParams) httpParams['header'] = dict(self.HTTP_HEADER) httpParams['header']['Referer'] = baseUrl sts, data = self.getPage(baseUrl, httpParams) if not sts: SetIPTVPlayerLastHostError(_('Fail to get "%s".') % baseUrl) return 0 sts, data = self.cm.ph.getDataBeetwenMarkers(data, '<form method="post">', '</form>') m1 = 'recaptcha_challenge_field' m2 = 'recaptcha_response_field' errMsg1 = _('Fail to get captcha data.') if sts: captchaUrl = self.cm.ph.getSearchGroups( data, '''['"](http[^"']+?recaptcha/api[^"']*?)["']''')[0] if not sts or '' == captchaUrl or m1 not in data or m2 not in data: SetIPTVPlayerLastHostError(errMsg1) return 0 sts, data = self.getPage(captchaUrl, httpParams) if not sts: SetIPTVPlayerLastHostError(_('Fail to get "%s".') % captchaUrl) return 0 challenge = self.cm.ph.getSearchGroups( data, '''challenge\s*:\s*['"]([^'^"]+?)['"]''')[0] lang = self.cm.ph.getSearchGroups( data, '''lang\s*:\s*['"]([^'^"]+?)['"]''')[0] server = self.cm.ph.getSearchGroups( data, '''server\s*:\s*['"]([^'^"]+?)['"]''')[0] site = self.cm.ph.getSearchGroups( data, '''site\s*:\s*['"]([^'^"]+?)['"]''')[0] if '' == challenge or '' == lang or '' == server or '' == site: SetIPTVPlayerLastHostError(errMsg1) return 0 captchaUrl = server + 'reload?c=%s&k=%s&reason=i&type=image&lang=%s&th=' % ( challenge, site, lang) sts, data = self.getPage(captchaUrl, httpParams) if not sts: SetIPTVPlayerLastHostError(_('Fail to get "%s".') % captchaUrl) return 0 sts, challenge = self.cm.ph.getDataBeetwenMarkers( data, "finish_reload('", "'", False) if not sts: SetIPTVPlayerLastHostError(errMsg1) return 0 imgUrl = 'http://www.google.com/recaptcha/api/image?c=' + challenge #return params = { 'maintype': 'image', 'subtypes': ['jpeg'], 'check_first_bytes': ['\xFF\xD8', '\xFF\xD9'] } filePath = GetTmpDir('.iptvplayer_captcha.jpg') ret = self.cm.saveWebFile(filePath, imgUrl, params) if not ret.get('sts'): SetIPTVPlayerLastHostError(_('Fail to get "%s".') % imgUrl) return 0 from copy import deepcopy params = deepcopy(IPTVMultipleInputBox.DEF_PARAMS) params['accep_label'] = _('Send') params['title'] = _('Answer') params['list'] = [] item = deepcopy(IPTVMultipleInputBox.DEF_INPUT_PARAMS) item['label_size'] = (300, 57) item['input_size'] = (300, 25) item['icon_path'] = filePath item['input']['text'] = '' params['list'].append(item) ret = 0 retArg = self.sessionEx.waitForFinishOpen(IPTVMultipleInputBox, params) printDBG(retArg) if retArg and len(retArg) and retArg[0]: printDBG(retArg[0]) sts, data = self.cm.getPage( baseUrl, httpParams, { 'recaptcha_challenge_field': challenge, 'recaptcha_response_field': retArg[0], 'submit': 'Get Free 10 Credits' }) printDBG(data) if 'got free' in data: ret = 1 elif 'incorrect' in data: ret = -1 if sts: msg = self.cm.ph.getDataBeetwenMarkers(data, '<div style="color:', '</div>')[1] SetIPTVPlayerLastHostError(self.cleanHtmlStr(msg)) else: SetIPTVPlayerLastHostError(_('Fail to get "%s".') % baseUrl) else: SetIPTVPlayerLastHostError(_('Wrong answer.')) return ret
def __init__(self, finished, chooseQuestion, showMessage, setInfo): printDBG("IPTVSetupImpl.__init__ -------------------------------") # callbacks self._finished = finished self._chooseQuestion = chooseQuestion self._showMessage = showMessage self._setInfo = setInfo self.workingObj = None self.stepHelper = None self.termination = False self.tmpDir = GetTmpDir() self.resourceServers = [ "http://iptvplayer.pl/resources/", "http://iptvplayer.vline.pl/resources/" ] self.ffmpegVersion = "" self.gstreamerVersion = "" self.openSSLVersion = "" self.libSSLPath = "" self.supportedPlatforms = ["sh4", "mipsel", "i686", "armv7", "armv5t"] self.platform = "unknown" # wget members self.wgetVersion = 15 # 1.15 self.wgetpaths = [ "wget", "/usr/bin/wget", "/usr/bin/fullwget", GetBinDir("wget", "") ] self._wgetInstallChoiseList = [ (_('Install into the "%s".') % ("/usr/bin/fullwget " + _("recommended")), "/usr/bin/fullwget"), (_('Install into the "%s".') % "IPTVPlayer/bin/wget", GetBinDir("wget", "")), (_('Install into the "%s".') % "/usr/bin/wget", "/usr/bin/wget"), (_("Do not install (not recommended)"), "") ] # rtmpdump members self.rtmpdumpVersion = { 'sh4': '2015', 'mipsel': '2015', 'armv5t': '2015', 'armv7': '2015', 'default': "Compiled by [email protected] 2015-01-11" } #'K-S-V patch' self.rtmpdumppaths = ["/usr/bin/rtmpdump", "rtmpdump"] # f4mdump member self.f4mdumpVersion = 0.80 self.f4mdumppaths = ["/usr/bin/f4mdump", GetBinDir("f4mdump", "")] self._f4mdumpInstallChoiseList = [ (_('Install into the "%s".') % ("/usr/bin/f4mdump (%s)" % _("recommended")), "/usr/bin/f4mdump"), (_('Install into the "%s".') % "IPTVPlayer/bin/f4mdump", GetBinDir("f4mdump", "")), (_("Do not install (not recommended)"), "") ] self._f4mdumpInstallChoiseList2 = [ (_('Install into the "%s".') % ("/usr/bin/f4mdump static libstdc++ (%s)" % _("recommended")), "/usr/bin/f4mdump"), (_('Install into the "%s".') % "IPTVPlayer/bin/f4mdump _static_libstdc++", GetBinDir("f4mdump", "")), (_("Do not install (not recommended)"), "") ] # uchardet member self.uchardetVersion = [ 0, 0, 6 ] #UCHARDET_VERSION_MAJOR, UCHARDET_VERSION_MINOR, UCHARDET_VERSION_REVISION self.uchardetpaths = ["/usr/bin/uchardet", GetBinDir("uchardet", "")] self._uchardetInstallChoiseList = [ (_('Install into the "%s".') % ("/usr/bin/uchardet (%s)" % _("recommended")), "/usr/bin/uchardet"), (_('Install into the "%s".') % "IPTVPlayer/bin/uchardet", GetBinDir("uchardet", "")), (_("Do not install (not recommended)"), "") ] self._uchardetInstallChoiseList2 = [ (_('Install into the "%s".') % ("/usr/bin/uchardet static libstdc++ (%s)" % _("recommended")), "/usr/bin/uchardet"), (_('Install into the "%s".') % "IPTVPlayer/bin/uchardet _static_libstdc++", GetBinDir("uchardet", "")), (_("Do not install (not recommended)"), "") ] # gstplayer self.gstplayerVersion = {'0.10': 20, '1.0': 10021} self.gstplayerpaths = [ "/usr/bin/gstplayer", GetBinDir("gstplayer", "") ] self._gstplayerInstallChoiseList = [ (_('Install into the "%s".') % ("/usr/bin/gstplayer (%s)" % _("recommended")), "/usr/bin/gstplayer"), (_('Install into the "%s".') % "IPTVPlayer/bin/gstplayer", GetBinDir("gstplayer", "")), (_("Do not install (not recommended)"), "") ] # exteplayer3 self.exteplayer3Version = { 'sh4': 33, 'mipsel': 33, 'armv7': 33, 'armv5t': 33 } self.exteplayer3paths = [ "/usr/bin/exteplayer3", GetBinDir("exteplayer3", "") ] self._exteplayer3InstallChoiseList = [ (_('Install into the "%s".') % ("/usr/bin/exteplayer3 (%s)" % _("recommended")), "/usr/bin/exteplayer3"), (_('Install into the "%s".') % "IPTVPlayer/bin/exteplayer3", GetBinDir("exteplayer3", "")), (_("Do not install (not recommended)"), "") ] # flumpegdemux self.flumpegdemuxVersion = "0.10.85" self.flumpegdemuxpaths = [ "/usr/lib/gstreamer-0.10/libgstflumpegdemux.so" ] # gstifdsrc self.gstifdsrcVersion = "1.1.1" self.gstifdsrcPaths = ["/usr/lib/gstreamer-1.0/libgstifdsrc.so"] # subparser self.subparserVersion = 0.4 self.subparserPaths = [ resolveFilename( SCOPE_PLUGINS, 'Extensions/IPTVPlayer/libs/iptvsubparser/_subparser.so') ] self.binaryInstalledSuccessfully = False self.tries = 0
def getVideoLinks(self, videoUrl): printDBG("MoovieCC.getVideoLinks [%s]" % videoUrl) videoUrl = strwithmeta(videoUrl) 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 orginUrl = str(videoUrl) url = videoUrl post_data = None while True: sts, data = self.getPage(url, post_data=post_data) if not sts: return [] videoUrl = self.cm.meta['url'] if self.up.getDomain( self.getMainUrl()) in videoUrl or self.up.getDomain( videoUrl) == self.up.getDomain(orginUrl): if 'captcha' in data: data = re.sub("<!--[\s\S]*?-->", "", data) if 'google.com/recaptcha/' in data and 'sitekey' in data: message = _('Link protected with google recaptcha v2.') SetIPTVPlayerLastHostError(message) break elif '<input name="captcha"' in data: tmp = self.cm.ph.getDataBeetwenMarkers( data, '<content', '</form>')[1] captchaTitle = self.cleanHtmlStr( self.cm.ph.getDataBeetwenMarkers(tmp, '<h1', '</h1>')[1]) captchaDesc = self.cleanHtmlStr( self.cm.ph.getDataBeetwenMarkers(tmp, '<p', '</p>')[1]) # parse form data data = self.cm.ph.getDataBeetwenMarkers( data, '<form', '</form>')[1] imgUrl = self.cm.ph.getSearchGroups( data, 'src="([^"]+?)"')[0] if imgUrl != '' and not imgUrl.startswith('/'): imgUrl = '/' + imgUrl if imgUrl.startswith('/'): imgUrl = urlparse.urljoin(videoUrl, imgUrl) printDBG("img URL [%s]" % imgUrl) actionUrl = self.cm.ph.getSearchGroups( data, 'action="([^"]+?)"')[0] if actionUrl != '': actionUrl = '/' + actionUrl if actionUrl.startswith('/'): actionUrl = urlparse.urljoin(videoUrl, actionUrl) elif actionUrl == '': actionUrl = videoUrl captcha_post_data = dict( re.findall( r'''<input[^>]+?name=["']([^"^']*)["'][^>]+?value=["']([^"^']*)["'][^>]*>''', data)) if self.cm.isValidUrl(imgUrl): params = dict(self.defaultParams) params['header'] = dict(params['header']) params['header'][ 'Accept'] = 'image/png,image/*;q=0.8,*/*;q=0.5' params = dict(self.defaultParams) params.update({ 'maintype': 'image', 'subtypes': ['jpeg', 'png'], 'check_first_bytes': ['\xFF\xD8', '\xFF\xD9', '\x89\x50\x4E\x47'], 'header': params['header'] }) filePath = GetTmpDir('.iptvplayer_captcha.jpg') ret = self.cm.saveWebFile(filePath, imgUrl.replace('&', '&'), params) if not ret.get('sts'): SetIPTVPlayerLastHostError( _('Fail to get "%s".') % imgUrl) return urlTab params = deepcopy(IPTVMultipleInputBox.DEF_PARAMS) params['accep_label'] = _('Send') params['title'] = captchaTitle params['status_text'] = captchaDesc params['with_accept_button'] = True params['list'] = [] item = deepcopy(IPTVMultipleInputBox.DEF_INPUT_PARAMS) item['label_size'] = (160, 75) item['input_size'] = (480, 25) item['icon_path'] = filePath item['title'] = _('Answer') item['input']['text'] = '' params['list'].append(item) ret = 0 retArg = self.sessionEx.waitForFinishOpen( IPTVMultipleInputBox, params) printDBG(retArg) if retArg and len(retArg) and retArg[0]: printDBG(retArg[0]) captcha_post_data['captcha'] = retArg[0][0] post_data = captcha_post_data url = actionUrl if not sts: return urlTab else: continue found = False printDBG(data) tmp = re.compile('''<iframe[^>]+?src=['"]([^"^']+?)['"]''', re.IGNORECASE).findall(data) for url in tmp: if 1 == self.up.checkHostSupport(url): videoUrl = url found = True break if not found or 'flashx' in videoUrl: tmp = self.cm.ph.getAllItemsBeetwenMarkers( data, 'embedFrame', '</a>') tmp.extend( self.cm.ph.getAllItemsBeetwenMarkers( data, '<a', '</a>')) for urlItem in tmp: url = self.cm.ph.getSearchGroups( urlItem, '''href=['"](https?://[^'^"]+?)['"]''')[0] if 1 == self.up.checkHostSupport(url): videoUrl = url found = True break break if self.cm.isValidUrl(videoUrl): urlTab = self.up.getVideoLinkExt(videoUrl) return urlTab
def downloadSubtitleFile(self, cItem): printDBG("Napisy24plProvider.downloadSubtitleFile") retData = {} title = cItem['title'] lang = cItem['lang'] subId = cItem['sub_id'] imdbid = cItem['imdbid'] fileName = self._getFileName(title, lang, subId, imdbid) fileName = GetSubtitlesDir(fileName) url = 'http://napisy24.pl/download?napisId={0}&typ=sru'.format(subId) tmpFile = GetTmpDir(self.TMP_FILE_NAME) tmpFileZip = tmpFile + '.zip' urlParams = dict(self.defaultParams) urlParams['max_data_size'] = self.getMaxFileSize() sts, data = self.getPage(url, urlParams) if not sts: SetIPTVPlayerLastHostError(_('Failed to download subtitle.')) return retData try: with open(tmpFileZip, 'w') as f: f.write(data) except Exception: printExc() SetIPTVPlayerLastHostError( _('Failed to write file "%s".') % tmpFileZip) return retData printDBG(">>") printDBG(tmpFile) printDBG(tmpFileZip) printDBG(fileName) printDBG("<<") def __cleanFiles(all=False): if all: rm(fileName) rm(tmpFile) rm(tmpFileZip) cmd = "unzip -po '{0}' -x Napisy24.pl.url > '{1}' 2>/dev/null".format( tmpFileZip, tmpFile) ret = self.iptv_execute(cmd) if not ret['sts'] or 0 != ret['code']: __cleanFiles() message = _('Unzip error code[%s].') % ret['code'] if str(ret['code']) == str(127): message += '\n' + _( 'It seems that unzip utility is not installed.') elif str(ret['code']) == str(9): message += '\n' + _('Wrong format of zip archive.') SetIPTVPlayerLastHostError(message) return retData # detect encoding cmd = '%s "%s"' % (config.plugins.iptvplayer.uchardetpath.value, tmpFile) ret = self.iptv_execute(cmd) if ret['sts'] and 0 == ret['code']: encoding = MapUcharEncoding(ret['data']) if 0 != ret['code'] or 'unknown' in encoding: encoding = '' else: encoding = encoding.strip() else: encoding = '' if GetDefaultLang() == 'pl' and encoding == 'iso-8859-2': encoding = GetPolishSubEncoding(tmpFile) elif '' == encoding: encoding = 'utf-8' # convert file to UTF-8 try: with open(tmpFile) as f: data = f.read() try: data = data.decode(encoding).encode('UTF-8') try: with open(fileName, 'w') as f: f.write(data) retData = { 'title': title, 'path': fileName, 'lang': lang, 'imdbid': imdbid, 'sub_id': subId } except Exception: printExc() SetIPTVPlayerLastHostError( _('Failed to write the file "%s".') % fileName) except Exception: printExc() SetIPTVPlayerLastHostError( _('Failed to convert the file "%s" to UTF-8.') % tmpFile) except Exception: printExc() SetIPTVPlayerLastHostError( _('Failed to open the file "%s".') % tmpFile) __cleanFiles() return retData
def getSweetCaptchaRespond(self, data): printDBG("FiliserTv.getSweetCaptchaRespond") def _getFullUrl(url): urlPrefix = 'http:' if url.startswith('//'): url = urlPrefix + url return url def n(e, n): a = "" n = urllib.unquote(n) for r in range(len(n)-1, -1, -1): t = n[r] if (t >= "a" and "z" >= t) or (t >= "A" and "Z" >= t): a += chr(65 + e.find(t) % 26) else: a += t return a.lower() retData = {} printDBG(data) url = _getFullUrl(self.cm.ph.getSearchGroups(data, '''['"]([^'^"]*?/captcha/[^'^"]*?)['"]''')[0]) url += 'mobile=1&_=' + str(int(time() * 1000)) sts, data = self.getPage(url) if not sts: return retData printDBG(data) thumbFileTab = [] try: data = json_loads(data) imgUrlTab = [] for item in data["a"]: imgUrlTab.append(_getFullUrl(n(data['simple_key'], item['src']))) imgUrlTab.append(_getFullUrl(n(data['simple_key'], data['q']))) printDBG(imgUrlTab) errorOccurred = False params = {'maintype': 'image', 'subtypes':['png'], 'check_first_bytes':['\x89\x50\x4E\x47']} for idx in range(len(imgUrlTab)): imgUrl = imgUrlTab[idx] filePath = GetTmpDir('.iptvplayer_captcha_%s.png' % idx) ret = self.cm.saveWebFile(filePath, imgUrl, params) if not ret.get('sts'): SetIPTVPlayerLastHostError(_('Fail to get "%s".') % imgUrl) errorOccurred = True break thumbFileTab.append(filePath) if not errorOccurred: verify = data['drag']['verify'] challenge = data['drag']['challenge'] printDBG(thumbFileTab) printDBG("OK") printDBG(verify) printDBG(challenge) retArg = self.sessionEx.waitForFinishOpen(UnCaptchaSweetCaptchaWidget, params={'icon_list':thumbFileTab, 'title':verify, 'challenge':challenge}) printDBG('>>>>>>>> Captcha response %r' % (retArg)) if retArg is not None and len(retArg) and retArg[0]: answer = retArg[0]['resp_idx'] printDBG('>>>>>>>> Captcha answer[%s]' % (answer)) retData = {'sckey':data['k'], 'scvalue':data['a'][answer]['hash'][5:15], 'scvalue2':0} else: retData = None except Exception: printExc() for file in thumbFileTab: rm(file) return retData
def tryTologin(self): printDBG('tryTologin start') if None == self.loggedIn or self.login != config.plugins.iptvplayer.serienstreamto_login.value or\ self.password != config.plugins.iptvplayer.serienstreamto_password.value: loginCookie = GetCookieDir('s.to.login') self.login = config.plugins.iptvplayer.serienstreamto_login.value self.password = config.plugins.iptvplayer.serienstreamto_password.value sts, data = self.cm.getPage(self.getMainUrl(), self.defaultParams) if sts: self.setMainUrl(self.cm.meta['url']) freshSession = False if sts and '/home/logout' in data: printDBG("Check hash") hash = hexlify( md5('%s@***@%s' % (self.login, self.password)).digest()) prevHash = ReadTextFile(loginCookie)[1].strip() printDBG("$hash[%s] $prevHash[%s]" % (hash, prevHash)) if hash == prevHash: self.loggedIn = True return else: freshSession = True rm(loginCookie) rm(self.COOKIE_FILE) if freshSession: sts, data = self.cm.getPage( self.getMainUrl(), MergeDicts(self.defaultParams, {'use_new_session': True})) self.loggedIn = False if '' == self.login.strip() or '' == self.password.strip(): return False actionUrl = self.getFullUrl('/login') post_data = { 'email': self.login, 'password': self.password, 'autoLogin': '******' } tries = 0 while tries < 3: tries += 1 errorMsg = '' httpParams = dict(self.defaultParams) httpParams['header'] = dict(httpParams['header']) httpParams['header']['Referer'] = actionUrl sts, data = self.getPage(actionUrl, httpParams, post_data) printDBG( "+++++++++++++++++++++++++++++++++++++++++++++++++++++++") printDBG(data) printDBG( "+++++++++++++++++++++++++++++++++++++++++++++++++++++++") if sts and not data.strip(): sts, data = self.getPage(actionUrl) if sts and '/home/logout' in data: printDBG('tryTologin OK') self.loggedIn = True break elif sts: errorMsg = ph.clean_html( ph.find(data, ('<div', '>', 'messageAlert'), '</div>', flags=0)[1]) tmp1 = ph.find(data, ('<div', '>', 'formCaptcha'), '</div>', flags=0)[1] imgUrl = self.getFullUrl( ph.search(tmp1, ph.IMAGE_SRC_URI_RE)[1], self.cm.meta['url']) tmp2 = ph.find(data, ('<input', '>', 'captcha'), flags=0)[1] if imgUrl: captchaLabel = _('Captcha') captchaTitle = errorMsg sendLabel = _('Send') header = dict(httpParams['header']) header['Accept'] = 'image/png,image/*;q=0.8,*/*;q=0.5' params = dict(self.defaultParams) params.update({ 'maintype': 'image', 'subtypes': ['jpeg', 'png'], 'check_first_bytes': ['\xFF\xD8', '\xFF\xD9', '\x89\x50\x4E\x47'], 'header': header }) filePath = GetTmpDir('.iptvplayer_captcha.jpg') rm(filePath) ret = self.cm.saveWebFile(filePath, imgUrl.replace('&', '&'), params) if not ret.get('sts'): SetIPTVPlayerLastHostError( _('Fail to get "%s".') % imgUrl) return params = deepcopy(IPTVMultipleInputBox.DEF_PARAMS) params['accep_label'] = sendLabel params['title'] = captchaLabel params['status_text'] = captchaTitle params['status_text_hight'] = 200 params['with_accept_button'] = True params['list'] = [] item = deepcopy(IPTVMultipleInputBox.DEF_INPUT_PARAMS) item['label_size'] = (660, 110) item['input_size'] = (680, 25) item['icon_path'] = filePath item['title'] = _('Answer') item['input']['text'] = '' params['list'].append(item) #params['vk_params'] = {'invert_letters_case':True} ret = 0 retArg = self.sessionEx.waitForFinishOpen( IPTVMultipleInputBox, params) printDBG(retArg) if retArg and len(retArg) and retArg[0]: printDBG(retArg[0]) post_data['captcha'] = retArg[0][0] continue else: break if self.loggedIn: hash = hexlify( md5('%s@***@%s' % (self.login, self.password)).digest()) WriteTextFile(loginCookie, hash) else: self.sessionEx.open(MessageBox, _('Login failed.') + '\n' + errorMsg, type=MessageBox.TYPE_ERROR, timeout=10) return self.loggedIn
def getVideoLinks(self, videoUrl): global x videoUrl = strwithmeta(videoUrl) 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 url = videoUrl printDBG(url) post_data = None while True: httpParams = dict(self.defaultParams) httpParams['max_data_size'] = 0 self.cm.getPage(url, httpParams, post_data) if 'url' in self.cm.meta: videoUrl = self.cm.meta['url'] else: return [] if self.up.getDomain(self.getMainUrl()) in videoUrl: sts, data = self.getPage(videoUrl) if not sts: return [] if 'captcha' in data: data = re.sub("<!--[\s\S]*?-->", "", data) if 'google.com/recaptcha/' in data and 'sitekey' in data: message = _('Link protected with google recaptcha v2.') if True != self.loggedIn: message += '\n' + _('Please fill your login and password in the host configuration (available under blue button) and try again.') SetIPTVPlayerLastHostError(message) break elif '<input name="captcha"' in data: data = self.cm.ph.getDataBeetwenMarkers(data, '<div align="center">', '</form>')[1] captchaTitle = self.cleanHtmlStr(self.cm.ph.getDataBeetwenMarkers(data, '<h3', '</h3>')[1]) captchaDesc = self.cleanHtmlStr(self.cm.ph.getDataBeetwenMarkers(data, '</h3>', '</span>')[1]) # parse form data data = self.cm.ph.getDataBeetwenMarkers(data, '<form', '</form>')[1] imgUrl = self.cm.ph.getSearchGroups(data, 'src="([^"]+?)"')[0] if imgUrl != '': imgUrl = '/' + imgUrl if imgUrl.startswith('/'): imgUrl = urlparse.urljoin(videoUrl, imgUrl) printDBG("img URL [%s]" % imgUrl) actionUrl = self.cm.ph.getSearchGroups(data, 'action="([^"]+?)"')[0] if actionUrl != '': actionUrl = '/' + actionUrl if actionUrl.startswith('/'): actionUrl = urlparse.urljoin(videoUrl, actionUrl) elif actionUrl == '': actionUrl = videoUrl captcha_post_data = dict(re.findall(r'''<input[^>]+?name=["']([^"^']*)["'][^>]+?value=["']([^"^']*)["'][^>]*>''', data)) if self.cm.isValidUrl(imgUrl): params = dict(self.defaultParams) params['header'] = dict(params['header'] ) params['header']['Accept'] = 'image/png,image/*;q=0.8,*/*;q=0.5' params = dict(self.defaultParams) params.update( {'maintype': 'image', 'subtypes':['jpeg', 'png'], 'check_first_bytes':['\xFF\xD8','\xFF\xD9','\x89\x50\x4E\x47'], 'header':params['header']} ) filePath = GetTmpDir('.iptvplayer_captcha.jpg') ret = self.cm.saveWebFile(filePath, imgUrl.replace('&', '&'), params) if not ret.get('sts'): SetIPTVPlayerLastHostError(_('Fail to get "%s".') % imgUrl) return urlTab params = deepcopy(IPTVMultipleInputBox.DEF_PARAMS) params['accep_label'] = _('Send') params['title'] = captchaTitle params['status_text'] = captchaDesc params['with_accept_button'] = True params['list'] = [] item = deepcopy(IPTVMultipleInputBox.DEF_INPUT_PARAMS) item['label_size'] = (160,75) item['input_size'] = (480,25) item['icon_path'] = filePath item['title'] = _('Answer') item['input']['text'] = '' params['list'].append(item) ret = 0 retArg = self.sessionEx.waitForFinishOpen(IPTVMultipleInputBox, params) printDBG(retArg) if retArg and len(retArg) and retArg[0]: printDBG(retArg[0]) captcha_post_data['captcha'] = retArg[0][0] post_data = captcha_post_data url = actionUrl if not sts: return urlTab else: continue tmp = ph.IFRAME.findall(data) for urlItem in tmp: url = self.cm.getFullUrl(urlItem[1]) if 1 == self.up.checkHostSupport(url): videoUrl = url break break if not self.up.checkHostSupport(videoUrl): sts, data = self.getPage(videoUrl) if not sts: return [] tmp = ph.IFRAME.findall(data) tmp.extend(ph.A.findall(data)) for item in tmp: url = self.cm.getFullUrl(item[1]) if 1 == self.up.checkHostSupport(url): videoUrl = url break if self.up.checkHostSupport(videoUrl): return self.up.getVideoLinkExt(videoUrl) return urlTab
def downloadSubtitleFile(self, cItem): printDBG("NapiProjektProvider.downloadSubtitleFile") retData = {} title = cItem['title'] lang = cItem.get('lang', 'pl') subId = cItem['sub_id'] imdbid = cItem['imdbid'] fps = cItem.get('fps', 0) post_data = { "mode": "32770", "client": "pynapi", "client_ver": "0.1", "VideoFileInfoID": subId } url = self.getFullUrl('api/api-napiprojekt3.php') sts, data = self.cm.getPage(url, self.defaultParams, post_data) if not sts: return retData fps = self.cm.ph.getDataBeetwenMarkers(data, '<fps>', '</fps>', False)[1] try: fps = float(fps.strip()) except Exception: fps = 0 post_data = { "downloaded_subtitles_id": subId, "mode": "1", "client": "pynapi", "client_ver": "0.1", "downloaded_subtitles_lang": lang.upper(), "downloaded_subtitles_txt": "1" } url = self.getFullUrl('api/api-napiprojekt3.php') sts, data = self.cm.getPage(url, self.defaultParams, post_data) if not sts: return retData data = self.cm.ph.getDataBeetwenMarkers(data, '<content><![CDATA[', ']]></content>', False)[1] try: data = base64.b64decode(data) if IsSubtitlesParserExtensionCanBeUsed(): from Plugins.Extensions.IPTVPlayer.libs.iptvsubparser import _subparser as subparser subsObj = subparser.parse(data, 0, False, False) typeExtMap = { 'microdvd': 'sub', 'subrip': 'srt', 'subviewer': 'sub', 'ssa1': 'ssa', 'ssa2-4': 'ssa', 'ass': 'ssa', 'vplayer': 'txt', 'sami': 'smi', 'mpl2': 'mpl', 'aqt': 'aqt', 'pjs': 'pjs', 'mpsub': 'sub', 'jacosub': 'jss', 'psb': 'psb', 'realtext': 'rt', 'dks': 'dks', 'subviewer1': 'sub', 'text/vtt': 'vtt', 'sbv': 'sbv' } ext = typeExtMap.get(subsObj['type'], '') if ext == '': SetIPTVPlayerLastHostError( _('Unknown subtitle parser for format "%s".') % subsObj['type']) return retData tmpFile = GetTmpDir(self.TMP_FILE_NAME) if not self.writeFile(tmpFile, data): return retData fileName = self._getFileName(title, lang, subId, imdbid, fps, ext) fileName = GetSubtitlesDir(fileName) if not self.converFileToUtf8(tmpFile, fileName): rm(tmpFile) return retData retData = { 'title': title, 'path': fileName, 'lang': lang, 'imdbid': imdbid, 'sub_id': subId } except Exception: printExc() return retData return retData
def getVideoLinks(self, videoUrl): printDBG("KinomanCO.getVideoLinks [%s]" % videoUrl) self.tryTologin() videoUrl = strwithmeta(videoUrl) 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 url = self.getFullUrl('/api/link/embed?width=500&height=500', 'api') post_data = '{"code":"%s","secure": 1}' % (videoUrl) videoUrl = '' try: while True: httpParams = dict(self.defaultParams) httpParams.update({'raw_post_data':True, 'ignore_http_code_ranges':[(401,401), (500,500)]}) httpParams['header'] = dict(httpParams['header']) httpParams['header']['Content-Type'] = 'application/json; charset=UTF-8' sts, data = self.getPage(url, httpParams, post_data) printDBG(data) if sts: data = byteify(json.loads(data), '', True) if not isinstance(data, str): videoUrl = data['link'] elif 'captcha' in data.lower(): sts, data = self.getPage(self.getFullUrl('/api/captcha', 'api')) if not sts: SetIPTVPlayerLastHostError(_('Network connection failed.')) break data = byteify(json.loads(data), '', True) captchaTitle = self._('Fill captcha') imgUrl = data['image'] KinomanCO.CAPTCHA_HASHKEY = data['key'] self.defaultParams['header']['x-captcha-hashkey'] = KinomanCO.CAPTCHA_HASHKEY if self.cm.isValidUrl(imgUrl): header = dict(self.HEADER) header['Accept'] = 'image/png,image/*;q=0.8,*/*;q=0.5' params = dict(self.defaultParams) params.update( {'maintype': 'image', 'subtypes':['jpeg', 'png'], 'check_first_bytes':['\xFF\xD8','\xFF\xD9','\x89\x50\x4E\x47'], 'header':header} ) filePath = GetTmpDir('.iptvplayer_captcha.jpg') rm(filePath) ret = self.cm.saveWebFile(filePath, imgUrl, params) if not ret.get('sts'): SetIPTVPlayerLastHostError(_('Fail to get "%s".') % imgUrl) return [] params = deepcopy(IPTVMultipleInputBox.DEF_PARAMS) params['accep_label'] = _('Send') params['title'] = _('Captcha') params['status_text'] = captchaTitle params['with_accept_button'] = True params['list'] = [] item = deepcopy(IPTVMultipleInputBox.DEF_INPUT_PARAMS) item['label_size'] = (160,75) item['input_size'] = (480,25) item['icon_path'] = filePath item['title'] = _('Answer') item['input']['text'] = '' params['list'].append(item) params['vk_params'] = {'invert_letters_case':True} ret = 0 retArg = self.sessionEx.waitForFinishOpen(IPTVMultipleInputBox, params) printDBG(retArg) if retArg and len(retArg) and retArg[0]: printDBG(retArg[0]) KinomanCO.CAPTCHA_CHALLENGE = retArg[0][0] self.defaultParams['header']['x-captcha-challenge'] = KinomanCO.CAPTCHA_CHALLENGE continue break elif 'x-user-token' not in httpParams['header'] and '_user_token' in data: msg = _('The host %s requires registration. \nPlease fill your login and password in the host configuration. Available under blue button.' % self.getMainUrl()) SetIPTVPlayerLastHostError(msg) else: SetIPTVPlayerLastHostError(_('Unknown server response: "%s"') % data) else: SetIPTVPlayerLastHostError(_('Network connection failed.')) break except Exception: SetIPTVPlayerLastHostError(_('Unknown server response.')) printExc() directLink = False if self.cm.isValidUrl(videoUrl): if 0 == self.up.checkHostSupport(videoUrl): params = dict(self.defaultParams) params.update({'return_data':False}) try: sts, response = self.cm.getPage(videoUrl, params) videoUrl = response.geturl() type = response.info().type.lower() printDBG("type [%s]" % type) if 'video' in type: directLink = True response.close() except Exception: printExc() if directLink: urlTab.append({'name':'direct_link', 'url':strwithmeta(videoUrl, {})}) else: urlTab = self.up.getVideoLinkExt(videoUrl) return urlTab