def get_url_ind(self, index=0, title='', icon=None, thumb=None):
        if self.error: return False
        self.dialog2 = progress.dwprogress()
        self.dialog2.updater(0, language(1004))
        addstr = ''
        if self.mode != 'PID': addstr = ' 0 0 0'
        comm = 'START ' + self.mode + ' ' + self.url + ' ' + str(
            index) + addstr
        self._TSpush(comm)

        while not self.r.got_url and not self.dialog2.ui.isCanceled and not self.r.err:

            if self.r.last_com == 'STATUS':
                try:
                    if self.r.state:
                        self.dialog2.updater(self.r.progress, self.r.state,
                                             self.r.label)
                except:
                    pass
                xbmc.sleep(1000)
        self.dialog2.ui.showCancel = False
        if self.dialog2.ui.isCanceled or self.r.err:
            self.dialog2.close()
            return False
        else:
            self.dialog2.ui.showCancel = False
            self.link = self.r.got_url
            self.dialog2.close()
            return self.r.got_url
	def get_url_ind(self, index=0, title='', icon=None, thumb=None):
		if self.error: return False
		self.dialog2 = progress.dwprogress()
		self.dialog2.updater(0,language(1004))
		addstr=''
		if self.mode != 'PID': addstr= ' 0 0 0'
		comm='START ' + self.mode + ' ' + self.url + ' ' + str(index) + addstr
		self._TSpush(comm)
		
		while not self.r.got_url and not self.dialog2.ui.isCanceled and not self.r.err:
			
			if self.r.last_com=='STATUS':
				try:
					if self.r.state: self.dialog2.updater(self.r.progress,self.r.state,self.r.label)
				except: pass
				xbmc.sleep(1000)
		self.dialog2.ui.showCancel=False
		if self.dialog2.ui.isCanceled or self.r.err:
			self.dialog2.close()
			return False
		else:
			self.dialog2.ui.showCancel=False
			self.link=self.r.got_url
			self.dialog2.close()
			return self.r.got_url
	def play_url_ind(self, index=0, title='', icon=None, thumb=None):

		if self.cache.lock("TSLock"):
			z=self.cache.set("Mode",'play')
			self.cache.unlock("TSLock")
		if not self.error:
			self.dialog2 = progress.dwprogress()
			self.dialog2.updater(0,language(1004))
			
			spons=''
			if self.mode!='PID': spons=' 0 0 0'
			comm='START '+self.mode+ ' ' + self.url + ' '+ str(index) + spons
			self._TSpush(comm)

			while not self.r.got_url and not self.dialog2.ui.isCanceled and not self.r.err:
				
				if self.r.last_com=='STATUS':
					try:
						if self.r.state: self.dialog2.updater(self.r.progress,self.r.state,self.r.label)
					except: pass
					xbmc.sleep(1000)
			self.dialog2.ui.showCancel=False
			if self.dialog2.ui.isCanceled or self.r.err: 
				self.dialog2.close()
				return False
			else:
				self.dialog2.ui.showCancel=False
				self.link=self.r.got_url
				self.dialog2.close()
				self.title=title
				lit= xbmcgui.ListItem(title, iconImage = thumb, thumbnailImage =thumb)
				self.play(self.r.got_url,lit)
				self.r.got_url=None
				self.loop()
				return 'Ok'
    def load_torrent(self, torrent, mode, host=server_ip, port=aceport):

        host = server_ip
        port = aceport
        self.ts_init()
        if self.error: return False
        if self.cache.lock("TSLock"):
            z = self.cache.set("Mode", 'load')
            self.cache.unlock("TSLock")
        self.mode = mode
        self.url = torrent
        self.dialog = progress.dwprogress()
        self.dialog.updater(0, language(1001))
        spons = ''
        if mode != 'PID': spons = ' 0 0 0'

        comm = 'LOADASYNC ' + str(random.randint(
            0, 0x7fffffff)) + ' ' + mode + ' ' + torrent + spons
        self._TSpush(comm)

        timeout = self.timeout
        while not self.r.files:
            timeout = timeout - 1
            if timeout == 0: break
            time.sleep(1)
        if timeout == 0:
            self.dialog.updater(100, language(1012))
            xbmc.sleep(2000)
            self.dialog.close()
            return 'Load Failed'
        self.filelist = self.r.files
        self.file_count = self.r.count
        self.files = {}
        self.dialog.updater(89)
        if self.file_count > 1:
            flist = json.loads(self.filelist)
            for list in flist['files']:
                self.files[urllib.unquote_plus(urllib.quote(
                    list[0]))] = list[1]
        elif self.file_count == 1:
            flist = json.loads(self.filelist)
            list = flist['files'][0]
            self.files[urllib.unquote_plus(urllib.quote(list[0]))] = list[1]
        self.dialog.close()

        return 'Ok'
	def load_torrent(self, torrent, mode, host=server_ip, port=aceport ):

		host=server_ip
		port=aceport
		self.ts_init()
		if self.error: return False
		if self.cache.lock("TSLock"):
			z=self.cache.set("Mode",'load')
			self.cache.unlock("TSLock")
		self.mode=mode
		self.url=torrent
		self.dialog = progress.dwprogress()
		self.dialog.updater(0,language(1001))
		spons=''
		if mode!='PID': spons=' 0 0 0'
		
		comm='LOADASYNC '+ str(random.randint(0, 0x7fffffff)) +' '+mode+' ' + torrent + spons
		self._TSpush(comm)
	
		timeout=self.timeout
		while not self.r.files:
			timeout=timeout-1
			if timeout==0: break
			time.sleep(1)
		if timeout==0: 
			self.dialog.updater(100,language(1012))
			xbmc.sleep(2000)
			self.dialog.close()
			return 'Load Failed'	
		self.filelist=self.r.files
		self.file_count = self.r.count
		self.files={}
		self.dialog.updater(89)
		if self.file_count>1:
			flist=json.loads(self.filelist)
			for list in flist['files']:
				self.files[urllib.unquote_plus(urllib.quote(list[0]))]=list[1]
		elif self.file_count==1:
			flist=json.loads(self.filelist)
			list=flist['files'][0]
			self.files[urllib.unquote_plus(urllib.quote(list[0]))]=list[1]
		self.dialog.close()

		return 'Ok'
    def play_url_ind(self, index=0, title='', icon=None, thumb=None):

        if self.cache.lock("TSLock"):
            z = self.cache.set("Mode", 'play')
            self.cache.unlock("TSLock")
        if not self.error:
            self.dialog2 = progress.dwprogress()
            self.dialog2.updater(0, language(1004))

            spons = ''
            if self.mode != 'PID': spons = ' 0 0 0'
            comm = 'START ' + self.mode + ' ' + self.url + ' ' + str(
                index) + spons
            self._TSpush(comm)

            while not self.r.got_url and not self.dialog2.ui.isCanceled and not self.r.err:

                if self.r.last_com == 'STATUS':
                    try:
                        if self.r.state:
                            self.dialog2.updater(self.r.progress, self.r.state,
                                                 self.r.label)
                    except:
                        pass
                    xbmc.sleep(1000)
            self.dialog2.ui.showCancel = False
            if self.dialog2.ui.isCanceled or self.r.err:
                self.dialog2.close()
                return False
            else:
                self.dialog2.ui.showCancel = False
                self.link = self.r.got_url
                self.dialog2.close()
                self.title = title
                lit = xbmcgui.ListItem(title,
                                       iconImage=thumb,
                                       thumbnailImage=thumb)
                self.play(self.r.got_url, lit)
                self.r.got_url = None
                self.loop()
                return 'Ok'
    def loop(self):
        visible = False
        pos = [0, 25, 50, 75, 100]
        while self.active or self.r.ad:
            #print self.r.ad
            if self.r.ad and not self.active:
                self.dialog2 = progress.dwprogress()
                self.dialog2.updater(0, language(1004))

                while not self.r.got_url and not self.dialog2.ui.isCanceled and not self.r.err:

                    if self.r.last_com == 'STATUS':
                        try:
                            if self.r.state:
                                self.dialog2.updater(self.r.progress,
                                                     self.r.state,
                                                     self.r.label)
                        except:
                            pass
                        xbmc.sleep(1000)
                self.dialog2.ui.showCancel = False
                if self.dialog2.ui.isCanceled or self.r.err:
                    self.dialog2.close()
                    break
                self.dialog2.close()
                lit = xbmcgui.ListItem(self.title)
                self.play(self.r.got_url, lit)
                self.r.got_url = None
                self.active = True
                pos = [0, 25, 50, 75, 100]
            if self.isPlaying() and not self.isStream:
                if self.getTotalTime() > 0:
                    cpos = int((1 - (self.getTotalTime() - self.getTime()) /
                                self.getTotalTime()) * 100)
                else:
                    cpos = 0
                if cpos in pos:
                    #print cpos
                    pos.remove(cpos)
                    comm = 'PLAYBACK ' + self.link.replace('\r', '').replace(
                        '\n', '') + ' %s' % cpos
                    self._TSpush(comm)
            if pausable:
                if self.r.pause == 1 and not self.paused:
                    self.pause()
                    self.r.pause = None
                    xbmc.sleep(1000)
                if self.r.pause == 0 and self.paused:
                    self.pause()
                    self.r.pause = None
            else:
                if autobuf:
                    if self.r.status == 3 and not self.paused:
                        self.dialog = progress.dwprogress()
                        self.dialog.ui.showCancel = False
                        self.dialog.updater(self.r.progress, self.r.state,
                                            self.r.label)
                        visible = True
                    elif visible and not self.paused:
                        self.dialog.close()
                        visible = False
            if self.paused:
                if not visible:
                    self.dialog = progress.dwprogress()
                    self.dialog.ui.showCancel = False
                    self.dialog.updater(self.r.progress, self.r.state,
                                        self.r.label)
                    visible = True
                else:
                    self.dialog.updater(self.r.progress, self.r.state,
                                        self.r.label)
            elif visible:
                self.dialog.close()
                visible = False
            #if self.isPlaying(): print self.getTime()
            xbmc.sleep(1000)
	def loop(self):
		visible=False
		pos=[0,25,50,75,100]
		while self.active or self.r.ad:
			#print self.r.ad
			if self.r.ad and not self.active:
				self.dialog2 = progress.dwprogress()
				self.dialog2.updater(0,language(1004))
				
				while not self.r.got_url and not self.dialog2.ui.isCanceled and not self.r.err:
					
					if self.r.last_com=='STATUS':
						try:
							if self.r.state: self.dialog2.updater(self.r.progress,self.r.state,self.r.label)
						except: pass
						xbmc.sleep(1000)
				self.dialog2.ui.showCancel=False
				if self.dialog2.ui.isCanceled or self.r.err: 
					self.dialog2.close()
					break
				self.dialog2.close()
				lit= xbmcgui.ListItem(self.title)
				self.play(self.r.got_url,lit)
				self.r.got_url=None
				self.active=True
				pos=[0,25,50,75,100]
			if self.isPlaying() and not self.isStream:
				if self.getTotalTime()>0: cpos= int((1-(self.getTotalTime()-self.getTime())/self.getTotalTime())*100)
				else: cpos=0
				if cpos in pos: 
					#print cpos
					pos.remove(cpos)
					comm='PLAYBACK '+self.link.replace('\r','').replace('\n','')+' %s'%cpos
					self._TSpush(comm)
			if pausable:
				if self.r.pause==1 and not self.paused:
					self.pause()
					self.r.pause=None
					xbmc.sleep(1000)
				if self.r.pause==0 and self.paused:
					self.pause()
					self.r.pause=None
			else:
				if autobuf:
					if self.r.status==3 and not self.paused:
						self.dialog = progress.dwprogress()
						self.dialog.ui.showCancel=False
						self.dialog.updater(self.r.progress,self.r.state,self.r.label)
						visible=True
					elif visible and not self.paused:
						self.dialog.close()
						visible=False
			if self.paused: 
				if not visible: 
					self.dialog = progress.dwprogress()
					self.dialog.ui.showCancel=False
					self.dialog.updater(self.r.progress,self.r.state,self.r.label)
					visible=True
				else: self.dialog.updater(self.r.progress,self.r.state,self.r.label)
			elif visible:
				self.dialog.close()
				visible=False
			#if self.isPlaying(): print self.getTime()
			xbmc.sleep(1000)