From 610983e3457492a8f45971f93df4a5bfe0aa196e Mon Sep 17 00:00:00 2001 From: inpos Date: Sun, 6 Mar 2016 02:23:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=B4=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B0=20mbcs=20=D0=B2=20=D0=BD=D0=B5=D1=80=D1=83=D1=81?= =?UTF-8?q?=D1=81=D0=BA=D0=BE=D0=B9=20Windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addon.xml | 2 +- lib/pyrrent2http/pyrrent2http.py | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/addon.xml b/addon.xml index 634d254..d905cb8 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - + diff --git a/lib/pyrrent2http/pyrrent2http.py b/lib/pyrrent2http/pyrrent2http.py index f053fdd..0d566dc 100644 --- a/lib/pyrrent2http/pyrrent2http.py +++ b/lib/pyrrent2http/pyrrent2http.py @@ -5,7 +5,6 @@ import sys, os import json import chardet try: - import xbmcgui from python_libtorrent import get_libtorrent lt=get_libtorrent() print('Imported libtorrent v%s from python_libtorrent' %(lt.version, )) @@ -172,7 +171,8 @@ class TorrentFile(object): if self.filePtr is None: #print('savePath: %s' % (self.savePath,)) while not os.path.exists(self.savePath): - time.sleep(0.1) + logging.info('Waiting: %s' % (self.savePath,)) + time.sleep(0.5) self.filePtr = io.open(self.savePath, 'rb') return self.filePtr def log(self, message): @@ -375,7 +375,11 @@ class TorrentFS(object): if index < 0 or index >= info.num_files(): raise IndexError fileEntry = info.file_at(index) - path = os.path.abspath(os.path.join(self.SavePath(), fileEntry.path)) + fe_path = fileEntry.path + fe_path = fe_path.decode(chardet.detect(fe_path)['encoding']) + if not sys.platform.startswith('win'): + fe_path = fe_path.encode(sys.getfilesystemencoding()) + path = os.path.abspath(os.path.join(self.SavePath(), fe_path)) return TorrentFile( self, fileEntry, @@ -383,9 +387,12 @@ class TorrentFS(object): index ) def FileByName(self, name): + name = name.decode(chardet.detect(name)['encoding']) + if not sys.platform.startswith('win'): + name = name.encode(sys.getfilesystemencoding()) savePath = os.path.abspath(os.path.join(self.SavePath(), name)) for file_ in self.Files(): - if file_.SavePath() == savePath: + if file_.savePath == savePath: return file_ raise IOError def Open(self, name): @@ -415,8 +422,7 @@ class TorrentFS(object): tf.num = self.fileCounter tf.log('Opening %s...' % (tf.name,)) tf.SetPriority(1) - startPiece, _ = tf.Pieces() - self.handle.set_piece_deadline(startPiece, 50) + self.handle.set_piece_deadline(tf.startPiece, 50) self.lastOpenedFile = tf self.addOpenedFile(tf) self.checkPriorities() @@ -982,7 +988,7 @@ class Pyrrent2http(object): if self.forceShutdown: return if time.time() - time_start > 0.5: - self.consumeAlerts() + #self.consumeAlerts() self.TorrentFS.LoadFileProgress() state = self.torrentHandle.status().state if self.config.exitOnFinish and (state == state.finished or state == state.seeding):