Dineshkarthik / telegram_media_downloader

Download media files from a telegram conversation/chat/channel up to 2GiB per file
MIT License
2.16k stars 364 forks source link

add progress bar in download file #487

Open rafaael1 opened 9 months ago

rafaael1 commented 9 months ago

It is possible to add a progress bar to monitor the download of files ?

I tried using a callback function, but the progress bar appears only once. Code below:

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

And,

async def download_media(...):
....
     if _can_download(_type, file_formats, file_format):
         global pbar
         global prev_curr
         ...
                    prev_curr = 0
                    pbar = tqdm(
                            total=getattr(message, _type).file_size, desc="Downloading...", leave=False,
                            unit='B', unit_scale=True
                     )
                     pbar.clear()

Output:

image