From 4ca7e13246eee2aa3cd8e664ff1d8a1b619be46f Mon Sep 17 00:00:00 2001 From: esefxdz Date: Tue, 23 Jun 2026 19:01:59 +0300 Subject: [PATCH] telegram gif issue fixed --- tgbridge/forwarder.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tgbridge/forwarder.py b/tgbridge/forwarder.py index 0304309..f814680 100644 --- a/tgbridge/forwarder.py +++ b/tgbridge/forwarder.py @@ -129,6 +129,24 @@ class TelegramForwarder: elif message.animation: file_data, filename = await self._download_file(message.animation.file_id) + + # convert mp4 animation to true gif so discord auto-loops it + try: + import asyncio + process = await asyncio.create_subprocess_exec( + 'ffmpeg', '-i', 'pipe:0', '-f', 'gif', '-loop', '0', 'pipe:1', + stdin=asyncio.subprocess.PIPE, + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.DEVNULL + ) + stdout_data, _ = await process.communicate(input=file_data) + if process.returncode == 0 and stdout_data: + file_data = stdout_data + # replace extension with .gif + filename = filename.rsplit('.', 1)[0] + '.gif' + except Exception as e: + print(f'ffmpeg gif conversion failed (is ffmpeg installed?): {e}') + text = f'{prefix}{caption}'.strip() await self._send_to_webhook(webhook_url, sender, text, file_data, filename)