From 4dde8a2c9e6c776628ed22e9f368b0f9380e6f62 Mon Sep 17 00:00:00 2001 From: inpos Date: Mon, 14 Mar 2016 13:29:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D0=B4=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pyrrent2http/engine.py | 4 ++-- lib/pyrrent2http/pyrrent2http.py | 6 +++--- lib/pyrrent2http/util.py | 6 +++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/pyrrent2http/engine.py b/lib/pyrrent2http/engine.py index b0d6362..9d6c658 100644 --- a/lib/pyrrent2http/engine.py +++ b/lib/pyrrent2http/engine.py @@ -6,7 +6,7 @@ import pyrrent2http import xbmc from error import Error from . import SessionStatus, FileStatus, PeerInfo, Encryption -from util import can_bind, find_free_port, localize_path, uri2path, normalize_msg +from util import can_bind, find_free_port, localize_path, uri2path import threading LOGGING = True @@ -19,7 +19,7 @@ class Engine: if self.logger: self.logger(message) else: - xbmc.log(normalize_msg("[pyrrent2http] %s", (message,))) + xbmc.log("[pyrrent2http] %s" % message) def __init__(self, uri=None, platform=None, download_path=".", diff --git a/lib/pyrrent2http/pyrrent2http.py b/lib/pyrrent2http/pyrrent2http.py index d00cca3..91cdf65 100644 --- a/lib/pyrrent2http/pyrrent2http.py +++ b/lib/pyrrent2http/pyrrent2http.py @@ -24,7 +24,7 @@ import BaseHTTPServer import SocketServer import threading import io -from util import localize_path, Struct, detect_media_type, uri2path, normalize_msg +from util import localize_path, Struct, detect_media_type, uri2path, encode_msg ###################################################################################### @@ -592,8 +592,8 @@ class Pyrrent2http(object): def buildTorrentParams(self, uri): try: absPath = uri2path(uri) - logging.info(normalize_msg('Opening local torrent file: %s', (absPath,))) - torrent_info = lt.torrent_info(absPath) + logging.info('Opening local torrent file: %s' % encode_msg(absPath)) + torrent_info = lt.torrent_info(lt.bdecode(open(absPath, 'rb').read())) except Exception as e: strerror = e.args logging.error('Build torrent params error is (%s)' % (strerror,)) diff --git a/lib/pyrrent2http/util.py b/lib/pyrrent2http/util.py index f788c1d..e4e318d 100644 --- a/lib/pyrrent2http/util.py +++ b/lib/pyrrent2http/util.py @@ -41,12 +41,16 @@ def detect_media_type(name): return MediaType.VIDEO else: return MediaType.UNKNOWN -def normalize_msg(tmpl, args): +def unicode_msg(tmpl, args): msg = isinstance(tmpl, unicode) and tmpl or tmpl.decode(chardet.detect(tmpl)['encoding']) arg_ = [] for a in args: arg_.append(isinstance(a, unicode) and a or a.decode(chardet.detect(a)['encoding'])) return msg % tuple(arg_) + +def encode_msg(msg): + msg = isinstance(msg, unicode) and msg.encode(True and sys.getfilesystemencoding() or 'utf-8') or msg + return msg def localize_path(path):