def getChannels(page): x = [] start = False if str(page) == '0': html = ShowsportTvCom.getContentFromUrl(ShowsportTvCom.MAIN_URL) element = {} element["link"] = '1' element["title"] = 'Display by event' x.append(element) if html.find('<div id="cssmenu">')>-1: #build channels menu from provider cssMenu = Decoder.extract('<div id="cssmenu">','</ul>',html) for htmlElement in cssMenu.split('<li class="has-sub">'): if htmlElement.find('<a href="')>-1: element = {} link = Decoder.extract('<a href="','"',htmlElement) if htmlElement.find(' title="')>-1: title = Decoder.extract(' title="','"',htmlElement) img = Decoder.extract('img src="/','"',htmlElement) element["title"] = title element["link"] = ShowsportTvCom.MAIN_URL+link element["thumbnail"] = ShowsportTvCom.MAIN_URL+img logger.debug("found element: "+title+", url: "+element["link"]) if title != '': x.append(element) elif str(page) == '1': #show by events html = ShowsportTvCom.getContentFromUrl(ShowsportTvCom.MAIN_URL) html = Decoder.extract('<div class="listmatch">','<div id="right_content">',html) for htmlElement in html.split('<div class="leaguelogo column">'): if htmlElement.find(' href="')>-1: href = Decoder.extract(' href="','">',htmlElement) timeHtml = Decoder.extract('<div class="date_time column"><span class="','</span></div>',htmlElement) time = "" if timeHtml.find('</span><span')>-1: time = Decoder.extract('>','</span><span',timeHtml) time+= " - "+timeHtml[timeHtml.rfind(">")+1:] name = Decoder.extract('png"><span>','</span></div>',htmlElement) logger.debug("first name is: "+name) if htmlElement.find('px;">')>-1 and htmlElement.find('</span><img')>-1: name += " vs "+Decoder.extract('px;">','</span><img',htmlElement) logger.debug("final name is: "+name) element = {} if time=='': element["title"] = name else: element["title"] = time+" - "+name element["link"] = ShowsportTvCom.MAIN_URL+href logger.debug("appending event: "+element["title"]) if element["title"].find(" vs ")>-1: x.append(element) else: #open link html = ShowsportTvCom.getContentFromUrl(page) iframeUrl = ShowsportTvCom.MAIN_URL+Decoder.extract('<iframe frameborder="0" marginheight="0" marginwidth="0" height="450" src="/','"',html) logger.debug("iframeUrl is: "+iframeUrl) html2 = ShowsportTvCom.getContentFromUrl(iframeUrl,"",ShowsportTvCom.cookie,page) if html2.find("http://www.caston.tv/player.php?")>-1: id = Decoder.extract("var id = "," ;",html2) url2 = "http://www.caston.tv/player.php?id="+id html3 = ShowsportTvCom.getContentFromUrl(url2,"id="+id,ShowsportTvCom.cookie,iframeUrl) script = Decoder.extract('<script type="text/javascript">\n','</script>',html3) if script.find("document.write(unescape('")>-1: #patch scriptContent = Decoder.extract("document.write(unescape('","'));",script) scriptContent = urllib.unquote(scriptContent) script=re.compile('eval\(function\(w,i,s,e\).*}\((.*?)\)').findall(scriptContent)[0] finalScriptContent = Decoder.preWise(script) logger.debug(finalScriptContent) token = Decoder.extract("token:\"","\"",finalScriptContent) logger.debug("pre-token is: "+token) ajaxContent = dict(token=token, is_ajax=1) #logger.debug(html3) tokenResponse = ShowsportTvCom.getContentFromUrl("http://www.caston.tv/sssss.php",urllib.urlencode(ajaxContent),ShowsportTvCom.cookie,url2,True) logger.debug("token response: "+tokenResponse) file = Decoder.extract("file:\"","\"",finalScriptContent)+Decoder.extract('","','",',tokenResponse)+"&e="+Decoder.rExtract(',',']',tokenResponse)+"|Referer=http://p.jwpcdn.com/6/12/jwplayer.flash.swf" elif html2.find("http://www.sostart.pw/js/embed.js")>-1: fid = Decoder.extract('<script type="text/javascript"> fid="','"',html2) url3 = "http://www.sostart.pw/jwplayer6.php?channel="+fid html3 = ShowsportTvCom.getContentFromUrl(url3,"",ShowsportTvCom.cookie,iframeUrl) if html3.find("http://static.bro.adca.st/broadcast/player.js")>-1: id2 = Decoder.extract("<script type='text/javascript'>id='","';",html3) logger.debug("using id = "+id2) url4 = "http://bro.adcast.site/stream.php?id="+id2+"&width=700&height=450&stretching=uniform" html4 = ShowsportTvCom.getContentFromUrl(url4,"",ShowsportTvCom.cookie,url3) logger.debug("html4: "+html4) curl = Decoder.extract('curl = "','"',html4) token = ShowsportTvCom.getContentFromUrl('http://bro.adcast.site/getToken.php',"",ShowsportTvCom.cookie,url4,True) logger.debug("token: "+token) token = Decoder.extract('":"','"',token) file = base64.decodestring(curl)+token+"|"+Downloader.getHeaders('http://cdn.bro.adcast.site/jwplayer.flash.swf') logger.debug("final url is: "+file) elif html2.find("http://www.iguide.to/embed")>-1: nextIframeUrl = Decoder.extractWithRegex('http://www.iguide.to/embed','"',html2).replace('"',"") file = Decoder.decodeIguide(nextIframeUrl,iframeUrl) elif "/embedplayer.php" in html2: nextIframeUrl = ShowsportTvCom.MAIN_URL+Decoder.extractWithRegex('/embedplayer.php', "'", html2).replace("'", "") logger.debug("next loop will use: "+nextIframeUrl) file = ShowsportTvCom.getChannels(nextIframeUrl) elif html2.find("adca.st/stream.php")>-1: token = False if "http://bro.adca.st/stream.php" not in html2: token = True id2 = Decoder.extract("<script type='text/javascript'>id='","';",html2) logger.debug("using id = "+id2) url4 = "http://bro.adcast.site/stream.php?id="+id2+"&width=700&height=450&stretching=uniform" else: #it's built, not needed extract id url4 = Decoder.extractWithRegex("http://bro.adca.st/stream.php",'"',html2) html4 = ShowsportTvCom.getContentFromUrl(url4,"",ShowsportTvCom.cookie,iframeUrl) logger.debug("html4: "+html4) curl = Decoder.extract('curl = "','"',html4) tokenUrl = "http://bro.adca.st/getToken.php" swfUrl = "http://cdn.allofme.site/jw/jwplayer.flash.swf" if token: tokenUrl = 'http://bro.adcast.site/getToken.php' swfUrl = 'http://cdn.bro.adcast.site/jwplayer.flash.swf' token = ShowsportTvCom.getContentFromUrl(tokenUrl,"",ShowsportTvCom.cookie,url4,True) logger.debug("token: "+token) token = Decoder.extract('":"','"',token) file = base64.decodestring(curl)+token+"|"+Downloader.getHeaders(swfUrl) logger.debug("final url is: "+file) else: logger.debug("trying crickfreetv way...: "+html2) file = Cricfreetv.seekIframeScript(html2, page, page) logger.debug("final remote url: "+file) element = {} element["link"] = file element["permaLink"] = True element["title"] = "Watch streaming" x.append(element) return x
def getSection(url): x = [] url = url.replace("&","&") html = RTVEAlaCarta.getContentFromUrl(url=url,referer=RTVEAlaCarta.A_LA_CARTA) content = Decoder.rExtract('</ul><div class="ContentTabla">','<div class="pagbox mark">',html) if ' class="anterior">' in html: logger.debug("'anterior' FOUND!") if '" class="anterior">' not in html: html2 = Decoder.extract(' class="anterior">', "</li>", html) else: html2 = Decoder.extract('" class="anterior">', "</li>", html) link = Decoder.extract('href="', '"', html2) if "<span>" in html2: title = Decoder.extract('<span>', '</span>', html2) else: #title is in other part, so it's needed more html html2 = Decoder.rExtract("<li",'" class="anterior">', html) title = Decoder.extract('title="','"',html2) element = {} if RTVEAlaCarta.MAIN_URL not in link: link = RTVEAlaCarta.MAIN_URL + link element["link"] = link element["title"] = title x.append(element) if '<!--EMPIEZA TOOL-TIP-->' in content: for line in content.split('<!--EMPIEZA TOOL-TIP-->'): logger.debug("html line is: "+line) title = Decoder.extract(' title="Ver programa seleccionado">','<',line) link = Decoder.rExtract('<a href=',title+'</a>',line) link = Decoder.extract('"','"',link) logger.debug("new link is: "+link) element = {} element["title"] = title if RTVEAlaCarta.MAIN_URL not in link: link = RTVEAlaCarta.MAIN_URL+link logger.debug("title: "+title+", url: "+link) element["link"] = link x.append(element) elif '</li><li class="' in content: for line in content.split('</li><li class="'): logger.debug("html line is: " + line) link = Decoder.extract('<a href="', '"', line) title = Decoder.extract('/">', '</a>', line).replace(" "," ").replace("<em>","").replace("</em>","") element = {} element["title"] = title if RTVEAlaCarta.MAIN_URL not in link: link = RTVEAlaCarta.MAIN_URL + link logger.debug("title: " + title + ", url: " + link) element["link"] = link element["finalLink"] = True if "</span>" not in title: x.append(element) elif '</li><li class="' in html: for line in html.split('</li><li class="'): logger.debug("html line is: " + line) link = Decoder.extract('<a href="', '"', line) title = Decoder.extract('/">', '</a>', line).replace(" ", " ").replace("<em>", "").replace("</em>", "") element = {} element["title"] = title if RTVEAlaCarta.MAIN_URL not in link: link = RTVEAlaCarta.MAIN_URL + link logger.debug("title: " + title + ", url: " + link) element["link"] = link element["finalLink"] = True if "</span>" not in title: x.append(element) if ' class="siguiente">' in html: logger.debug("'siguiente' FOUND!") if '" class="siguiente">' not in html: html2 = Decoder.extract(' class="siguiente">', "</li>", html) else: html2 = Decoder.extract('" class="siguiente">', "</li>", html) link = Decoder.extract('href="', '"', html2) if "<span>" in html2: title = Decoder.extract('<span>', '</span>', html2) else: #title is in other part, so it's needed more html html2 = Decoder.rExtract("<li", '" class="siguiente">', html) title = Decoder.extract('title="','"',html2) element = {} if RTVEAlaCarta.MAIN_URL not in link: link = RTVEAlaCarta.MAIN_URL + link element["link"] = link element["title"] = title x.append(element) if len(x) == 0: #json api pageCode = Decoder.extract('/alacarta/interno/contenttable.shtml?ctx=','&',html) jsonPage = "http://www.rtve.es/api/programas/%s/videos.json?page=1&size=60" % pageCode jsonContent = RTVEAlaCarta.getContentFromUrl(url=jsonPage) try: jsonObject = json.loads(jsonContent) logger.debug("loaded json") for item in jsonObject["page"]["items"]: logger.debug("item looping...") url = item["htmlUrl"] title = item["longTitle"] element = {} element["link"] = link element["title"] = title try: element["thumbnail"] = item["imageSEO"] except: logger.error("No imageSEO found!") pass element["finalLink"] = True x.append(element) except: logger.error("Could not parse JSON from ALACARTA alternative way: "+jsonPage) return x
def seekIframeScript(html, referer, iframeUrl): lastIframeHtml = html file = "" logger.debug("seek iframe logic... ") if html.find("http://theactionlive.com/live") > -1: file = Cricfreetv.launchScriptLogic( "http://theactionlive.com/live", html, referer, iframeUrl) elif html.find('http://biggestplayer.me/play') > -1: file = Cricfreetv.launchScriptLogic("http://biggestplayer.me/play", html, referer, iframeUrl) elif html.find("http://www.yotv.co/play") > -1: file = Cricfreetv.launchScriptLogic("http://www.yotv.co/play", html, referer, iframeUrl) elif html.find("http://www.yocast.tv/embed") > -1: file = Cricfreetv.launchScriptLogic("http://www.yocast.tv/embed", html, referer, iframeUrl) elif html.find("http://www.rocktv.co/play") > -1: file = Cricfreetv.launchScriptLogic("http://www.rocktv.co/play", html, referer, iframeUrl) elif html.find("http://miplayer.net/embed") > -1: file = Cricfreetv.launchScriptLogic("http://miplayer.net/embed", html, referer, iframeUrl) elif html.find("http://www.cast4u.tv/embed") > -1: file = Cricfreetv.launchScriptLogic("http://www.cast4u.tv/embed", html, referer, iframeUrl) elif html.find("http://www.cast4u.tv/Player") > -1: file = Cricfreetv.launchScriptLogic( "http://www.cast4u.tv/Playercr", html, referer, iframeUrl) elif html.find("http://www.topcast.live/embed") > -1: file = Cricfreetv.launchScriptLogic( "http://www.topcast.live/embed", html, referer, iframeUrl) elif 'http://www.webtv.ws/player' in html: file = Cricfreetv.launchScriptLogic("http://www.webtv.ws/player", html, referer, iframeUrl) elif "http://www.hdcast.info/embed.js" in html: id = Decoder.extract('fid="', '"', html) scriptUrl = "http://www.hdcast.info/embed.php?live=" + id + "&vw=620&vh=490" logger.debug("using script url: " + scriptUrl) lastIframeHtml = Cricfreetv.getContentFromUrl( scriptUrl, "", Cricfreetv.cookie, iframeUrl) logger.debug("html is: " + lastIframeHtml) lastIframeHtml = Decoder.rExtract("<body", "</body>", lastIframeHtml) file = Cricfreetv.seekIframeScript(lastIframeHtml, iframeUrl, scriptUrl) elif html.find("http://violadito.biggestplayer.me/playercr.js") > -1: id = Decoder.extract("<script type='text/javascript'>id='", "'", html) logger.debug("violadito id=" + id) #newUrl = "http://lqgq.biggestplayer.me/streamcr.php?id="+id+"&width=620&height=460" jsLogic = Cricfreetv.getContentFromUrl( 'http://violadito.biggestplayer.me/playercr.js', "", Cricfreetv.cookie, iframeUrl) try: jsLogic = jsunpack.unpack(jsLogic) logger.debug("jsLogic: " + jsLogic) newUrl = Decoder.extractWithRegex('http://', '"', jsLogic).replace( "\\'+id+\\'", str(id)) except: logger.debug( "could not use unpack from jsunpack, using new method...") logger.debug("jsLogic is: " + jsLogic) newUrl = Decoder.extract(' src="', '"', jsLogic).replace("'+id+'", id) pass logger.debug("using referer: " + iframeUrl) html2 = Cricfreetv.getContentFromUrl(newUrl, "", Cricfreetv.cookie, iframeUrl) logger.debug("extracting file from " + newUrl) if html2.find('file: "') > -1: file = Decoder.extract('file: "', '"', html2) logger.debug("obtained file: " + file) elif 'file: "rtmp:' in html: # found final link logger.debug("detected rtmp link...") rtmp = "rtmp:" + Decoder.extract('file: "rtmp:', '"', html) swfJS = Decoder.extract('<script src="', '"', html[html.find('<div id="myElement">'):]) jsContent = Downloader.getContentFromUrl(url=swfJS, referer=referer) swfUrl = Decoder.extract('"flashplayer": "', '"', jsContent) if "http:" not in swfUrl: swfUrl = "http:" + swfUrl logger.debug("swfUrl is: " + swfUrl) logger.debug("iframeUrl is: " + iframeUrl) logger.debug("referer is: " + referer) link = rtmp + " swfUrl=" + swfUrl + " pageUrl=" + iframeUrl logger.debug("final rtmp link built is: " + link) file = link elif 'file: "http' in html: # found final link logger.debug("using http file extractor...") file = "http" + Decoder.extract('file: "http', '"', html) file += "|" + Downloader.getHeaders( iframeUrl) #TODO review this part logger.debug("found final link: " + file) elif html.find("http://www.filmon.com/tv/") > -1: url = Decoder.extractWithRegex("http://www.filmon.com/tv/", '"', html).replace('"', "") logger.debug("using first filmon.com url from provider, url: " + url + ", r: " + referer) file = Filmoncom.launchScriptLogic(url, referer)[0]["url"] elif html.find('return(["r","t","m","p"' ) > -1: #changed order to build final url first logger.debug("launching array logic for rtmp link...") swfUrl = "http://cdn.ibrod.tv/player/jwplayer.flash.swf" if 'cast4u.tv' in html: swfUrl = "http://cast4u.tv/jwplayer/jwplayer.flash.swf" elif 'http://www.hdcast.info/video-js/video-js.swf' in html: swfUrl = "http://www.hdcast.info/video-js/video-js.swf" if '<script type="text/javascript">\nvar' in html: scriptSplit = '<script type="text/javascript">\nvar' elif '<script type="text/javascript">\n\nvar' in html: scriptSplit = '<script type="text/javascript">\n\nvar' bruteData = Decoder.extract(scriptSplit, "</script>", html) rtmp = "" file = Decoder.extract('file: ', '}],', bruteData).replace(' ', '') logger.debug("file form is: " + file) playpath = "" for functionName in file.split('+'): if functionName.find("/") == -1: logger.debug("using function: " + functionName) bruteData2 = Decoder.extract( 'function ' + functionName + ' {', "}", bruteData) line = Decoder.extract('return([', ');', bruteData2) #now begin the fix for linePart in line.split("+"): if '].join' in linePart: linePart = linePart[:linePart.find('].join')] linePart2 = linePart.replace('","', "").replace( '"', '').replace('\\', "").replace(",", "") logger.debug("at this moment linePart1 is: " + linePart2) rtmp += linePart2 if '/' not in linePart2: playpath = linePart2 elif 'document.getElementById' in linePart: #extract id and get content idSpan = Decoder.extract('(', ')', linePart).replace( "\"", "").replace("'", "") content = Decoder.extract(' id=' + idSpan + '>', '</span>', html) logger.debug("at this moment linePart2 is: " + content) rtmp += content elif 'join("")' in linePart: #array to join with a replace like first condition idArrayVar = linePart.replace('.join("")', '').replace(' ', '') content = Decoder.extract( 'var ' + idArrayVar + " = [", "];", bruteData).replace(",", "").replace('"', '') logger.debug("at this moment linePart3 is: " + content) rtmp += content else: rtmp += "/" logger.debug("at this moment final rtmp is: " + rtmp) ''' token = "" if bruteData.find('securetoken: ')>-1: token = Decoder.extract('securetoken: ','\n',bruteData) swfUrlJS = 'http://cast4u.tv/jwplayer/jwplayer.js?v=3.3' htmlToken = Cricfreetv.getContentFromUrl(url=swfUrlJS) token = Decoder.extract('var '+token+' = "','"',htmlToken) logger.debug("Fresh token is: "+token) ''' if "/live" in rtmp: app = 'live' + Decoder.extract('/live', '==/', rtmp) + "==/" else: #/hd app = 'hd' + Decoder.extract('/hd', '==/', rtmp) + "==/" file = rtmp + " app=" + app + " playpath=" + playpath + r" token=%XB00(nKH@#. flashver=WIN\2021,0,0,182 timeout=30 live=1 swfUrl=" + swfUrl + " pageUrl=" + iframeUrl + "" logger.debug("Built a rtmp with data: " + file) elif html.find('securetoken:') > -1: logger.debug("building final link from html: " + html) file = Decoder.extract('file: "', '"', html) securetoken = Decoder.extract('securetoken: "', '"', html) #logger.debug(html) flashPlayer = 'http://p.jwpcdn.com/6/12/jwplayer.flash.swf' tokenString = "" if "html>" not in securetoken: tokenString = " token=" + securetoken else: jsUrl = Decoder.rExtract( '<script type="text/javascript" src="', '" ></script>', html) jsContent = Cricfreetv.getContentFromUrl(url=jsUrl) var = Decoder.extract('securetoken: ', "\n", html) logger.debug("seeking var: " + var) tokenString = Decoder.extract('var ' + var + " = \"", '";', jsContent) logger.debug("new token string is: " + tokenString) tokenString = " token=" + tokenString rtmpUrl = file[0:file.rfind('/') + 1] + " playpath=" + file[ file.rfind('/') + 1:] + tokenString + " swfUrl=" + flashPlayer + " live=1 timeout=13 pageUrl=" + iframeUrl logger.debug("found final link: " + rtmpUrl) file = rtmpUrl elif html.find("eval(unescape('") > -1: logger.debug("eval unescape js logic...") html = Cricfreetv.decodeContent(html).lower() elif html.find('<a href="http://sports4u.tv/channel' ) > -1 or html.find('http://sports4u.tv/embed/') > -1: logger.debug("embed link logic...") if html.find('http://sports4u.tv/embed/') > -1: urlLink = Decoder.extractWithRegex('http://sports4u.tv/embed/', '"', html).replace('"', "") logger.debug("seek new iframe url with: " + urlLink) html2 = Cricfreetv.getContentFromUrl(urlLink, "", Cricfreetv.cookie, iframeUrl) file = Cricfreetv.seekIframeScript(html2, iframeUrl, urlLink) elif html.find('<a href="http://sports4u.tv/channel') > -1: logger.debug("urlLink...") urlLink = Decoder.extractWithRegex( '<a href="http://sports4u.tv/channel', '/"', html) logger.debug("urlLink2..." + urlLink) urlLink = urlLink[urlLink.find('"') + 1:urlLink.rfind('"')] logger.debug("urlLinkFinal..." + urlLink) if urlLink != iframeUrl: urlLink = urlLink.replace(".tv/", ".pw/") html2 = Cricfreetv.getContentFromUrl( url=urlLink, cookie=Cricfreetv.cookie, referer=iframeUrl) logger.debug("html2 is: " + html2) file = Cricfreetv.seekIframeScript(html2, iframeUrl, urlLink) if file == '': #extract iframe value iframe = Decoder.extract( '<iframe frameborder="0" marginheight="0" marginWidth="0" height="490" id="iframe" src="', '" id="', html).replace('"', "") file = Cricfreetv.extractIframeValue( iframe, html, referer) elif ' src="http://cricfree.sx/' in html: logger.debug("native cricfree.sx logic") #it's a cricfree.sx native page, so launch this logic urlLink = Decoder.extractWithRegex('http://cricfree.sx/', '"', html).replace('"', "") logger.debug("seek new http://cricfree.sx/ iframe url with: " + urlLink) html2 = Cricfreetv.getContentFromUrl(urlLink, "", Cricfreetv.cookie, iframeUrl) file = Cricfreetv.seekIframeScript(html2, iframeUrl, urlLink) elif 'http://sports4u.pw/embed/' in html: logger.debug("repeating proccess...") newOldUrl = Decoder.extractWithRegex('http://sports4u.pw/embed/', '"', html).replace('"', '') logger.debug("new old url is: " + newOldUrl) html2 = Cricfreetv.getContentFromUrl(url=newOldUrl, referer=iframeUrl) logger.debug("html is: " + html2) file = Cricfreetv.seekIframeScript(html2, iframeUrl, newOldUrl) else: logger.debug("enterring to ELSE logic") if html.find( '<iframe id="player" scrolling="no" width="620" height="490" allowtransparency="no" frameborder="0" src="' ) > -1: iframe = Decoder.extract( '<iframe id="player" scrolling="no" width="620" height="490" allowtransparency="no" frameborder="0" src="', '"', html) file = Cricfreetv.extractIframeValue(iframe, html, referer) elif html.find('<iframe ') > -1: # brute method forced logger.debug("brute method launched...") logger.debug("referer is: " + referer) logger.debug("iframeUrl is: " + iframeUrl) iframe = Decoder.rExtract('<iframe ', '</iframe>', html) iframe = Decoder.extract('src="', '"', iframe) if iframe == referer or iframe == iframeUrl: logger.debug("is the same page so needs to be changed!") logger.debug("html is: " + html) for content in html.split(".php"): link = content[content.rfind('"') + 1:] + ".php" logger.debug("target ELSE link is: " + link) if "http://" in link and "/update/" not in link and "/update/" in iframeUrl: logger.debug("ELSE link has been updated from: " + iframeUrl + ", to: " + link) iframe = link if iframe != referer and iframe != iframeUrl: logger.debug("fixed the same url, continue...") file = Cricfreetv.extractIframeValue( iframe, html, referer) else: logger.debug("NOT fixed the same url, stopping...") else: file = Cricfreetv.extractIframeValue(iframe, html, referer) else: logger.debug(html) return file