How to use the pyrogram.client.ext.utils.get_input_media_from_file_id 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 / edit_message_media.py View on Github external
)
                )

                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(
                    url=media.media
                )
            else:
                media = utils.get_input_media_from_file_id(media.media, media.file_ref, 4)
        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(
github pyrogram / pyrogram / pyrogram / client / methods / users / delete_profile_photos.py View on Github external
``bool``: True on success.

        Example:
            .. code-block:: python

                # Get the photos to be deleted
                photos = app.get_profile_photos("me")

                # Delete one photo
                app.delete_profile_photos(photos[0].file_id)

                # Delete the rest of the photos
                app.delete_profile_photos([p.file_id for p in photos[1:]])
        """
        photo_ids = photo_ids if isinstance(photo_ids, list) else [photo_ids]
        input_photos = [utils.get_input_media_from_file_id(i).id for i in photo_ids]

        return bool(self.send(
            functions.photos.DeletePhotos(
                id=input_photos
            )
github pyrogram / pyrogram / pyrogram / client / methods / messages / send_sticker.py View on Github external
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,
                            reply_to_msg_id=reply_to_message_id,
                            random_id=self.rnd_id(),
                            schedule_date=schedule_date,
                            reply_markup=reply_markup.write() if reply_markup else None,
                            message=""
                        )
                    )
                except FilePartMissing as e:
github pyrogram / pyrogram / pyrogram / client / methods / messages / send_animated_sticker.py View on Github external
try:
            if os.path.exists(animated_sticker):
                file = self.save_file(animated_sticker, progress=progress, progress_args=progress_args)
                media = types.InputMediaUploadedDocument(
                    mime_type=self.guess_mime_type(animated_sticker) or "application/x-tgsticker",
                    file=file,
                    attributes=[
                        types.DocumentAttributeFilename(file_name=os.path.basename(animated_sticker))
                    ]
                )
            elif animated_sticker.startswith("http"):
                media = types.InputMediaDocumentExternal(
                    url=animated_sticker
                )
            else:
                media = utils.get_input_media_from_file_id(animated_sticker, 5)

            while True:
                try:
                    r = self.send(
                        functions.messages.SendMedia(
                            peer=self.resolve_peer(chat_id),
                            media=media,
                            silent=disable_notification or None,
                            reply_to_msg_id=reply_to_message_id,
                            random_id=self.rnd_id(),
                            reply_markup=reply_markup.write() if reply_markup else None,
                            message=""
                        )
                    )
                except FilePartMissing as e:
                    self.save_file(animated_sticker, file_id=file.id, file_part=e.x)
github pyrogram / pyrogram / pyrogram / client / methods / messages / send_media_group.py View on Github external
peer=self.resolve_peer(chat_id),
                            media=types.InputMediaDocumentExternal(
                                url=i.media
                            )
                        )
                    )

                    media = types.InputMediaDocument(
                        id=types.InputDocument(
                            id=media.document.id,
                            access_hash=media.document.access_hash,
                            file_reference=media.document.file_reference
                        )
                    )
                else:
                    media = utils.get_input_media_from_file_id(i.media, i.file_ref, 4)

            multi_media.append(
                types.InputSingleMedia(
                    media=media,
                    random_id=self.rnd_id(),
                    **self.parser.parse(i.caption, i.parse_mode)
                )
            )

        while True:
            try:
                r = self.send(
                    functions.messages.SendMultiMedia(
                        peer=self.resolve_peer(chat_id),
                        multi_media=multi_media,
                        silent=disable_notification or None,
github pyrogram / pyrogram / pyrogram / client / methods / messages / send_cached_media.py View on Github external
Additional interface options. An object for an inline keyboard, custom reply keyboard,
                instructions to remove reply keyboard or to force a reply from the user.

        Returns:
            :obj:`Message`: On success, the sent media message is returned.

        Example:
            .. code-block:: python

                app.send_cached_media("me", "CAADBAADyg4AAvLQYAEYD4F7vcZ43AI")
        """

        r = self.send(
            functions.messages.SendMedia(
                peer=self.resolve_peer(chat_id),
                media=utils.get_input_media_from_file_id(file_id, file_ref),
                silent=disable_notification or None,
                reply_to_msg_id=reply_to_message_id,
                random_id=self.rnd_id(),
                schedule_date=schedule_date,
                reply_markup=reply_markup.write() if reply_markup else None,
                **self.parser.parse(caption, parse_mode)
            )
        )

        for i in r.updates:
            if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage)):
                return pyrogram.Message._parse(
                    self, i.message,
                    {i.id: i for i in r.users},
                    {i.id: i for i in r.chats},
                    is_scheduled=isinstance(i, types.UpdateNewScheduledMessage)
github pyrogram / pyrogram / pyrogram / client / methods / messages / send_audio.py View on Github external
thumb=thumb,
                    attributes=[
                        types.DocumentAttributeAudio(
                            duration=duration,
                            performer=performer,
                            title=title
                        ),
                        types.DocumentAttributeFilename(file_name=os.path.basename(audio))
                    ]
                )
            elif audio.startswith("http"):
                media = types.InputMediaDocumentExternal(
                    url=audio
                )
            else:
                media = utils.get_input_media_from_file_id(audio, file_ref, 9)

            while True:
                try:
                    r = self.send(
                        functions.messages.SendMedia(
                            peer=self.resolve_peer(chat_id),
                            media=media,
                            silent=disable_notification or None,
                            reply_to_msg_id=reply_to_message_id,
                            random_id=self.rnd_id(),
                            schedule_date=schedule_date,
                            reply_markup=reply_markup.write() if reply_markup else None,
                            **self.parser.parse(caption, parse_mode)
                        )
                    )
                except FilePartMissing as e:
github pyrogram / pyrogram / pyrogram / client / methods / messages / send_photo.py View on Github external
file = None

        try:
            if os.path.exists(photo):
                file = self.save_file(photo, progress=progress, progress_args=progress_args)
                media = types.InputMediaUploadedPhoto(
                    file=file,
                    ttl_seconds=ttl_seconds
                )
            elif photo.startswith("http"):
                media = types.InputMediaPhotoExternal(
                    url=photo,
                    ttl_seconds=ttl_seconds
                )
            else:
                media = utils.get_input_media_from_file_id(photo, file_ref, 2)

            while True:
                try:
                    r = self.send(
                        functions.messages.SendMedia(
                            peer=self.resolve_peer(chat_id),
                            media=media,
                            silent=disable_notification or None,
                            reply_to_msg_id=reply_to_message_id,
                            random_id=self.rnd_id(),
                            schedule_date=schedule_date,
                            reply_markup=reply_markup.write() if reply_markup else None,
                            **self.parser.parse(caption, parse_mode)
                        )
                    )
                except FilePartMissing as e:
github pyrogram / pyrogram / pyrogram / client / methods / messages / edit_message_media.py View on Github external
)
                )

                media = types.InputMediaPhoto(
                    id=types.InputPhoto(
                        id=media.photo.id,
                        access_hash=media.photo.access_hash,
                        file_reference=b""
                    )
                )
            elif media.media.startswith("http"):
                media = types.InputMediaPhotoExternal(
                    url=media.media
                )
            else:
                media = utils.get_input_media_from_file_id(media.media, media.file_ref, 2)
        elif isinstance(media, InputMediaVideo):
            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 "video/mp4",
                            thumb=None if media.thumb is None else self.save_file(media.thumb),
                            file=self.save_file(media.media),
                            attributes=[
                                types.DocumentAttributeVideo(
                                    supports_streaming=media.supports_streaming or None,
                                    duration=media.duration,
                                    w=media.width,
                                    h=media.height
                                ),