Fix #934 use 'name.utf-8' if available and decode the file path before

joining it with the prefix
This commit is contained in:
Andrew Resch 2009-05-12 20:22:21 +00:00
parent 397434f7ca
commit 5606925aa0
1 changed files with 8 additions and 5 deletions

View File

@ -76,8 +76,11 @@ class TorrentInfo(object):
elif "codepage" in self.__m_metadata: elif "codepage" in self.__m_metadata:
self.encoding = str(self.__m_metadata["codepage"]) self.encoding = str(self.__m_metadata["codepage"])
# We try to decode based on the encoding found and if we can't, we try # Check if 'name.utf-8' is in the torrent and if not try to decode the string
# to detect the encoding and decode that # using the encoding found.
if "name.utf-8" in self.__m_metadata["info"]:
self.__m_name = decode_string(self.__m_metadata["info"]["name.utf-8"])
else:
self.__m_name = decode_string(self.__m_metadata["info"]["name"], self.encoding) self.__m_name = decode_string(self.__m_metadata["info"]["name"], self.encoding)
# Get list of files from torrent info # Get list of files from torrent info
@ -88,7 +91,7 @@ class TorrentInfo(object):
prefix = self.__m_name prefix = self.__m_name
for index, f in enumerate(self.__m_metadata["info"]["files"]): for index, f in enumerate(self.__m_metadata["info"]["files"]):
path = decode_string(os.path.join(prefix, *f["path"])) path = decode_string(os.path.join(prefix, decode_string(os.path.join(*f["path"]))))
f["index"] = index f["index"] = index
paths[path] = f paths[path] = f
@ -113,7 +116,7 @@ class TorrentInfo(object):
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': decode_string(os.path.join(prefix, *f["path"])), 'path': decode_string(os.path.join(prefix, decode_string(os.path.join(*f["path"])))),
'size': f["length"], 'size': f["length"],
'download': True 'download': True
}) })