简体   繁体   中英

Telegram Telethon Media Download Progress with TQDM

i just want a working Progressbar (tqdm) when downloading with Telethon.

def prog(current, total):
    global pbar
    pbar.update(current)

pbar = tqdm()

async def DoIt():
    global pbar
    async for message in client.iter_messages(entity=entity, limit=60,reverse=False):
        pbar = tqdm(unit='B',unit_scale=True,total=message.media.document.size)
        await client.download_media(message.media.document, "Q:\\dl", progress_callback=prog)
        pbar.close()

It does not really work. The Progressbar goes from "0" to "100": pbar

then this appears:

pbar

The way tqdm work in my opinion, is that it update the chunk that was completed. For this example to work, I had to workout the change from previous update and feed that to update. Work well.

# Printing download progress
def callback(current, total):
    global pbar
    global prev_curr
    pbar.update(current-prev_curr)
    prev_curr = current

async def main():
    global pbar
    global prev_curr
    async for message in client.iter_messages(chat, reverse=True):
    if message.media:  
        prev_curr = 0
        pbar = tqdm(total=message.document.size, unit='B', unit_scale=True)
        path = await message.download_media('{}/{}'.format(dlw_path,file_name), progress_callback=callback)
        pbar.close()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM