def GetHeadercookie(self, url): Domain = re.sub(r'https*:\/\/([^/]+)(\/*.*)', '\\1', url) cook = GestionCookie().Readcookie(Domain.replace('.', '_')) if cook == '': return '' return '|' + urlEncode({'User-Agent': UA, 'Cookie': cook})
def __getMediaLinkForGuest(self): vUrl = False sId = self.__getIdFromUrl(self.__sUrl) query_args = {'r': '["tVL0gjqo5",["preview/flv_image",{"uid":"' + sId + '"}],["preview/flv_link",{"uid":"' + sId + '"}]]'} data = urlEncode(query_args) headers = {'User-Agent': 'Mozilla 5.10'} url = 'http://api.letitbit.net' request = urllib2.Request(url, data, headers) try: reponse = urllib2.urlopen(request) except UrlError as e: print(e.read()) print(e.reason) html = reponse.read() sHtmlContent = html.replace('\\', '') link = re.findall('"link":"(.+?)"', sHtmlContent) if link: vUrl = link[0] # print(vUrl) if (vUrl): api_call = vUrl return True, api_call return False, False
def __getMediaLinkForGuest(self): import random api_call = False url = 'https://1fichier.com/?' + self.__getIdFromUrl(self.__sUrl) headers = { 'User-Agent': UA, 'Host': '1fichier.com', 'Referer': self.__sUrl, 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3' # 'Content-Type': 'application/x-www-form-urlencoded' } adcode = random.uniform(000.000000000, 999.999999999) Mode = '' # Mode = {'dl_no_ssl': 'on', 'dlinline': 'on'} Mode = {'dl_no_ssl': 'on', 'adzone': adcode} postdata = urlEncode(Mode) req = urllib2.Request(url, postdata, headers) try: # import ssl # context = ssl._create_unverified_context() # response = urllib2.urlopen(req, context=context) response = urllib2.urlopen(req) except UrlError as e: print(e.read()) print(e.reason) sHtmlContent = response.read() response.close() # fh = open('c:\\test.txt', "w") # fh.write(sHtmlContent) # fh.close() api_call = self.GetMedialinkDL(sHtmlContent) if (api_call): return True, api_call return False, False
def __getMediaLinkForGuest(self): api_call = '' url = self.__sUrl oRequest = cRequestHandler(url) oRequest.addHeaderEntry('User-Agent', UA) oRequest.addHeaderEntry('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8') oRequest.addHeaderEntry('Accept-Language', 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3') sHtmlContent = oRequest.request() oParser = cParser() sPattern = '<script type="text/javascript" src="(.+?)"' aResult = oParser.parse(sHtmlContent, sPattern)[1][1] oRequest = cRequestHandler(aResult) oRequest.addHeaderEntry('User-Agent', UA) oRequest.addHeaderEntry('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8') oRequest.addHeaderEntry('Accept-Language', 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3') sHtmlContent = oRequest.request() sPattern = '(?:parseJSON|atob).+?ey(.+?)"' code = oParser.parse(sHtmlContent, sPattern) for i in code[1]: try: if isMatrix(): code = base64.b64decode("ey" + i).decode('ascii') else: code = base64.b64decode("ey" + i) break except: pass api_call = json.loads(code)['url'] if (api_call): return True, api_call + '|' + urlEncode(headers) return False, False
def getParameterAsUri(self): if len(self.__aParams) > 0: return urlEncode(self.__aParams) return 'params=0'
def __callRequest(self, jsonDecode=False): if self.__enableDNS: import socket self.save_getaddrinfo = socket.getaddrinfo socket.getaddrinfo = self.new_getaddrinfo if self.__aParamatersLine: sParameters = self.__aParamatersLine else: sParameters = self.__aParamaters if (self.__cType == cRequestHandler.REQUEST_TYPE_GET): if (len(sParameters) > 0): if (self.__sUrl.find('?') == -1): self.__sUrl = self.__sUrl + '?' + str(sParameters) sParameters = '' else: self.__sUrl = self.__sUrl + '&' + str(sParameters) sParameters = '' sContent = '' if self.BUG_SSL == True: self.verify = False if self.__cType == cRequestHandler.REQUEST_TYPE_GET: method = "GET" else: method = "POST" oResponse = None try: _request = Request(method, self.__sUrl, headers=self.__aHeaderEntries) if method in ['POST']: _request.data = sParameters if self.__Cookie: _request.cookies = self.__Cookie if self.json: _request.json = self.json prepped = _request.prepare() self.s.headers.update(self.__aHeaderEntries) oResponse = self.s.send(prepped, timeout=self.__timeout, allow_redirects=self.redirects, verify=self.verify) self.__sResponseHeader = oResponse.headers self.__sRealUrl = oResponse.url if jsonDecode == False: sContent = oResponse.content #Necessaire pour Python 3 if isMatrix() and not 'youtube' in oResponse.url: try: sContent = sContent.decode('unicode-escape') except: try: sContent = sContent.decode() except: pass else: sContent = oResponse.json() except ConnectionError as e: # Retry with DNS only if addon is present from Plugins.Extensions.IPTVPlayer.tsiplayer.addons.resources.lib import xbmcvfs if xbmcvfs.exists('special://home/addons/script.module.dnspython/' ) and self.__enableDNS == False: self.__enableDNS = True return self.__callRequest() else: error_msg = addon().VSlang(30470) except RequestException as e: if 'CERTIFICATE_VERIFY_FAILED' in str(e) and self.BUG_SSL == False: self.BUG_SSL = True return self.__callRequest() elif 'getaddrinfo failed' in str(e) and self.__enableDNS == False: # Retry with DNS only if addon is present from Plugins.Extensions.IPTVPlayer.tsiplayer.addons.resources.lib import xbmcvfs if xbmcvfs.exists( 'special://home/addons/script.module.dnspython/'): self.__enableDNS = True return self.__callRequest() else: error_msg = addon().VSlang(30470) else: error_msg = "%s (%s),%s" % (addon().VSlang(30205), e, self.__sUrl) dialog().VSerror(error_msg) sContent = '' if oResponse.status_code in [503, 403]: if not "Forbidden" in sContent: #Default CLOUDPROXY_ENDPOINT = 'http://localhost:8191/v1' try: json_session = post(CLOUDPROXY_ENDPOINT, headers=self.__aHeaderEntries, data=dumps({'cmd': 'sessions.list'})) except: dialog().VSerror("%s" % ( "Page protege par Cloudflare, veuillez executer FlareSolverr." )) #On regarde si une session existe deja. if json_session.json()['sessions']: cloudproxy_session = json_session.json()['sessions'][0] else: json_session = post(CLOUDPROXY_ENDPOINT, headers=self.__aHeaderEntries, data=dumps({'cmd': 'sessions.create'})) response_session = loads(json_session.text) cloudproxy_session = response_session['session'] self.__aHeaderEntries[ 'Content-Type'] = 'application/x-www-form-urlencoded' if ( method == 'post') else 'application/json' #Ont fait une requete. json_response = post(CLOUDPROXY_ENDPOINT, headers=self.__aHeaderEntries, data=dumps({ 'cmd': 'request.%s' % method.lower(), 'url': self.__sUrl, 'session': cloudproxy_session, 'postData': '%s' % urlEncode(sParameters) if (method.lower() == 'post') else '' })) http_code = json_response.status_code response = loads(json_response.text) if 'solution' in response: if self.__sUrl != response['solution']['url']: self.__sRealUrl = response['solution']['url'] sContent = response['solution']['response'] if oResponse and not sContent: #Ignorer ces deux codes erreurs. ignoreStatus = [200, 302] if oResponse.status_code not in ignoreStatus: dialog().VSerror("%s (%d),%s" % (addon().VSlang(30205), oResponse.status_code, self.__sUrl)) if sContent: if (self.__bRemoveNewLines == True): sContent = sContent.replace("\n", "") sContent = sContent.replace("\r\t", "") if (self.__bRemoveBreakLines == True): sContent = sContent.replace(" ", "") if self.__enableDNS: socket.getaddrinfo = self.save_getaddrinfo self.__enableDNS = False return sContent
def __getMediaLinkByPremiumUser(self): api_call = False if not self.oPremiumHandler.Authentificate(): return False, False url = 'https://1fichier.com/?' + self.__getIdFromUrl(self.__sUrl) ''' La partie ci-dessous permet d'utiliser l'option "Forcer l'affichage du menu pour les téléchargements" permettant notamment de choisir depuis l'interface web de télécharger ou d'ajouter un fichier. Pour cela, on va ajouter le paramètre e=1 (cf. https://1fichier.com/hlp.html#dev ) à la requête permettant d'obtenir le lien direct ''' sHtmlContent = self.oPremiumHandler.GetHtml('%s' % url + '&e=1') if (sHtmlContent): # L'option est désactivée : la réponse sera de type "text/plain; charset=utf-8", exemple : # https://serveur-2b.1fichier.com/lelienactif;Film.de.Jacquie.et.Michel.a.la.montagne.mkv;1234567890;0 m = re.search('^(.*);.*;.*;.*$', sHtmlContent) if (m): url = m.group(1) # L'option est activée : pour récupérer le lien direct il faut POSTer le formulaire demandant le download else: cookie = self.oPremiumHandler.AddCookies().replace( 'Cookie=', '', 1) data = {'submit': 'download'} # Seul le Cookie est nécessaire, néanmoins autant rendre les headers cohérents headers = { 'User-Agent': UA, 'Host': '1fichier.com', 'Referer': url, 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3', 'Cookie': cookie, 'Content-Length': '15', 'Content-Type': 'application/x-www-form-urlencoded' } request = urllib2.Request(url, urlEncode(data), headers) try: response = urllib2.urlopen(request) except UrlError as e: print(e.read()) print(e.reason) # Par défaut on suit la redirection (code: 302 + entête 'Location') dans la réponse # on peut ainsi récupérer le lien direct url = response.geturl() response.close() else: return False, False # Mode = '' # Mode = {'dl_no_ssl': 'on' , 'dlinline': 'on'} # Mode = {'dl_no_ssl': 'on'} # postdata = urlEncode(Mode) # Pas de page html mais lien direct # sHtmlContent = self.oPremiumHandler.GetHtml(url, postdata) # fh = open('c:\\test.txt', "w") # fh.write(sHtmlContent) # fh.close() # mode inline # url = url + '&inline' api_call = url + '|' + self.oPremiumHandler.AddCookies() # VSlog(api_call) if (api_call): return True, api_call return False, False
def showMovies(sSearch=''): oGui = cGui() oParser = cParser() oInputParameterHandler = cInputParameterHandler() nextPageSearch = oInputParameterHandler.getValue('nextPageSearch') sUrl = oInputParameterHandler.getValue('siteUrl') if nextPageSearch: sSearch = sUrl if sSearch: if URL_SEARCH[0] in sSearch: sSearch = sSearch.replace(URL_SEARCH[0], '') if nextPageSearch: query_args = (('do', 'search'), ('subaction', 'search'), ('search_start', nextPageSearch), ('story', sSearch)) else: query_args = (('do', 'search'), ('subaction', 'search'), ('story', sSearch)) data = urlEncode(query_args) oRequestHandler = cRequestHandler(URL_SEARCH[0]) oRequestHandler.setRequestType(cRequestHandler.REQUEST_TYPE_POST) oRequestHandler.addParametersLine(data) oRequestHandler.addParameters('User-Agent', UA) sHtmlContent = oRequestHandler.request() else: sUrl = oInputParameterHandler.getValue('siteUrl') oRequestHandler = cRequestHandler(sUrl) sHtmlContent = oRequestHandler.request() if sSearch: sPattern = '<div class="fullstream fullstreaming">.+?<img src="([^"]+)".+?<h3 class="mov-title"><a href="([^"]+)" >([^<]+)</a>.+?<strong>(?:Qualit|Version).+?">(.+?)</a>.+?</*strong>' else: sPattern = 'class="fullstream fullstreaming".+?src="([^"]+).+?alt="([^"]+).+?<strong>(?:Qualit|Version).+?>(.+?)</a>.+?</*strong>.+?xfsearch.+?>([^<]+).+?itemprop="description".+?;">([^<]+).+?<a href="([^"]+)' aResult = oParser.parse(sHtmlContent, sPattern) if (aResult[0] == False): oGui.addText(SITE_IDENTIFIER) if (aResult[0] == True): total = len(aResult[1]) progress_ = progress().VScreate(SITE_NAME) oOutputParameterHandler = cOutputParameterHandler() for aEntry in aResult[1]: progress_.VSupdate(progress_, total) if progress_.iscanceled(): break sYear = '' if sSearch: sThumb = aEntry[0] if sThumb.startswith('/'): sThumb = URL_MAIN[:-1] + sThumb siteUrl = re.sub('www\.', '', aEntry[1]) sTitle = aEntry[2] sQual = aEntry[3] sQual = sQual.replace(':', '').replace(' ', '').replace(',', '/') sDesc = '' else: sThumb = aEntry[0] if sThumb.startswith('/'): sThumb = "https:" + sThumb sTitle = aEntry[1] sQual = aEntry[2] sQual = sQual.replace(':', '').replace(' ', '').replace(',', '/') # Certain film n'ont pas de date. try: sYear = re.search('(\d{4})', aEntry[3]).group(1) except: pass sDesc = aEntry[4] siteUrl = re.sub('www\.', '', aEntry[5]) sDisplayTitle = '%s [%s]' % (sTitle, sQual) oOutputParameterHandler.addParameter('siteUrl', siteUrl) oOutputParameterHandler.addParameter('sMovieTitle', sTitle) oOutputParameterHandler.addParameter('sThumb', sThumb) oOutputParameterHandler.addParameter('sYear', sYear) oGui.addMovie(SITE_IDENTIFIER, 'showHosters', sDisplayTitle, 'films.png', sThumb, sDesc, oOutputParameterHandler) progress_.VSclose(progress_) if sSearch: sPattern = '<a name="nextlink" id="nextlink" onclick="javascript:list_submit\(([0-9]+)\); return\(false\)" href="#">Suivant' aResult = oParser.parse(sHtmlContent, sPattern) if (aResult[0] == True): oOutputParameterHandler = cOutputParameterHandler() oOutputParameterHandler.addParameter('siteUrl', sSearch) oOutputParameterHandler.addParameter('nextPageSearch', aResult[1][0]) number = re.search('([0-9]+)', aResult[1][0]).group(1) oGui.addNext(SITE_IDENTIFIER, 'showMovies', 'Page ' + number, oOutputParameterHandler) else: sNextPage = __checkForNextPage(sHtmlContent) if (sNextPage != False): oOutputParameterHandler = cOutputParameterHandler() oOutputParameterHandler.addParameter('siteUrl', sNextPage) number = re.search('/page/([0-9]+)', sNextPage).group(1) oGui.addNext(SITE_IDENTIFIER, 'showMovies', 'Page ' + number, oOutputParameterHandler) if nextPageSearch: oGui.setEndOfDirectory() if not sSearch: oGui.setEndOfDirectory()