Автоматическое определение кодировки файлов

sandbox1
inpos 2016-03-05 18:09:26 +03:00
parent 25319c55ac
commit 142a9cf4a9
2 changed files with 8 additions and 7 deletions

View File

@ -2,9 +2,8 @@
<addon id="script.module.pyrrent2http" name="pyrrent2http" version="0.6.0" provider-name="inpos"> <addon id="script.module.pyrrent2http" name="pyrrent2http" version="0.6.0" provider-name="inpos">
<requires> <requires>
<import addon="xbmc.python" version="2.14.0"/> <import addon="xbmc.python" version="2.14.0"/>
<import addon="script.module.libtorrent" /><import <import addon="script.module.libtorrent" />
addon="script.module.chardet"> <import addon="script.module.chardet" />
</import>
</requires> </requires>
<extension point="xbmc.python.module" library="lib"/> <extension point="xbmc.python.module" library="lib"/>
<extension point="xbmc.addon.metadata"> <extension point="xbmc.addon.metadata">

View File

@ -149,6 +149,8 @@ class TorrentFile(object):
def __init__(self, tfs, fileEntry, savePath, index): def __init__(self, tfs, fileEntry, savePath, index):
self.tfs = tfs self.tfs = tfs
self.fileEntry = fileEntry self.fileEntry = fileEntry
self.name = self.Name()
self.unicode_name = self.name.decode(chardet.detect(self.name)['encoding'])
self.savePath = savePath self.savePath = savePath
self.index = index self.index = index
self.piece_length = int(self.pieceLength()) self.piece_length = int(self.pieceLength())
@ -219,7 +221,7 @@ class TorrentFile(object):
return True return True
def Close(self): def Close(self):
if self.closed: return if self.closed: return
self.log('Closing %s...' % (self.Name(),)) self.log('Closing %s...' % (self.name,))
self.tfs.removeOpenedFile(self) self.tfs.removeOpenedFile(self)
self.closed = True self.closed = True
if self.filePtr is not None: if self.filePtr is not None:
@ -411,7 +413,7 @@ class TorrentFS(object):
tf.closed = False tf.closed = False
self.fileCounter += 1 self.fileCounter += 1
tf.num = self.fileCounter tf.num = self.fileCounter
tf.log('Opening %s...' % (tf.Name(),)) tf.log('Opening %s...' % (tf.name,))
tf.SetPriority(1) tf.SetPriority(1)
startPiece, _ = tf.Pieces() startPiece, _ = tf.Pieces()
self.handle.set_piece_deadline(startPiece, 50) self.handle.set_piece_deadline(startPiece, 50)
@ -892,9 +894,9 @@ class Pyrrent2http(object):
if self.TorrentFS.HasTorrentInfo(): if self.TorrentFS.HasTorrentInfo():
files = self.TorrentFS.Files() files = self.TorrentFS.Files()
for file_ in files: for file_ in files:
Url = 'http://' + self.config.bindAddress + '/files/' + urllib.quote(file_.Name()) Url = 'http://' + self.config.bindAddress + '/files/' + urllib.quote(file_.name)
fi = { fi = {
'name': file_.Name(), 'name': file_.unicode_name,
'size': file_.size, 'size': file_.size,
'offset': file_.offset, 'offset': file_.offset,
'download': file_.Downloaded(), 'download': file_.Downloaded(),