Search code examples
web-scrapingtelegramtelegram-bottelethon

How to get the total MB size of all media data using Telethon


As the title says, how do I get the total MB size of all media data (photos, videos, ect.) from a Telegram Channel using Telethon?

I figured out I could use data = await client(functions.messages.SearchRequest(...)) to get the data of a channel, but it seems like when I try to strip the data with data.media.document.size, it only gets the sizes of some media files, and not all? How do I get for all media types?


Solution

  • Using client.iter_messages you can then get the Message.file which has a File.size. In v1:

    total_size = 0
    async for message in client.iter_messages(chat):
        if message.file:
            total_size += message.file.size
            print('current total:', total_size)