Skip to content

Commit

Permalink
修复BT文件中有中文时添加出错的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chliny committed Oct 26, 2013
1 parent b887176 commit 5b93d4e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions xfdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,10 @@ def __pushtor(self,myfile,filename):
return False

fileentry = torinfo["files"][i]
filename = fileentry["file_name"]
if filename in oldfiles:
inname = fileentry["file_name"]
if inname in oldfiles:
continue
btfilenames.append(filename)
btfilenames.append(inname)
btindexs.append(str(i))
btsizes.append(str(fileentry["file_size_ori"]))

Expand All @@ -445,6 +445,7 @@ def __pushtor(self,myfile,filename):

btindex = "#".join(btindexs)
btfilename = "#".join(btfilenames)
btfilename = self.toUnicode(btfilename).encode("utf8")
btfilesize = "#".join(btsizes)

data3={"cmd":"add_bt_task",
Expand All @@ -467,6 +468,20 @@ def __pushtor(self,myfile,filename):

return True

def toUnicode(self,word):
if isinstance(word,unicode):
return word
if not isinstance(word,str):
return None
if word == None or word == "":
return word
try:
word = word.decode("utf8")
except:
word = word.decode("gbk")

return word

def __addtask(self):
if self._addurl == '':
_print ("请输入下载地址:")
Expand Down

0 comments on commit 5b93d4e

Please # to comment.