def get_page(*args,**kwargs):
	last=prefs.get("anidb","lasttime")
	if "cachetime" in kwargs:
		ulhttp=kwargs.pop("cachetime")
	if last == {}:last=time.time()
	comid=md5.md5("http"+str(kwargs.get("query",{}))).hexdigest()
	cf=os.path.join(ump.defs.addon_ddir,cd,comid+".html")
	if os.path.exists(cf) and (time.time()-os.path.getmtime(cf)<ulhttp):
		f=open(cf)
		res=unicode(f.read().decode(encoding))
		f.close()
	else:
		while True:
			since=time.time()-last
			if since>lthttp:
				res=ump.get_page(*args,**kwargs)
				f=open(cf,"w")
				f.write(res.encode(encoding))
				f.close()
				prefs.set("anidb","lasttime",time.time())
				break
			else:
				xbmc.sleep(100)
				percent=int(since/lthttp*100)
				ump.dialogpg.update(percent,"Waiting to Cache from Anidb Server for %s"%args[0])	
	return res
Exemplo n.º 2
0
def get_page(*args, **kwargs):
    last = prefs.get("anidb", "lasttime")
    if "cachetime" in kwargs:
        ulhttp = kwargs.pop("cachetime")
    if last == {}: last = time.time()
    comid = md5.md5("http" + str(kwargs.get("query", {}))).hexdigest()
    cf = os.path.join(ump.defs.addon_ddir, cd, comid + ".html")
    if os.path.exists(cf) and (time.time() - os.path.getmtime(cf) < ulhttp):
        f = open(cf)
        res = unicode(f.read().decode(encoding))
        f.close()
    else:
        while True:
            since = time.time() - last
            if since > lthttp:
                res = ump.get_page(*args, **kwargs)
                f = open(cf, "w")
                f.write(res.encode(encoding))
                f.close()
                prefs.set("anidb", "lasttime", time.time())
                break
            else:
                xbmc.sleep(100)
                percent = int(since / lthttp * 100)
                ump.dialogpg.update(
                    percent,
                    "Waiting to Cache from Anidb Server for %s" % args[0])
    return res
def command(request,args={}):
	last=prefs.get("anidb","lasttime")
	if last == {}:last=time.time()
	comid=request
	for arg in args:
		comid+="_"+arg+"_"+args[arg]
	cf=os.path.join(ump.defs.addon_ddir,cd,comid)
	if (os.path.exists(cf+".xml") and time.time()-os.path.getmtime(cf+".xml")<ul):
		xml=dom.read(cf+".xml")
	elif os.path.exists(cf+"_perm.xml"):
		xml=dom.read(cf+"_perm.xml")
	else:
		while True:
			since=time.time()-last
			if since>lt:
				query={"request":request,"client":cid,"clientver":cver,"protover":pver}
				query.update(args)
				res=ump.get_page(apiu,encoding,query=query,throttle=False)
				prefs.set("anidb","lasttime",time.time())
				xmlstr=minidom.parseString(res.encode(encoding))
				#check if anime ended, if ended store permanently
				sd=re.findall("<startdate>(.*?)</startdate>",res)
				ed=re.findall("<enddate>(.*?)</enddate>",res)
				if len(ed) and len(sd) and parser.parse(ed[0])<datetime.datetime.now() and parser.parse(sd[0])<parser.parse(ed[0]):
					cf=cf+"_perm.xml"
				else:
					cf=cf+".xml"
				dom.write(cf,xmlstr)
				xml=dom.read(cf)
				break
			else:
				xbmc.sleep(100)
				percent=int(since/lt*100)
				ump.dialogpg.update(percent,"Waiting to Cache from Anidb Server for %s:%s"%(request,str(args)[1:-1]))
	return xml
Exemplo n.º 4
0
	def get_keyboard(self,*args):
		if self.refreshing:
			return True,prefs.get("play","keyboard") 
		kb = xbmc.Keyboard(*args)
		kb.setDefault("")
		kb.setHiddenInput(False)
		if not self.backwards.abortRequested():
			kb.doModal()
		if self.backwards.abortRequested():
			self.dialogpg.close()
			sys.exit()
		text=kb.getText()
		prefs.set("play","keyboard",json.dumps(text))
		if kb.isConfirmed():
			self.stat.query(search=text)
		return kb.isConfirmed(),text
Exemplo n.º 5
0
def command(request, args={}):
    last = prefs.get("anidb", "lasttime")
    if last == {}: last = time.time()
    comid = request
    for arg in args:
        comid += "_" + arg + "_" + args[arg]
    cf = os.path.join(ump.defs.addon_ddir, cd, comid)
    if (os.path.exists(cf + ".xml")
            and time.time() - os.path.getmtime(cf + ".xml") < ul):
        xml = dom.read(cf + ".xml")
    elif os.path.exists(cf + "_perm.xml"):
        xml = dom.read(cf + "_perm.xml")
    else:
        while True:
            since = time.time() - last
            if since > lt:
                query = {
                    "request": request,
                    "client": cid,
                    "clientver": cver,
                    "protover": pver
                }
                query.update(args)
                res = ump.get_page(apiu, encoding, query=query, throttle=False)
                prefs.set("anidb", "lasttime", time.time())
                xmlstr = minidom.parseString(res.encode(encoding))
                #check if anime ended, if ended store permanently
                sd = re.findall("<startdate>(.*?)</startdate>", res)
                ed = re.findall("<enddate>(.*?)</enddate>", res)
                if len(ed) and len(sd) and parser.parse(
                        ed[0]) < datetime.datetime.now() and parser.parse(
                            sd[0]) < parser.parse(ed[0]):
                    cf = cf + "_perm.xml"
                else:
                    cf = cf + ".xml"
                dom.write(cf, xmlstr)
                xml = dom.read(cf)
                break
            else:
                xbmc.sleep(100)
                percent = int(since / lt * 100)
                ump.dialogpg.update(
                    percent, "Waiting to Cache from Anidb Server for %s:%s" %
                    (request, str(args)[1:-1]))
    return xml
Exemplo n.º 6
0
	def _do_container(self):
		items=[]
		mediatypes={}
		if len(self.index_items):
			for u,li,isfolder,adddef,coms,remold,mediatype in self.index_items:
				if not mediatype in mediatypes: mediatypes[mediatype]=1
				else: mediatypes[mediatype]+=1
				items.append((u,li,isfolder))
				if adddef:
					mcc=self.defs.media_to_cc[mediatype]
					coms.append(('Set current view \"default\" for %s'%mcc,"RunScript(%s,setview,%s,%s)"%(os.path.join(defs.addon_dir,"lib","ump","script.py"),self.content_type,mcc)))
					li.addContextMenuItems(coms,remold)
			xbmcplugin.addDirectoryItems(self.handle,items,len(items))
		else:
			return
		v=list(mediatypes.values())
	 	k=list(mediatypes.keys())
	 	self.container_mediatype=k[v.index(max(v))]
	 	content_cat= self.defs.media_to_cc[self.container_mediatype]
	 	xbmcplugin.setContent(self.handle, content_cat)
	 	xbmcplugin.endOfDirectory(self.handle,cacheToDisc=False,updateListing=False,succeeded=True)
		wmode=addon.getSetting("view_"+content_cat).lower()
		if wmode=="":wmode="default"
		if not wmode == "default":
			mode=self.defs.VIEW_MODES[wmode].get(xbmc.getSkinDir(),None)
		else:
			mode=prefs.get("pref_views",content_cat,xbmc.getSkinDir())
			if mode=={}: mode=None
		if not mode is None:
			for i in range(0, 10*20):
				if self.terminate or self.backwards.abortRequested():
					break
				if self.content_type==self.defs.CT_AUDIO and content_cat in ["songs","movies","artists","albums"]:
					#issue #38
					xbmc.sleep(300)
					xbmc.executebuiltin('Container.SetViewMode(%d)' % mode)
					break
				elif xbmc.getCondVisibility('Container.Content(%s)' % content_cat):
					xbmc.executebuiltin('Container.SetViewMode(%d)' % mode)
					break
				xbmc.sleep(100)
Exemplo n.º 7
0
	def __init__(self,pt=False):
		if not os.path.exists(defs.addon_ddir):
			os.makedirs(defs.addon_ddir)
		self.pub=[]
		self.index_items=[]
		self.backwards=teamkodi.backwards()
		self.settings={}
		self.buffermode=buffering.get()
		self.log=""
		self.handle = int(sys.argv[1])
		self.ws_limit=False #web search limit
		self.defs=defs
		if self.backwards.abortRequested():sys.exit()
		self.window = ui.listwindow('select.xml', defs.addon_dir,'Default', '720p',ump=self)
		self.iwindow = ui.imagewindow('picture.xml', defs.addon_dir,"Default","720p")
		self.urlval_en=True
		self.urlval_tout=30
		self.urlval_d_size={self.defs.CT_VIDEO:1000000,self.defs.CT_AUDIO:10000,self.defs.CT_IMAGE:200}
		self.urlval_d_tout=1.5
		try:self.tm_conc=int(float(addon.getSetting("conc")))
		except:self.tm_conc=10
		self.player=None
		self.cfagents=prefs.get("cfagents")
		self.cflocks={}
		self.mirrors=[]
		self.terminate=False
		self.loaded_uprv={}
		self.checked_uids={"video":{},"audio":{},"image":{}}
		self.pt=pt
		socket.socket = proxy.getsocket()
		policy=cookielib.DefaultCookiePolicy(rfc2965=True, rfc2109_as_netscape=True, strict_rfc2965_unverifiable=False)
		self.cj=cookielib.LWPCookieJar(os.path.join(defs.addon_ddir, "cookie"))
		self.cj.set_policy(policy)
		self.dialog=xbmcgui.Dialog()
		if os.path.exists(defs.addon_cookfile):
			try:
				self.cj.load()
			except cookielib.LoadError:
				pass
			except IOError:
				pass
		if addon.getSetting("verifyssl").lower()=="false":
			self.opener = urllib2.build_opener(http.HTTPErrorProcessor,urllib2.HTTPCookieProcessor(self.cj),http.HTTPSHandler)
		else:
			self.opener = urllib2.build_opener(http.HTTPErrorProcessor,urllib2.HTTPCookieProcessor(self.cj))	
		if addon.getSetting("overrideua")=="true":
			self.ua=addon.getSetting("useragent")
		else:
			from ump import useragents
			self.ua=choice(useragents.all)
		self.opener.addheaders = [('User-agent', self.ua)]
		self.tunnel=webtunnel.tunnel(self.opener)
		query=sys.argv[2][1:]
		result=parse_qs(query)
		[self.module]= result.get('module', ["ump"])
		[self.page]= result.get('page', ["root"])
		[args]= result.get('args', ["e30="])
		try:
			self.args=json.loads(args.decode("base64"))
		except:
			try:
				self.args=json.loads(args) # old url formatting
			except:
				self._wronguri()
		for keep in ["info","art","pub"]:
			if keep in ["pub"]:default="W10="
			else: default= "e30="
			[lst]=result.get(keep, [default])
			try:
				setattr(self,keep,json.loads(lst.decode("base64")))
			except:
				try:
					setattr(self,keep,json.loads(lst))
				except:
					self._wronguri()
		[self.content_type]= result.get('content_type', ["ump"])
		self.loadable_uprv=providers.find(self.content_type,"url")
		self.stats=stats.stats()
		self.throttle=throttle.throttle(self.defs.addon_tdir)

		if prefs.get("play","flag"):
			self.refreshing=True
			prefs.set("play","flag",False)
		else:
			self.refreshing=False
		self.dialogpg=teamkodi.backwards.DialogProgressBG()
		self.dialogpg.create("UMP")
		self.tm=task.manager(self.dialogpg,self.tm_conc)
		self.stat=clicky.clicky(self)
		if not self.page=="urlselect":
			self.stat.query()
		self.identifier=identifier.identifier()
		self.container_mediatype=defs.MT_NONE
		self.dialogpg.update(100,"UMP %s:%s:%s"%(self.content_type,self.module,self.page))