Exemplo n.º 1
0
 def download_files(self, entity, messages: Iterable[Message], delete_on_success: bool = False):
     messages = reversed(list(messages))
     for message in messages:
         filename_attr = get_message_file_attribute(message)
         filename = filename_attr.file_name if filename_attr else 'Unknown'
         if message.document.size > free_disk_usage():
             raise TelegramUploadNoSpaceError(
                 'There is no disk space to download "{}". Space required: {}'.format(
                     filename, sizeof_fmt(message.document.size - free_disk_usage())
                 )
             )
         progress, bar = get_progress_bar('Downloading', filename, message.document.size)
         try:
             self.download_media(message, progress_callback=progress)
         finally:
             bar.render_finish()
         if delete_on_success:
             self.delete_messages(entity, [message])
Exemplo n.º 2
0
 def download_files(self,
                    entity,
                    messages: Iterable[Message],
                    delete_on_success: bool = False):
     messages = reversed(list(messages))
     for message in messages:
         filename_attr = next(
             filter(lambda x: isinstance(x, DocumentAttributeFilename),
                    message.document.attributes), None)
         filename = filename_attr.file_name if filename_attr else 'Unknown'
         if message.document.size > free_disk_usage():
             raise TelegramUploadNoSpaceError(
                 'There is no disk space to download "{}". Space required: {}'
                 .format(
                     filename,
                     sizeof_fmt(message.document.size - free_disk_usage())))
         progress = get_progress_bar('Downloading', filename,
                                     message.document.size)
         self.download_media(message, progress_callback=progress)
         if delete_on_success:
             self.delete_messages(entity, [message])
         print()