diff --git a/backends/transmission.py b/backends/transmission.py index 972dc01..70b089c 100644 --- a/backends/transmission.py +++ b/backends/transmission.py @@ -1,3 +1,5 @@ +import base64 + import transmissionrpc @@ -15,7 +17,15 @@ def __init__(self, config): config['port']) def add_torrent(self, torrent, timeout=None, **kwargs): - return Torrent(self.transmission.add_torrent(torrent, timeout, **kwargs)) + """Adds new torrent to download list. + + Args: + torrent (telegram.File): File torrent object. + timeout (int): Drop connection after timeout seconds. + """ + barray = torrent.download_as_bytearray() + filedump = base64.b64encode(barray).decode('utf-8') + self.transmission.add_torrent(filedump, timeout, **kwargs) def get_torrents(self): """Yields Torrents objects.""" diff --git a/handlers/message_handlers.py b/handlers/message_handlers.py index a4dd186..6fad8c7 100644 --- a/handlers/message_handlers.py +++ b/handlers/message_handlers.py @@ -1,4 +1,3 @@ -import base64 import logging from telegram.ext import Filters, MessageHandler @@ -13,9 +12,8 @@ def __init__(self, client): super().__init__(self.filters, self.callback) def callback(self, update, context): - torrent = update.message.document.get_file().download_as_bytearray() - filedump = base64.b64encode(torrent).decode('utf-8') - self.client.add_torrent(filedump) + torrent = update.message.document.get_file() + self.client.add_torrent(torrent) logging.info('Added new torrent file %s', update.message.document.file_name) context.bot.send_message(