кодировки
This commit is contained in:
		
							parent
							
								
									8532df64e4
								
							
						
					
					
						commit
						4dde8a2c9e
					
				@ -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=".",
 | 
			
		||||
 | 
			
		||||
@ -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,))
 | 
			
		||||
 | 
			
		||||
@ -41,13 +41,17 @@ 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):
 | 
			
		||||
    if not isinstance(path, unicode): path = path.decode(chardet.detect(path)['encoding'])
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user