def list_items(channels,ui): time.sleep(1) k=0 for cnum,channel in channels.iteritems(): k+=1 li=xbmcgui.ListItem(iconImage="DefaultFolder.png", thumbnailImage="DefaultFolder.png") bt.setliprops(li,channel) updatetitle(li) bt.setliprop(li,"icon0","") bt.setliprop(li,"icon1","") ui.addListItem(li) ui.progress.setPercent(100*k/len(channels.keys()))
def onAction(self, action): bui.sportsui.onAction(self,action) return None li=self.lst.getSelectedItem() if li is None: return None seps=["vs","/","-","v.s","v.s."] for icon in [0,1]: img=bt.getliprop(li,"icon%d"%icon) if isinstance(img,str) and img.startswith("http"): continue for sep in seps: name=bt.getliprop(li,"name") if ":" in name: name=name.split(":")[-1] ops=name.split(sep) if len(ops)==2: img=bt.web_search("images","%s logo filetype:png "%ops[icon]) if len(img)>0: bt.setliprop(li,"icon%d"%icon,str(img[0]))
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 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