DEV Community

Telegram Tracker
Telegram Tracker

Posted on

14 2

Python download telegram media

# Download from Message
await app.download_media(message)

# Download from file id
await app.download_media(message.photo.file_id)

# Keep track of the progress while downloading
async def progress(current, total):
    print(f"{current * 100 / total:.1f}%")

await app.download_media(message, progress=progress)
Enter fullscreen mode Exit fullscreen mode

Parameters:

  • message (Message | str) – Pass a Message containing the media, the media itself (message.audio, message.video, …) or a file id as string.
  • file_name (str, optional) – A custom file_name to be used instead of the one provided by Telegram. By default, all files are downloaded in the downloads folder in your working directory. You can also specify a path for downloading files in a custom location: paths that end with “/” are considered directories. All non-existent folders will be created automatically.
  • in_memory (bool, optional) – Pass True to download the media in-memory. A binary file-like object with its attribute “.name” set will be returned. Defaults to False.
  • block (bool, optional) – Blocks the code execution until the file has been downloaded. Defaults to True.
  • progress (Callable, optional) – Pass a callback function to view the file transmission progress. The function must take (current, total) as positional arguments (look at Other Parameters below for a detailed description) and will be called back each time a new file chunk has been successfully transmitted.
  • progress_args (tuple, optional) – Extra custom arguments for the progress callback function. You can pass anything you need to be available in the progress callback scope; for example, a Message object or a Client instance in order to edit the message with the updated progress status.

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay