def check(self,channels): for cnum in channels.keys(): ctitle="%s %d"%(c,cnum) bt.notify(notifications["check"],ctitle) channels[cnum]=self.rplay(channels,cnum,tout=ctimeout,silent=True)[cnum] if self.isPlaying(): self.stop() return channels
def splay(self, li, tout=None, silent=False): # returns 0:alive,1:scraper error,2:dead cname = bt.getliprop(li, "link") if tout is None: self.timeout = self.deftimeout else: self.timeout = tout stream = self.scraper(li, self.timeout) if stream is None: ret = 1 else: self.play(stream, self.create_item(li)) time.sleep(1) self.timeout -= 1 if self.isPlaying: if not silent: self.notification(0, notifications["waiting"] % (cname, self.timeout)) factor = 5 for i in range(self.timeout * factor): if self.alive or not self.isPlaying(): break # if not silent and self.progres.iscanceled(): # self.stop() # self.notification(100,"") # return li xbmc.sleep(1000 / factor) if not silent: self.notification( 100 * i / self.timeout / factor, notifications["waiting"] % (cname, self.timeout - i / factor), ) if not silent: self.notification(100, "") if not self.alive: self.stop() bt.notify(cname, notifications["offline"]) bt.setliprop(li, "status", notifications["red"] % notifications["dead"]) bt.setliprop(li, "last_check", time.time()) ret = 2 else: bt.setliprop(li, "status", notifications["green"] % notifications["live"]) bt.setliprop(li, "last_check", time.time()) ret = 0 self.alive = False self.postprocess(li) return ret
def rplay(self,channels,channel,tout=None,silent=False): if tout is None: self.timeout=timeout else: self.timeout=tout type,stream=scrape_channel_page(channels[channel],timeout) ctitle="%s %d %s"%(c, channels[channel]["number"], channels[channel]["name"]) if "ERROR:" in type: bt.notify(ctitle,type) channels[channel]["status"]=notifications["orange"]%type channels[channel]["last_check"]=time.time() else: li=xbmcgui.ListItem(ctitle, iconImage="DefaultFolder.png", thumbnailImage="DefaultFolder.png") self.play(stream,li) time.sleep(1) self.timeout-=1 if self.isPlaying: if not silent: progres=xbmcgui.DialogProgress() progres.create("WEBSPOR",notifications["waiting"]%(ctitle,self.timeout)) factor=5 for i in range(self.timeout*factor): if self.alive or not self.isPlaying(): break if not silent and progres.iscanceled(): self.stop() progres.close() return channels xbmc.sleep(1000/factor) if not silent: progres.update(100*i/self.timeout/factor,notifications["waiting"]%(ctitle,self.timeout-i/factor)) if not silent: progres.close() if not self.alive: self.stop() bt.notify(ctitle,notifications["offline"]) channels[channel]["status"]=notifications["red"]%notifications["dead"] channels[channel]["last_check"]=time.time() else: channels[channel]["status"]=notifications["green"]%notifications["live"] channels[channel]["last_check"]=time.time() self.alive=False return channels
def scrape_channel_page(li,tout=None): # scrapes the given channel and return a playable url # arguments: channel:dict ; {"link":"/channel1","name":"Channel1","status":"state","number":int(1)} # returns stream:str link=bt.getliprop(li,"link") purl="%s%s"%(defs.domain,link) page=bt.get_page(purl,defs.encoding) fidscript=re.findall('fid="(.*?)".*?script.*?src="(.*?)"',page) aliez=re.findall('src="(.*?aliez\..*?/player/live\.php.*?)"',page) mips=re.findall("channel='(.*?)', .='(.*?)';</script><script type='text/javascript' src='(.*?)'></script>",page) playerhd=re.findall("http://(.*?)/.*php\?file=([0-9]*?)&",page) weplayer=re.findall("id='(.*?)'; width='([0-9]*?)'; height='([0-9]*?)';</script><script type='text/javascript' src='/player.js'>",page) weplayer2=re.findall("id='(.*?)'; width='([0-9]*?)'; height='([0-9]*?)';</script><script type='text/javascript' src='http\://weplayer.pw/player.js'>",page) jw=re.findall('content.jwplatform.com/players/(.*?)\.html"',page) worldspor=re.findall('fid="(.*?)"',page) micast=re.findall('src="(.*?/iframe.php\?ch=.*?)"',page) sostart=re.findall("id='(.*?)';.*?</script><script type='text/javascript' src='http://sostart.org/player.js'></script>",page) zony=re.findall("channel='(.*?)'.*?src='.*?/static/scripts/zony\.js'",page) castamp=re.findall('channel="(.*?)".*?src=".*?castamp.com/embed\.js"',page) zenex=re.findall("channel='(.*?)'.*?src='.*?data/scripts/ZenexEmbed\.js'",page) janjua=re.findall("channel='(.*?)'.*?src='.*?/scripts/janjua.js'",page) ll.timeout=tout if len(janjua): type,stream=ll.scrape_url("janjua",janjua[0],purl) elif len(zenex): type,stream=ll.scrape_url("zenex",zenex[0],purl) elif len(castamp): type,stream=ll.scrape_url("castamp",castamp[0],purl) elif len(zony): type,stream=ll.scrape_url("zony",zony[0],purl) elif len(fidscript) and "cast4u" in fidscript[0][1]: key,u=fidscript[0] type,stream=ll.scrape_url("cast4u",key,defs.domain) elif len(fidscript) and "hdcast" in fidscript[0][1]: key,u=fidscript[0] type,stream=ll.scrape_url("hdcast",key,defs.domain) elif len(aliez)>0: #id=urlparse.parse_qs(urlparse.urlparse(aliez[0]).query)["id"][0] type,stream=ll.scrape_url("aliez",aliez[0],defs.domain) elif len(jw)>0: type,stream=ll.scrape_url("jw",jw[0],defs.domain) elif len(worldspor)>0: type,stream=ll.scrape_url("worldspor",worldspor[0],defs.domain) elif len(micast): type,stream=ll.scrape_url("micast",micast[0],purl) elif len(mips)>0: channel=mips[0][0] e=mips[0][1] script=mips[0][2] type,stream=ll.scrape_url("mips",channel,e,script,defs.domain) elif len(weplayer)>0: id,w,h=weplayer[0] type,stream=ll.scrape_url("weplayer",id,defs.domain,w,h) elif len(weplayer2)>0: id,w,h=weplayer2[0] type,stream=ll.scrape_url("weplayer",id,defs.domain,w,h) elif len(playerhd)>0: domain,id=playerhd[0] type,stream=ll.scrape_url("playerhd",domain,id,purl) elif len(sostart)>0: type,stream=ll.scrape_url("sostart",sostart[0],purl) else: type="ERROR: WEBSPOR | Can't detect streaming service type" stream = "" if "ERROR:" in type: bt.notify(bt.getliprop(li,"name"),type) bt.setliprop(li,"status",defs.notifications["orange"]%type) bt.setliprop(li,"last_check",time.time()) return None else: return stream