mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-09 09:58:39 +00:00
Fix displaying torrents with non-utf8 encodings in add torrent dialog
This commit is contained in:
parent
322dffa105
commit
3c4b511e6b
2 changed files with 31 additions and 20 deletions
|
@ -134,16 +134,22 @@ class DelugeRPCProtocol(Protocol):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Format the RPCRequest message for debug printing
|
# Format the RPCRequest message for debug printing
|
||||||
s = call[1] + "("
|
try:
|
||||||
if call[2]:
|
s = call[1] + "("
|
||||||
s += ", ".join([str(x) for x in call[2]])
|
|
||||||
if call[3]:
|
|
||||||
if call[2]:
|
if call[2]:
|
||||||
s += ", "
|
s += ", ".join([str(x) for x in call[2]])
|
||||||
s += ", ".join([key + "=" + str(value) for key, value in call[3].items()])
|
if call[3]:
|
||||||
s += ")"
|
if call[2]:
|
||||||
|
s += ", "
|
||||||
|
s += ", ".join([key + "=" + str(value) for key, value in call[3].items()])
|
||||||
|
s += ")"
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
pass
|
||||||
|
#log.debug("RPCRequest had some non-ascii text..")
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
#log.debug("RPCRequest: %s", s)
|
||||||
|
|
||||||
#log.debug("RPCRequest: %s", s)
|
|
||||||
reactor.callLater(0, self._dispatch, *call)
|
reactor.callLater(0, self._dispatch, *call)
|
||||||
|
|
||||||
def sendData(self, data):
|
def sendData(self, data):
|
||||||
|
|
|
@ -48,15 +48,20 @@ class TorrentInfo(object):
|
||||||
|
|
||||||
self.__m_info_hash = sha(bencode.bencode(self.__m_metadata["info"])).hexdigest()
|
self.__m_info_hash = sha(bencode.bencode(self.__m_metadata["info"])).hexdigest()
|
||||||
|
|
||||||
|
# Get encoding from torrent file if available
|
||||||
|
self.encoding = "UTF-8"
|
||||||
|
if "encoding" in self.__m_metadata:
|
||||||
|
self.encoding = self.__m_metadata["encoding"]
|
||||||
|
|
||||||
# Get list of files from torrent info
|
# Get list of files from torrent info
|
||||||
paths = {}
|
paths = {}
|
||||||
if self.__m_metadata["info"].has_key("files"):
|
if self.__m_metadata["info"].has_key("files"):
|
||||||
prefix = ""
|
prefix = ""
|
||||||
if len(self.__m_metadata["info"]["files"]) > 1:
|
if len(self.__m_metadata["info"]["files"]) > 1:
|
||||||
prefix = self.__m_metadata["info"]["name"]
|
prefix = self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8")
|
||||||
|
|
||||||
for index, f in enumerate(self.__m_metadata["info"]["files"]):
|
for index, f in enumerate(self.__m_metadata["info"]["files"]):
|
||||||
path = os.path.join(prefix, *f["path"])
|
path = os.path.join(prefix, *f["path"]).decode(self.encoding).encode("utf8")
|
||||||
f["index"] = index
|
f["index"] = index
|
||||||
paths[path] = f
|
paths[path] = f
|
||||||
|
|
||||||
|
@ -70,24 +75,24 @@ class TorrentInfo(object):
|
||||||
self.__m_files_tree = file_tree.get_tree()
|
self.__m_files_tree = file_tree.get_tree()
|
||||||
else:
|
else:
|
||||||
self.__m_files_tree = {
|
self.__m_files_tree = {
|
||||||
self.__m_metadata["info"]["name"]: (self.__m_metadata["info"]["length"], True)
|
self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8"): (self.__m_metadata["info"]["length"], True)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.__m_files = []
|
self.__m_files = []
|
||||||
if self.__m_metadata["info"].has_key("files"):
|
if self.__m_metadata["info"].has_key("files"):
|
||||||
prefix = ""
|
prefix = ""
|
||||||
if len(self.__m_metadata["info"]["files"]) > 1:
|
if len(self.__m_metadata["info"]["files"]) > 1:
|
||||||
prefix = self.__m_metadata["info"]["name"]
|
prefix = self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8")
|
||||||
|
|
||||||
for f in self.__m_metadata["info"]["files"]:
|
for f in self.__m_metadata["info"]["files"]:
|
||||||
self.__m_files.append({
|
self.__m_files.append({
|
||||||
'path': os.path.join(prefix, *f["path"]),
|
'path': os.path.join(prefix, *f["path"]).decode(self.encoding).encode("utf8"),
|
||||||
'size': f["length"],
|
'size': f["length"],
|
||||||
'download': True
|
'download': True
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
self.__m_files.append({
|
self.__m_files.append({
|
||||||
"path": self.__m_metadata["info"]["name"],
|
"path": self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8"),
|
||||||
"size": self.__m_metadata["info"]["length"],
|
"size": self.__m_metadata["info"]["length"],
|
||||||
"download": True
|
"download": True
|
||||||
})
|
})
|
||||||
|
@ -103,7 +108,7 @@ class TorrentInfo(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return self.__m_metadata["info"]["name"]
|
return self.__m_metadata["info"]["name"].decode(self.encoding).encode("utf8")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def info_hash(self):
|
def info_hash(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue