Python telethon.tl.types.DocumentAttributeFilename() Examples

The following are 5 code examples of telethon.tl.types.DocumentAttributeFilename(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module telethon.tl.types , or try the search function .
Example #1
Source File: client.py    From telegram-upload with MIT License 6 votes vote down vote up
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() 
Example #2
Source File: deepfry.py    From BotHub with Apache License 2.0 6 votes vote down vote up
def check_media(reply_message):
    if reply_message and reply_message.media:
        if reply_message.photo:
            data = reply_message.photo
        elif reply_message.document:
            if DocumentAttributeFilename(file_name='AnimatedSticker.tgs') in reply_message.media.document.attributes:
                return False
            if reply_message.gif or reply_message.video or reply_message.audio or reply_message.voice:
                return False
            data = reply_message.media.document
        else:
            return False
    else:
        return False

    if not data or data is None:
        return False
    else:
        return data 
Example #3
Source File: deepfryer.py    From X-tra-Telegram with Apache License 2.0 6 votes vote down vote up
def check_media(reply_message):
    if reply_message and reply_message.media:
        if reply_message.photo:
            data = reply_message.photo
        elif reply_message.document:
            if DocumentAttributeFilename(file_name='AnimatedSticker.tgs') in reply_message.media.document.attributes:
                return False
            if reply_message.gif or reply_message.video or reply_message.audio or reply_message.voice:
                return False
            data = reply_message.media.document
        else:
            return False
    else:
        return False

    if not data or data is None:
        return False
    else:
        return data 
Example #4
Source File: client.py    From telegram-upload with MIT License 5 votes vote down vote up
def send_files(self, entity, files, delete_on_success=False, print_file_id=False,
                   force_file=False, forward=(), caption=None):
        for file in files:
            progress = get_progress_bar('Uploading', os.path.basename(file), os.path.getsize(file))
            name = '.'.join(os.path.basename(file).split('.')[:-1])
            thumb = None
            try:
                thumb = get_file_thumb(file)
            except ThumbError as e:
                click.echo('{}'.format(e), err=True)
            caption = caption[:CAPTION_MAX_LENGTH] if caption else caption
            caption = caption or ((name[:CAPTION_MAX_LENGTH] + '..') if len(name) > CAPTION_MAX_LENGTH else name)
            try:
                if force_file:
                    attributes = [DocumentAttributeFilename(file)]
                else:
                    attributes = get_file_attributes(file)
                message = self.send_file(entity, file, thumb=thumb,
                                         caption=caption, force_document=force_file,
                                         progress_callback=progress, attributes=attributes)
            except Exception:
                raise
            finally:
                if thumb:
                    os.remove(thumb)
            click.echo()
            if print_file_id:
                click.echo('Uploaded successfully "{}" (file_id {})'.format(file, pack_bot_file_id(message.media)))
            if delete_on_success:
                click.echo('Deleting {}'.format(file))
                os.remove(file)
            self.forward_to(message, forward) 
Example #5
Source File: download_service.py    From tgcloud with Apache License 2.0 5 votes vote down vote up
def upload_block(hash_uid):
    try:
        hash_uid = str(hash_uid)
        os.chdir(path_home)
        entity = client.get_entity(client.get_me())
        FIFO = f"upipe_{hash_uid}"

        import errno
        try:
            os.mkfifo(FIFO)
        except OSError as oe:
            if oe.errno != errno.EEXIST:
                raise
        messages = client.get_messages(entity, limit=1, search=hash_uid)   
        with open(FIFO, 'rb') as bytesin:
            if len(messages):
                bytesin.read(1)
                bytesin.close()
                return 0
            message = client.send_file(entity,
                                       file=bytesin,
                                       caption=f'{hash_uid}',
                                       attributes=[DocumentAttributeFilename(f'{hash_uid}')],
                                       allow_cache=False,
                                       part_size_kb=512,
                                       force_document=True,
                                       progress_callback=on_upload_progress)
        return 0
    except Exception:
        return -1
    finally:
        client.disconnect()