[Python] how to use FastTelethonhelper properly in an existing code?

Discussão em 'Python' iniciado por Stack, Fevereiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to implement fast_download in my existing code. The problem is fast_download module uses await which I am not familiar with. The official documentation is not enough to implement for my current knowledge. Is there anyone who can help me?

    here is my code.

    from telethon.sync import TelegramClient
    from telethon.tl.functions.messages import GetDialogsRequest
    from telethon.tl.functions.channels import GetFullChannelRequest
    from FastTelethonhelper import fast_download
    from telethon.tl.types import InputPeerEmpty
    from tqdm import tqdm

    api_id =
    api_hash = ''


    def callback(current, total):
    global pbar
    global prev_curr
    pbar.update(current - prev_curr)
    prev_curr = current


    def download_media(group, cl, name):
    global pbar
    global prev_curr

    messages = cl.get_messages(group, limit=2000)

    start = 0
    print(start)
    for i, message in enumerate(messages[start:]):
    prev_curr = 0
    if message.video:
    print("\n{} / {} : {}".format(i + start, len(messages), message.file.name))
    pbar = tqdm(total=message.document.size, unit='B', unit_scale=True)
    message.download_media('./' + name + '/', progress_callback=callback)
    # fast_download(client, message.video, download_folder = './' + name + '/', progress_bar_function=callback)
    pbar.close()


    with TelegramClient('name', api_id, api_hash) as client:
    result = client(GetDialogsRequest(
    offset_date=None,
    offset_id=0,
    offset_peer=InputPeerEmpty(),
    limit=500,
    hash=0,
    ))

    title = 'channel_name' # Title for channel
    channel = client(GetFullChannelRequest(title))
    download_media(channel.full_chat, client, "directory_name")



    I was expecting to enhance download speed of telethon api. Download speed of some files are limited to 100 kbs, which is too slow for large files. I have already implemented a code to use with telethon built-in module "download_media".

    Continue reading...

Compartilhe esta Página