Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images from restricted channels #44

Closed
balki97 opened this issue Sep 11, 2022 · 1 comment
Closed

Images from restricted channels #44

balki97 opened this issue Sep 11, 2022 · 1 comment

Comments

@balki97
Copy link

balki97 commented Sep 11, 2022

As I've been using telemirror for a while now and came to test all of its features. I can confirm that it pulls content from restricted channels but just not media (images,videos). I just want to confirm if this is a problem from my side or its something that cannot be achieved ?

@khoben
Copy link
Owner

khoben commented Sep 11, 2022

As I've been using telemirror for a while now and came to test all of its features. I can confirm that it pulls content from restricted channels but just not media (images,videos). I just want to confirm if this is a problem from my side or its something that cannot be achieved ?

You can only retrieve and forward content from protected channels by re-saving it. The easiest ones are text and images. Text is simply copied and images are downloaded as an array of bytes and sent. The other types of media require a bit more processing logic.
I have now completely removed option to forward from such channels, but this is easily fixed by removing checks for the noforwards chat flag and implementing re-saving.

For forwarding text and pictures, you can do the following:

  1. Check that chat has the noforwards flag
  2. If the incomin_message.media is a picture, download it as an array of bytes (or even to storage) and re-send it:
downloaded_bytes = await self.download_media(incoming_message, file=bytes)
await self.send_message(
     entity=outgoing_chat,
     message=incoming_message.message,
     file=downloaded_bytes,
     formatting_entities=incoming_message.entities,
     reply_to=reply_to_messages.get(outgoing_chat)
)

Such a scheme worked quite well. To handle more media types, you should use storage and check if it makes sense to re-upload large files.

@khoben khoben pinned this issue Sep 12, 2022
@khoben khoben closed this as completed Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants