11import os
2+ import pprint
3+ import sys
24import yt_dlp
35import asyncio
46import time
@@ -112,7 +114,7 @@ def _run_yt_dlp_download(
112114 user_download_dir = get_user_download_path (user_id )
113115 cancel_event = active_downloads .get (original_msg_id )
114116
115- def download_progress_hook (d ):
117+ def download_progress_hook (d : dict ):
116118 # Check for cancellation signal
117119 if cancel_event and cancel_event .is_set ():
118120 # Use a specific exception type if yt-dlp allows interrupting downloads
@@ -128,27 +130,36 @@ def download_progress_hook(d):
128130 current_time - last_update_time .get ((chat_id , message_id ), 0 )
129131 > UPDATE_INTERVAL
130132 ):
131- percentage_str = d .get ("_percent_str" , "0%" ).strip ("%" )
133+ # print("I got what I needed, quitting...")
134+ # with open("progresshook.log", "a", encoding="utf-8") as f:
135+ # for key, value in d.items():
136+ # f.write(f'{key}: {value}\n')
137+ # print("I got what i needed, quitting...")
138+ # # pprint.pprint(d.items())
139+ # sys.exit(1)
140+ total_bytes = d .get ("total_bytes_estimate" , 1 )
141+ downloaded_bytes = d .get ("downloaded_bytes" , 1 )
142+ total_mb = total_bytes / (1024 * 1024 ) if total_bytes else 0
143+ downloaded_mb = (
144+ downloaded_bytes / (1024 * 1024 ) if downloaded_bytes else 0
145+ )
146+ percentage_str = d .get ("_percent" , 0.0 )
147+
132148 try :
133149 percentage_float = float (percentage_str )
134150 except ValueError :
135151 percentage_float = 0.0
136152
137153 speed = d .get ("_speed_str" , "N/A" )
138154 eta = d .get ("_eta_str" , "N/A" )
139- total_bytes = d .get ("total_bytes" ) or d .get ("total_bytes_estimate" , 0 )
140- downloaded_bytes = d .get ("downloaded_bytes" , 0 )
141155
142156 progress_bar = create_progress_bar (percentage_float )
143157 total_mb = total_bytes / (1024 * 1024 ) if total_bytes else 0
144- downloaded_mb = (
145- downloaded_bytes / (1024 * 1024 ) if downloaded_bytes else 0
146- )
147158
148159 progress_text = (
149160 f"{ dl_text } \n "
150161 f"**By:** { user_mention } \n **User ID:** `{ user_id } `\n \n "
151- f"**Progress:** { progress_bar } { percentage_float :.1f } %\n "
162+ f"**Progress:** { progress_bar } { percentage_float :.2f } %\n "
152163 f"File Size: `{ total_mb :.2f} MB`\n "
153164 )
154165
0 commit comments