def add_torrent(self, torrent_data: Union[str, bytes], download_dir: str=None) -> bool:
self.total_size = 0
self.expected_torrent_name = ''
lf = NamedTemporaryFile()
lf.write(torrent_data)
params = {'action': 'add-file', 'token': self.token}
files = {'torrent_file': open(lf.name, 'rb')}
try:
response = requests.post(
self.UTORRENT_URL,
auth=self.auth,
params=params,
files=files,
timeout=25).json()
lf.close()
if 'error' in response:
return False
else:
return True
except RequestException:
lf.close()
return False
评论列表
文章目录