better handling of unicode

This commit is contained in:
iou1name 2018-06-30 19:16:05 -04:00
parent e8baf1848b
commit 23eb0543c8

View File

@ -39,9 +39,9 @@ class OppaiBot(irc.IRCClient):
""" """
res = requests.get(url, cookies=self.cj, headers=HEADERS, verify=True) res = requests.get(url, cookies=self.cj, headers=HEADERS, verify=True)
res.raise_for_status() res.raise_for_status()
fname = re.search(r'filename="(.+)"',res.headers['content-disposition']) fname =re.search(r'filename="(.+)"',res.headers['content-disposition'])
fname = fname.group(1) fname = fname.group(1)
fname = fname.replace(u"â\x80\x93", "") fname = fname.encode("latin-1").decode("utf-8")
print(self.tracker + ": Saving torrent:", fname) print(self.tracker + ": Saving torrent:", fname)
with open(os.path.join(directory, fname), "wb") as file: with open(os.path.join(directory, fname), "wb") as file:
for chunk in res.iter_content(100000): for chunk in res.iter_content(100000):