threading update by srg70
parent
6b97d52b7e
commit
65c82894b2
|
@ -223,34 +223,43 @@ class BTClientPlayer(xbmc.Player):
|
||||||
# self.torrent.continueSession(ind)
|
# self.torrent.continueSession(ind)
|
||||||
|
|
||||||
def buffer(self):
|
def buffer(self):
|
||||||
#iterator = 0
|
iterator = 0
|
||||||
progressBar = xbmcgui.DialogProgress()
|
progressBar = xbmcgui.DialogProgress()
|
||||||
progressBar.create(self.localize('Please Wait') + str(' [%s]' % str(self.lt.version)),
|
progressBar.create(self.localize('Please Wait') + str(' [%s]' % str(self.lt.version)),
|
||||||
self.localize('Seeds searching.'))
|
self.localize('Seeds searching.'))
|
||||||
while not self.c.is_file_ready: #iterator < 100:#or not self.torrent.is_playble()
|
while iterator < 100 or not self.c.is_file_ready:# not self.c.is_file_ready
|
||||||
|
iterator = 0
|
||||||
|
ready_list=[]
|
||||||
status = self.c.get_normalized_status()
|
status = self.c.get_normalized_status()
|
||||||
iterator = int(status['progress'] * 10000)
|
conditions=[status['state'] in ['downloading', 'finished', 'seeding'], status['desired_rate'] > 0,
|
||||||
if iterator > 99: iterator = 99
|
status['progress'] > 0,
|
||||||
|
status['desired_rate'] > 0 and (status['download_rate'] > status['desired_rate'] or
|
||||||
|
status['download_rate'] * status['progress'] * 100 > status['desired_rate'])]
|
||||||
|
for cond in conditions:
|
||||||
|
if cond:
|
||||||
|
ready_list.append(True)
|
||||||
|
iterator+=100/len(conditions)
|
||||||
|
else:
|
||||||
|
ready_list.append(False)
|
||||||
|
|
||||||
|
speedsText = '%s: %s Mbit/s %s %s: %s Mbit/s' % (self.localize('Bitrate'), str(int(status['desired_rate'] * 8 / (1024 * 1024))) if status['desired_rate'] else 0,
|
||||||
|
'[COLOR=green]>[/COLOR]' if ready_list[3] else '[COLOR=red]<[/COLOR]',
|
||||||
|
self.localize('Download speed'),str(status['download_rate'] * 8 / 1000000))
|
||||||
|
|
||||||
if status['state'] in ['queued','checking','checking fastresume'] or (status['progress'] == 0 and status['num_pieces'] > 0):
|
if status['state'] in ['queued','checking','checking fastresume'] or (status['progress'] == 0 and status['num_pieces'] > 0):
|
||||||
progressBar.update(iterator, self.localize('Checking preloaded files...'), ' ', ' ')
|
progressBar.update(iterator, self.localize('Checking preloaded files...'), speedsText, ' ')
|
||||||
elif status['state'] == 'downloading':
|
|
||||||
dialogText = self.localize('Preloaded: ') + str(status['downloaded'] / 1024 / 1024) + ' MB / ' + str(
|
elif status['state'] in ['downloading', 'finished', 'seeding']:
|
||||||
status['total_size'] / 1024 / 1024) + ' MB'
|
dialogText = self.localize('Preloaded: ') + '%s MB / %s MB' % \
|
||||||
peersText = ' [%s: %s; %s: %s]' % (
|
(str(status['downloaded'] / 1024 / 1024), str(status['total_size'] / 1024 / 1024))
|
||||||
self.localize('Seeds'), str(status['seeds_connected']), self.localize('Peers'),
|
peersText = '[%s: %s; %s: %s]' % (self.localize('Seeds'), str(status['seeds_connected']), self.localize('Peers'),
|
||||||
str(status['peers_connected']),)
|
str(status['peers_connected']),)
|
||||||
speedsText = '%s: %s Mbit/s; %s: %s Mbit/s' % (
|
progressBar.update(iterator, peersText, speedsText, dialogText,
|
||||||
self.localize('Downloading'), str(status['download_rate'] * 8 / 1000000),
|
)
|
||||||
self.localize('Uploading'), str(status['upload_rate'] * 8 / 1000000))
|
|
||||||
#if self.debug:
|
|
||||||
# peersText=peersText + ' ' + self.torrent.get_debug_info('dht_state')
|
|
||||||
# dialogText=dialogText.replace(self.localize('Preloaded: '),'') + ' ' + self.torrent.get_debug_info('trackers_sum')
|
|
||||||
progressBar.update(iterator, self.localize('Seeds searching.') + peersText, dialogText,
|
|
||||||
speedsText)
|
|
||||||
else:
|
else:
|
||||||
progressBar.update(iterator, self.localize('UNKNOWN STATUS'), ' ', ' ')
|
progressBar.update(iterator, self.localize('UNKNOWN STATUS'), ' ', ' ')
|
||||||
if progressBar.iscanceled():
|
if progressBar.iscanceled():
|
||||||
self.c.close()
|
self.on_exit()
|
||||||
break
|
break
|
||||||
xbmc.sleep(1000)
|
xbmc.sleep(1000)
|
||||||
progressBar.update(0)
|
progressBar.update(0)
|
||||||
|
@ -291,6 +300,7 @@ class BTClientPlayer(xbmc.Player):
|
||||||
self.basename = label
|
self.basename = label
|
||||||
#self.seeding_run = False
|
#self.seeding_run = False
|
||||||
listitem = xbmcgui.ListItem(label)
|
listitem = xbmcgui.ListItem(label)
|
||||||
|
info={}
|
||||||
|
|
||||||
#if self.subs_dl:
|
#if self.subs_dl:
|
||||||
# self.setup_subs(label, path)
|
# self.setup_subs(label, path)
|
||||||
|
@ -306,16 +316,15 @@ class BTClientPlayer(xbmc.Player):
|
||||||
title, int(seasonId), int(self.episodeId), self.basename.split('.')[-1], self.basename)
|
title, int(seasonId), int(self.episodeId), self.basename.split('.')[-1], self.basename)
|
||||||
|
|
||||||
if seasonId and self.episodeId and label and title:
|
if seasonId and self.episodeId and label and title:
|
||||||
listitem = xbmcgui.ListItem(label)
|
info={'title': label,
|
||||||
|
|
||||||
listitem.setInfo(type='video', infoLabels={'title': label,
|
|
||||||
'episode': int(self.episodeId),
|
'episode': int(self.episodeId),
|
||||||
'season': int(seasonId),
|
'season': int(seasonId),
|
||||||
'tvshowtitle': title})
|
'tvshowtitle': title}
|
||||||
except:
|
except:
|
||||||
log('[BTClientPlayer] Operation INFO failed!')
|
log('[BTClientPlayer] Operation INFO failed!')
|
||||||
|
|
||||||
thumbnail = self.get("thumbnail")
|
thumbnail = self.get("thumbnail")
|
||||||
|
listitem.setInfo(type='Video', infoLabels=info)
|
||||||
if thumbnail:
|
if thumbnail:
|
||||||
listitem.setThumbnailImage(urllib.unquote_plus(thumbnail))
|
listitem.setThumbnailImage(urllib.unquote_plus(thumbnail))
|
||||||
self.display_name = label
|
self.display_name = label
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import abc
|
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
import cookielib
|
import cookielib
|
||||||
|
@ -38,8 +37,6 @@ from functions import log, debug
|
||||||
|
|
||||||
|
|
||||||
class SearcherABC:
|
class SearcherABC:
|
||||||
__metaclass__ = abc.ABCMeta
|
|
||||||
|
|
||||||
searchIcon = '/icons/video.png'
|
searchIcon = '/icons/video.png'
|
||||||
sourceWeight = 1
|
sourceWeight = 1
|
||||||
cookieJar = None
|
cookieJar = None
|
||||||
|
@ -56,7 +53,6 @@ class SearcherABC:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
print '!!!!!!!!!!!!!!!!!! BORN '+self.__class__.__name__
|
print '!!!!!!!!!!!!!!!!!! BORN '+self.__class__.__name__
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def search(self, keyword):
|
def search(self, keyword):
|
||||||
'''
|
'''
|
||||||
Retrieve keyword from the input and return a list of tuples:
|
Retrieve keyword from the input and return a list of tuples:
|
||||||
|
@ -70,7 +66,6 @@ class SearcherABC:
|
||||||
'''
|
'''
|
||||||
return
|
return
|
||||||
|
|
||||||
@abc.abstractproperty
|
|
||||||
def isMagnetLinkSource(self):
|
def isMagnetLinkSource(self):
|
||||||
return 'Should never see this'
|
return 'Should never see this'
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import gc
|
||||||
import xbmcaddon
|
import xbmcaddon
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,3 +38,7 @@ if (__name__ == "__main__" ):
|
||||||
else:
|
else:
|
||||||
params = core.getParameters(sys.argv[2])
|
params = core.getParameters(sys.argv[2])
|
||||||
core.executeAction(params)
|
core.executeAction(params)
|
||||||
|
del core
|
||||||
|
|
||||||
|
collected = gc.collect()
|
||||||
|
print "Garbage collector: collected %d objects." % (collected)
|
33
functions.py
33
functions.py
|
@ -1066,13 +1066,14 @@ class Searchers():
|
||||||
def searchWithSearcher(self, keyword, searcher):
|
def searchWithSearcher(self, keyword, searcher):
|
||||||
import traceback
|
import traceback
|
||||||
filesList = []
|
filesList = []
|
||||||
slist = Searchers().list()
|
slist = self.list()
|
||||||
if slist[searcher]['path'] not in sys.path:
|
if slist[searcher]['path'] not in sys.path:
|
||||||
sys.path.insert(0, slist[searcher]['path'])
|
sys.path.insert(0, slist[searcher]['path'])
|
||||||
print 'Added %s in sys.path' % (slist[searcher]['path'])
|
print 'Added %s in sys.path' % (slist[searcher]['path'])
|
||||||
try:
|
try:
|
||||||
searcherObject = getattr(__import__(searcher), searcher)()
|
searcherObject = getattr(__import__(searcher), searcher)
|
||||||
filesList = searcherObject.search(keyword)
|
filesList = searcherObject().search(keyword)
|
||||||
|
del searcherObject
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print 'Unable to use searcher: ' + searcher + ' at ' + __plugin__ + ' searchWithSearcher(). Exception: ' + str(
|
print 'Unable to use searcher: ' + searcher + ' at ' + __plugin__ + ' searchWithSearcher(). Exception: ' + str(
|
||||||
e)
|
e)
|
||||||
|
@ -1111,9 +1112,9 @@ class Searchers():
|
||||||
def search(url, searchersList, isApi=None):
|
def search(url, searchersList, isApi=None):
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
try:
|
try:
|
||||||
from Queue import Queue
|
from Queue import Queue, Empty
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from queue import Queue
|
from queue import Queue, Empty
|
||||||
|
|
||||||
num_threads=__settings__.getSetting('num_threads')
|
num_threads=__settings__.getSetting('num_threads')
|
||||||
if num_threads and int(num_threads)>0:
|
if num_threads and int(num_threads)>0:
|
||||||
|
@ -1124,14 +1125,17 @@ def search(url, searchersList, isApi=None):
|
||||||
result = {}
|
result = {}
|
||||||
iterator, filesList, left_searchers = 0, [], []
|
iterator, filesList, left_searchers = 0, [], []
|
||||||
timeout_multi=int(sys.modules["__main__"].__settings__.getSetting("timeout"))
|
timeout_multi=int(sys.modules["__main__"].__settings__.getSetting("timeout"))
|
||||||
wait_time=10+(10*timeout_multi)
|
|
||||||
left_searchers.extend(searchersList)
|
left_searchers.extend(searchersList)
|
||||||
if not isApi:
|
if not isApi:
|
||||||
progressBar = xbmcgui.DialogProgress()
|
progressBar = xbmcgui.DialogProgress()
|
||||||
progressBar.create(Localization.localize('Please Wait'), Localization.localize('Materials are loading now.'))
|
progressBar.create(Localization.localize('Please Wait'), Localization.localize('Materials are loading now.'))
|
||||||
|
|
||||||
|
class CleanExit:
|
||||||
|
pass
|
||||||
|
|
||||||
def search_one(i, q):
|
def search_one(i, q):
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
if not isApi and progressBar.iscanceled():
|
if not isApi and progressBar.iscanceled():
|
||||||
progressBar.update(0)
|
progressBar.update(0)
|
||||||
progressBar.close()
|
progressBar.close()
|
||||||
|
@ -1139,23 +1143,36 @@ def search(url, searchersList, isApi=None):
|
||||||
iterator=100*int(len(searchersList)-len(left_searchers))/len(searchersList)
|
iterator=100*int(len(searchersList)-len(left_searchers))/len(searchersList)
|
||||||
if not isApi:
|
if not isApi:
|
||||||
progressBar.update(int(iterator), join_list(left_searchers, replace='.py'))
|
progressBar.update(int(iterator), join_list(left_searchers, replace='.py'))
|
||||||
searcherFile = q.get()
|
searcherFile = q.get_nowait()
|
||||||
|
if searcherFile == CleanExit:
|
||||||
|
sys.exit()
|
||||||
searcher=searcherFile.replace('.py','')
|
searcher=searcherFile.replace('.py','')
|
||||||
print "Thread %s: Searching at %s" % (i, searcher)
|
print "Thread %s: Searching at %s" % (i, searcher)
|
||||||
result[searcherFile]=Searchers().searchWithSearcher(url, searcher)
|
result[searcherFile]=Searchers().searchWithSearcher(url, searcher)
|
||||||
left_searchers.remove(searcherFile)
|
left_searchers.remove(searcherFile)
|
||||||
q.task_done()
|
q.task_done()
|
||||||
|
except Empty:
|
||||||
|
pass
|
||||||
|
|
||||||
|
workers=[]
|
||||||
for i in range(num_threads):
|
for i in range(num_threads):
|
||||||
worker = Thread(target=search_one, args=(i, queue))
|
worker = Thread(target=search_one, args=(i, queue))
|
||||||
worker.setDaemon(True)
|
worker.setDaemon(True)
|
||||||
worker.start()
|
worker.start()
|
||||||
|
workers.append(worker)
|
||||||
|
|
||||||
for searcherFile in searchersList:
|
for searcherFile in searchersList:
|
||||||
queue.put(searcherFile, timeout=wait_time)
|
queue.put(searcherFile)
|
||||||
|
|
||||||
print "Main Thread Waiting"
|
print "Main Thread Waiting"
|
||||||
queue.join()
|
queue.join()
|
||||||
|
for i in range(num_threads):
|
||||||
|
queue.put(CleanExit)
|
||||||
|
|
||||||
|
print "Main Thread Waiting for Threads"
|
||||||
|
for w in workers:
|
||||||
|
w.join()
|
||||||
|
|
||||||
print "Done"
|
print "Done"
|
||||||
|
|
||||||
if not isApi:
|
if not isApi:
|
||||||
|
|
Loading…
Reference in New Issue