From 5606925aa069dcc5d7de6a66d8cf21d8f75f2361 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Tue, 12 May 2009 20:22:21 +0000 Subject: [PATCH] Fix #934 use 'name.utf-8' if available and decode the file path before joining it with the prefix --- deluge/ui/common.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/deluge/ui/common.py b/deluge/ui/common.py index 74497eed2..077e844b7 100644 --- a/deluge/ui/common.py +++ b/deluge/ui/common.py @@ -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 })