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