def download(type_, book_id, msg):
try:
if type_ in ['fb2', 'epub', 'mobi']:
r = requests.get(f"http://flibusta.is/b/{book_id}/{type_}")
else:
r = requests.get(f"http://flibusta.is/b/{book_id}/download")
except requests.exceptions.ConnectionError as err:
telebot.logger.exception(err)
return None
if 'text/html' in r.headers['Content-Type']: # if bot get html file with error message
try: # try download file from tor
if type_ in ['fb2', 'epub', 'mobi']:
r = requests.get(f"http://flibustahezeous3.onion/b/{book_id}/{type_}",
proxies=config.PROXIES)
else:
r = requests.get(f"http://flibustahezeous3.onion/b/{book_id}/download",
proxies=config.PROXIES)
except requests.exceptions.ConnectionError as err:
logger.debug(err)
bot.reply_to(msg, "?????? ??????????? ? ???????! ?????????? ???????.").wait()
return None
if 'text/html' in r.headers['Content-Type']: # send message to user when get
bot.reply_to(msg, "??????! ?????????? ????? ???? ????? :(").wait() # html file
return None
return r
评论列表
文章目录