How to use the pyrogram.api.types.DocumentAttributeFilename function in Pyrogram

To help you get started, we’ve selected a few Pyrogram examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyrogram / pyrogram / pyrogram / client / methods / messages / send_media_group.py View on Github external
try:
                            media = await self.send(
                                functions.messages.UploadMedia(
                                    peer=await self.resolve_peer(chat_id),
                                    media=types.InputMediaUploadedDocument(
                                        file=await self.save_file(i.media),
                                        thumb=None if i.thumb is None else self.save_file(i.thumb),
                                        mime_type=self.guess_mime_type(i.media) or "video/mp4",
                                        attributes=[
                                            types.DocumentAttributeVideo(
                                                supports_streaming=i.supports_streaming or None,
                                                duration=i.duration,
                                                w=i.width,
                                                h=i.height
                                            ),
                                            types.DocumentAttributeFilename(file_name=os.path.basename(i.media))
                                        ]
                                    )
                                )
                            )
                        except FloodWait as e:
                            logging.warning("Sleeping for {}s".format(e.x))
                            await asyncio.sleep(e.x)
                        else:
                            break

                    media = types.InputMediaDocument(
                        id=types.InputDocument(
                            id=media.document.id,
                            access_hash=media.document.access_hash,
                            file_reference=media.document.file_reference
                        )
github pyrogram / pyrogram / pyrogram / client / methods / messages / send_media_group.py View on Github external
try:
                            media = self.send(
                                functions.messages.UploadMedia(
                                    peer=self.resolve_peer(chat_id),
                                    media=types.InputMediaUploadedDocument(
                                        file=self.save_file(i.media),
                                        thumb=None if i.thumb is None else self.save_file(i.thumb),
                                        mime_type=self.guess_mime_type(i.media) or "video/mp4",
                                        attributes=[
                                            types.DocumentAttributeVideo(
                                                supports_streaming=i.supports_streaming or None,
                                                duration=i.duration,
                                                w=i.width,
                                                h=i.height
                                            ),
                                            types.DocumentAttributeFilename(file_name=os.path.basename(i.media))
                                        ]
                                    )
                                )
                            )
                        except FloodWait as e:
                            log.warning("Sleeping for {}s".format(e.x))
                            time.sleep(e.x)
                        else:
                            break

                    media = types.InputMediaDocument(
                        id=types.InputDocument(
                            id=media.document.id,
                            access_hash=media.document.access_hash,
                            file_reference=media.document.file_reference
                        )
github pyrogram / pyrogram / pyrogram / client / methods / messages / send_animation.py View on Github external
try:
            if os.path.exists(animation):
                thumb = None if thumb is None else self.save_file(thumb)
                file = self.save_file(animation, progress=progress, progress_args=progress_args)
                media = types.InputMediaUploadedDocument(
                    mime_type=self.guess_mime_type(animation) or "video/mp4",
                    file=file,
                    thumb=thumb,
                    attributes=[
                        types.DocumentAttributeVideo(
                            supports_streaming=True,
                            duration=duration,
                            w=width,
                            h=height
                        ),
                        types.DocumentAttributeFilename(file_name=os.path.basename(animation)),
                        types.DocumentAttributeAnimated()
                    ]
                )
            elif animation.startswith("http"):
                media = types.InputMediaDocumentExternal(
                    url=animation
                )
            else:
                media = utils.get_input_media_from_file_id(animation, file_ref, 10)

            while True:
                try:
                    r = self.send(
                        functions.messages.SendMedia(
                            peer=self.resolve_peer(chat_id),
                            media=media,
github pyrogram / pyrogram / pyrogram / client / types / messages_and_media / message.py View on Github external
location = Location._parse(client, media.geo)
                elif isinstance(media, types.MessageMediaContact):
                    contact = Contact._parse(client, media)
                elif isinstance(media, types.MessageMediaVenue):
                    venue = pyrogram.Venue._parse(client, media)
                elif isinstance(media, types.MessageMediaGame):
                    game = pyrogram.Game._parse(client, message)
                elif isinstance(media, types.MessageMediaDocument):
                    doc = media.document

                    if isinstance(doc, types.Document):
                        attributes = {type(i): i for i in doc.attributes}

                        file_name = getattr(
                            attributes.get(
                                types.DocumentAttributeFilename, None
                            ), "file_name", None
                        )

                        if types.DocumentAttributeAudio in attributes:
                            audio_attributes = attributes[types.DocumentAttributeAudio]

                            if audio_attributes.voice:
                                voice = pyrogram.Voice._parse(client, doc, audio_attributes)
                            else:
                                audio = pyrogram.Audio._parse(client, doc, audio_attributes, file_name)
                        elif types.DocumentAttributeAnimated in attributes:
                            video_attributes = attributes.get(types.DocumentAttributeVideo, None)

                            animation = pyrogram.Animation._parse(client, doc, video_attributes, file_name)
                        elif types.DocumentAttributeVideo in attributes:
                            video_attributes = attributes[types.DocumentAttributeVideo]
github pyrogram / pyrogram / pyrogram / client / methods / messages / send_sticker.py View on Github external
# Send sticker by uploading from local file
                app.send_sticker("me", "sticker.webp")

                # Send sticker using file_id
                app.send_sticker("me", "CAADBAADyg4AAvLQYAEYD4F7vcZ43AI")
        """
        file = None

        try:
            if os.path.exists(sticker):
                file = self.save_file(sticker, progress=progress, progress_args=progress_args)
                media = types.InputMediaUploadedDocument(
                    mime_type=self.guess_mime_type(sticker) or "image/webp",
                    file=file,
                    attributes=[
                        types.DocumentAttributeFilename(file_name=os.path.basename(sticker))
                    ]
                )
            elif sticker.startswith("http"):
                media = types.InputMediaDocumentExternal(
                    url=sticker
                )
            else:
                media = utils.get_input_media_from_file_id(sticker, file_ref, 8)

            while True:
                try:
                    r = self.send(
                        functions.messages.SendMedia(
                            peer=self.resolve_peer(chat_id),
                            media=media,
                            silent=disable_notification or None,
github pyrogram / pyrogram / pyrogram / client / methods / messages / send_video.py View on Github external
try:
            if os.path.exists(video):
                thumb = None if thumb is None else self.save_file(thumb)
                file = self.save_file(video, progress=progress, progress_args=progress_args)
                media = types.InputMediaUploadedDocument(
                    mime_type=self.guess_mime_type(video) or "video/mp4",
                    file=file,
                    thumb=thumb,
                    attributes=[
                        types.DocumentAttributeVideo(
                            supports_streaming=supports_streaming or None,
                            duration=duration,
                            w=width,
                            h=height
                        ),
                        types.DocumentAttributeFilename(file_name=os.path.basename(video))
                    ]
                )
            elif video.startswith("http"):
                media = types.InputMediaDocumentExternal(
                    url=video
                )
            else:
                media = utils.get_input_media_from_file_id(video, file_ref, 4)

            while True:
                try:
                    r = self.send(
                        functions.messages.SendMedia(
                            peer=self.resolve_peer(chat_id),
                            media=media,
                            silent=disable_notification or None,
github pyrogram / pyrogram / pyrogram / client / message_parser.py View on Github external
longitude=media.geo.long,
                    latitude=media.geo.lat
                ),
                title=media.title,
                address=media.address,
                foursquare_id=media.venue_id or None
            )
        elif isinstance(media, types.MessageMediaDocument):
            doc = media.document

            if isinstance(doc, types.Document):
                attributes = {type(i): i for i in doc.attributes}

                file_name = getattr(
                    attributes.get(
                        types.DocumentAttributeFilename, None
                    ), "file_name", None
                )

                if types.DocumentAttributeAudio in attributes:
                    audio_attributes = attributes[types.DocumentAttributeAudio]

                    if audio_attributes.voice:
                        voice = pyrogram_types.Voice(
                            file_id=encode(
                                pack(
                                    "
github pyrogram / pyrogram / pyrogram / client / methods / messages / edit_message_media.py View on Github external
elif isinstance(media, InputMediaAudio):
            if os.path.exists(media.media):
                media = self.send(
                    functions.messages.UploadMedia(
                        peer=self.resolve_peer(chat_id),
                        media=types.InputMediaUploadedDocument(
                            mime_type=self.guess_mime_type(media.media) or "audio/mpeg",
                            thumb=None if media.thumb is None else self.save_file(media.thumb),
                            file=self.save_file(media.media),
                            attributes=[
                                types.DocumentAttributeAudio(
                                    duration=media.duration,
                                    performer=media.performer,
                                    title=media.title
                                ),
                                types.DocumentAttributeFilename(
                                    file_name=os.path.basename(media.media)
                                )
                            ]
                        )
                    )
                )

                media = types.InputMediaDocument(
                    id=types.InputDocument(
                        id=media.document.id,
                        access_hash=media.document.access_hash,
                        file_reference=b""
                    )
                )
            elif media.media.startswith("http"):
                media = types.InputMediaDocumentExternal(