debug update

pull/1/head
DiMartinoXBMC 2015-07-24 20:22:30 +03:00
parent c807d5ffc2
commit 6a055fbe98
3 changed files with 67 additions and 30 deletions

View File

@ -30,10 +30,9 @@ import xbmc
import xbmcgui import xbmcgui
import xbmcvfs import xbmcvfs
import Localization import Localization
from functions import file_decode, file_encode, isSubtitle, DownloadDB, log, debug from functions import file_encode, isSubtitle, DownloadDB, log, debug
from platform_pulsar import get_platform from platform_pulsar import get_platform
class Libtorrent: class Libtorrent:
torrentFile = None torrentFile = None
magnetLink = None magnetLink = None
@ -74,7 +73,8 @@ class Libtorrent:
self.torrentFilesPath = os.path.join(self.storageDirectory, torrentFilesDirectory) + os.sep self.torrentFilesPath = os.path.join(self.storageDirectory, torrentFilesDirectory) + os.sep
if xbmcvfs.exists(torrentFile): if xbmcvfs.exists(torrentFile):
self.torrentFile = torrentFile self.torrentFile = torrentFile
self.torrentFileInfo = self.lt.torrent_info(file_decode(self.torrentFile)) e=self.lt.bdecode(xbmcvfs.File(self.torrentFile,'rb').read())
self.torrentFileInfo = self.lt.torrent_info(e)
elif re.match("^magnet\:.+$", torrentFile): elif re.match("^magnet\:.+$", torrentFile):
self.magnetLink = torrentFile self.magnetLink = torrentFile
@ -91,7 +91,7 @@ class Libtorrent:
torrentUrl) + '.torrent' torrentUrl) + '.torrent'
try: try:
if not re.match("^http\:.+$", torrentUrl): if not re.match("^http\:.+$", torrentUrl):
content = xbmcvfs.File(file_decode(torrentUrl), "rb").read() content = xbmcvfs.File(torrentUrl, "rb").read()
else: else:
request = urllib2.Request(torrentUrl) request = urllib2.Request(torrentUrl)
request.add_header('Referer', torrentUrl) request.add_header('Referer', torrentUrl)
@ -113,7 +113,8 @@ class Libtorrent:
return return
if xbmcvfs.exists(torrentFile): if xbmcvfs.exists(torrentFile):
try: try:
self.torrentFileInfo = self.lt.torrent_info(file_decode(torrentFile)) e=self.lt.bdecode(xbmcvfs.File(torrentFile,'rb').read())
self.torrentFileInfo = self.lt.torrent_info(e)
except Exception, e: except Exception, e:
print 'Exception: ' + str(e) print 'Exception: ' + str(e)
xbmcvfs.delete(torrentFile) xbmcvfs.delete(torrentFile)
@ -134,7 +135,8 @@ class Libtorrent:
return return
self.torrentFile = newFile self.torrentFile = newFile
if not self.torrentFileInfo: if not self.torrentFileInfo:
self.torrentFileInfo = self.lt.torrent_info(file_decode(self.torrentFile)) e=self.lt.bdecode(xbmcvfs.File(self.torrentFile,'rb').read())
self.torrentFileInfo = self.lt.torrent_info(e)
return self.torrentFile return self.torrentFile
def getMagnetInfo(self): def getMagnetInfo(self):
@ -177,7 +179,8 @@ class Libtorrent:
torentFileHandler = xbmcvfs.File(self.torrentFile, "w+b") torentFileHandler = xbmcvfs.File(self.torrentFile, "w+b")
torentFileHandler.write(self.lt.bencode(torrentFile.generate())) torentFileHandler.write(self.lt.bencode(torrentFile.generate()))
torentFileHandler.close() torentFileHandler.close()
self.torrentFileInfo = self.lt.torrent_info(file_decode(self.torrentFile)) e=self.lt.bdecode(xbmcvfs.File(self.torrentFile,'rb').read())
self.torrentFileInfo = self.lt.torrent_info(e)
except: except:
xbmc.executebuiltin("Notification(%s, %s, 7500)" % (Localization.localize('Error'), Localization.localize( xbmc.executebuiltin("Notification(%s, %s, 7500)" % (Localization.localize('Error'), Localization.localize(
'Can\'t download torrent, probably no seeds available.'))) 'Can\'t download torrent, probably no seeds available.')))
@ -328,17 +331,18 @@ class Libtorrent:
#self.session.add_extension("smart_ban") #self.session.add_extension("smart_ban")
# Session settings # Session settings
#session_settings = self.session.settings() session_settings = self.session.settings()
# #
#session_settings.announce_to_all_tiers = True session_settings.announce_to_all_tiers = True
#session_settings.announce_to_all_trackers = True session_settings.announce_to_all_trackers = True
#session_settings.connection_speed = 100 session_settings.connection_speed = 100
#session_settings.peer_connect_timeout = 2 session_settings.peer_connect_timeout = 2
#session_settings.rate_limit_ip_overhead = True session_settings.rate_limit_ip_overhead = True
#session_settings.request_timeout = 5 session_settings.request_timeout = 1
#session_settings.torrent_connect_boost = 100 session_settings.torrent_connect_boost = 100
session_settings.user_agent = 'uTorrent/3430(40298)'
# #
#self.session.set_settings(session_settings) self.session.set_settings(session_settings)
def encryptSession(self): def encryptSession(self):
# Encryption settings # Encryption settings
@ -359,10 +363,10 @@ class Libtorrent:
if None == self.magnetLink: if None == self.magnetLink:
self.torrentHandle = self.session.add_torrent({'ti': self.torrentFileInfo, self.torrentHandle = self.session.add_torrent({'ti': self.torrentFileInfo,
'save_path': self.storageDirectory, 'save_path': self.storageDirectory,
#'flags': 0x300, 'flags': 0x300,
'paused': False, 'paused': False,
'auto_managed': False, #'auto_managed': False,
'storage_mode': self.lt.storage_mode_t.storage_mode_allocate, #'storage_mode': self.lt.storage_mode_t.storage_mode_allocate,
}) })
else: else:
self.torrentFileInfo = self.getMagnetInfo() self.torrentFileInfo = self.getMagnetInfo()
@ -432,11 +436,13 @@ class Libtorrent:
state_str = ['queued', 'checking', 'downloading metadata', state_str = ['queued', 'checking', 'downloading metadata',
'downloading', 'finished', 'seeding', 'allocating'] 'downloading', 'finished', 'seeding', 'allocating']
log('[%s] %.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \ log('[%s] %.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s %s %s' % \
(self.lt.version, s.progress * 100, s.download_rate / 1000, (self.lt.version, s.progress * 100, s.download_rate / 1000,
s.upload_rate / 1000, s.upload_rate / 1000, s.num_peers, state_str[s.state],
s.num_peers, state_str[s.state])) self.get_debug_info('dht_state'), self.get_debug_info('trackers_sum')))
debug('TRACKERS:' +str(self.torrentHandle.trackers())) debug('TRACKERS:' +str(self.torrentHandle.trackers()))
#log('is_dht_running:' +str(self.session.is_dht_running()))
#log('dht_state:' +str(self.session.dht_state()))
#i = 0 #i = 0
# for t in s.pieces: # for t in s.pieces:
# if t: i=i+1 # if t: i=i+1
@ -449,6 +455,28 @@ class Libtorrent:
print 'debug error' print 'debug error'
pass pass
def get_debug_info(self, info):
result=''
if info in ['trackers_full','trackers_sum']:
trackers=[]
for tracker in self.torrentHandle.trackers():
trackers.append((tracker['url'], tracker['fails'], tracker['verified']))
if info=='trackers_full':
for url, fails, verified in trackers:
result=result+'%s: f=%d, v=%s' %(url, fails, str(verified))
if info=='trackers_sum':
fails_sum, verified_sum = 0, 0
for url, fails, verified in trackers:
fails_sum+=fails
if verified: verified_sum+=1
result=result+'Trakers: verified %d/%d, fails=%d' %(verified_sum, len(trackers)-1, fails_sum)
if info=='dht_state':
is_dht_running='ON' if self.session.is_dht_running() else 'OFF'
nodes=self.session.dht_state().get('nodes')
nodes=len(nodes) if nodes else 0
result='DHT: %s (%d)' % (is_dht_running, nodes)
return result
def dump(self, obj): def dump(self, obj):
for attr in dir(obj): for attr in dir(obj):
try: try:

View File

@ -158,7 +158,7 @@ class TorrentPlayer(xbmc.Player):
while True: while True:
if self.setup_play(): if self.setup_play():
# print '************************************* GOING LOOP' # print '************************************* GOING LOOP'
self.torrent.continueSession(self.contentId) #self.torrent.continueSession(self.contentId)
self.loop() self.loop()
else: else:
break break
@ -252,6 +252,9 @@ class TorrentPlayer(xbmc.Player):
speedsText = '%s: %s Mbit/s; %s: %s Mbit/s' % ( speedsText = '%s: %s Mbit/s; %s: %s Mbit/s' % (
Localization.localize('Downloading'), str(self.torrent.getDownloadRate() * 8 / 1000000), Localization.localize('Downloading'), str(self.torrent.getDownloadRate() * 8 / 1000000),
Localization.localize('Uploading'), str(self.torrent.getUploadRate() * 8 / 1000000)) Localization.localize('Uploading'), str(self.torrent.getUploadRate() * 8 / 1000000))
if self.debug:
peersText=peersText + ' ' + self.torrent.get_debug_info('dht_state')
dialogText=dialogText.replace(Localization.localize('Preloaded: '),'') + ' ' + self.torrent.get_debug_info('trackers_sum')
progressBar.update(iterator, Localization.localize('Seeds searching.') + peersText, dialogText, progressBar.update(iterator, Localization.localize('Seeds searching.') + peersText, dialogText,
speedsText) speedsText)
else: else:
@ -264,6 +267,7 @@ class TorrentPlayer(xbmc.Player):
return return
progressBar.update(0) progressBar.update(0)
progressBar.close() progressBar.close()
self.torrent.continueSession(self.contentId)
return True return True
def setup_subs(self, label, path): def setup_subs(self, label, path):
@ -419,7 +423,7 @@ class TorrentPlayer(xbmc.Player):
def _get_status_lines(self, s): def _get_status_lines(self, s):
return [ return [
self.display_name.decode('utf-8'), self.display_name.decode('utf-8'),
"%.2f%% %s" % (s.progress * 100, Localization.localize(STATE_STRS[s.state]).decode('utf-8')), "%.2f%% %s %s %s" % (s.progress * 100, Localization.localize(STATE_STRS[s.state]).decode('utf-8'), self.torrent.get_debug_info('dht_state'), self.torrent.get_debug_info('trackers_sum')),
"D:%.2f%s U:%.2f%s S:%d P:%d" % (s.download_rate / 1000, Localization.localize('kb/s').decode('utf-8'), "D:%.2f%s U:%.2f%s S:%d P:%d" % (s.download_rate / 1000, Localization.localize('kb/s').decode('utf-8'),
s.upload_rate / 1000, Localization.localize('kb/s').decode('utf-8'), s.upload_rate / 1000, Localization.localize('kb/s').decode('utf-8'),
s.num_seeds, s.num_peers) s.num_seeds, s.num_peers)

View File

@ -94,7 +94,11 @@ def clearStorage(userStorageDirectory):
if saved_bool: if saved_bool:
shutil.move(saved_temp, saved) shutil.move(saved_temp, saved)
try:
DownloadDB().clear() DownloadDB().clear()
except Exception, e:
log('[clearStorage]: DownloadDB().clear() failed. '+str(e))
showMessage(Localization.localize('Storage'), Localization.localize('Storage was cleared'), forced=True) showMessage(Localization.localize('Storage'), Localization.localize('Storage was cleared'), forced=True)
@ -1521,11 +1525,12 @@ def fetchData(url, referer=None):
def file_decode(filename): def file_decode(filename):
if not __settings__.getSetting('delete_russian') == 'true':
try:
filename = filename.decode('utf-8') # ,'ignore')
except:
pass pass
#if not __settings__.getSetting('delete_russian') == 'true':
# try:
# filename = filename.decode('utf-8') # ,'ignore')
# except:
# pass
return filename return filename