кодировки
parent
8532df64e4
commit
4dde8a2c9e
|
@ -6,7 +6,7 @@ import pyrrent2http
|
||||||
import xbmc
|
import xbmc
|
||||||
from error import Error
|
from error import Error
|
||||||
from . import SessionStatus, FileStatus, PeerInfo, Encryption
|
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
|
import threading
|
||||||
|
|
||||||
LOGGING = True
|
LOGGING = True
|
||||||
|
@ -19,7 +19,7 @@ class Engine:
|
||||||
if self.logger:
|
if self.logger:
|
||||||
self.logger(message)
|
self.logger(message)
|
||||||
else:
|
else:
|
||||||
xbmc.log(normalize_msg("[pyrrent2http] %s", (message,)))
|
xbmc.log("[pyrrent2http] %s" % message)
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, uri=None, platform=None, download_path=".",
|
def __init__(self, uri=None, platform=None, download_path=".",
|
||||||
|
|
|
@ -24,7 +24,7 @@ import BaseHTTPServer
|
||||||
import SocketServer
|
import SocketServer
|
||||||
import threading
|
import threading
|
||||||
import io
|
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):
|
def buildTorrentParams(self, uri):
|
||||||
try:
|
try:
|
||||||
absPath = uri2path(uri)
|
absPath = uri2path(uri)
|
||||||
logging.info(normalize_msg('Opening local torrent file: %s', (absPath,)))
|
logging.info('Opening local torrent file: %s' % encode_msg(absPath))
|
||||||
torrent_info = lt.torrent_info(absPath)
|
torrent_info = lt.torrent_info(lt.bdecode(open(absPath, 'rb').read()))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
strerror = e.args
|
strerror = e.args
|
||||||
logging.error('Build torrent params error is (%s)' % (strerror,))
|
logging.error('Build torrent params error is (%s)' % (strerror,))
|
||||||
|
|
|
@ -41,12 +41,16 @@ def detect_media_type(name):
|
||||||
return MediaType.VIDEO
|
return MediaType.VIDEO
|
||||||
else:
|
else:
|
||||||
return MediaType.UNKNOWN
|
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'])
|
msg = isinstance(tmpl, unicode) and tmpl or tmpl.decode(chardet.detect(tmpl)['encoding'])
|
||||||
arg_ = []
|
arg_ = []
|
||||||
for a in args:
|
for a in args:
|
||||||
arg_.append(isinstance(a, unicode) and a or a.decode(chardet.detect(a)['encoding']))
|
arg_.append(isinstance(a, unicode) and a or a.decode(chardet.detect(a)['encoding']))
|
||||||
return msg % tuple(arg_)
|
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):
|
def localize_path(path):
|
||||||
|
|
Loading…
Reference in New Issue