fixed percentage and mb/s view
This commit is contained in:
@@ -253,15 +253,48 @@ class SeriesApp:
|
||||
if isinstance(progress_info, dict):
|
||||
# Calculate percentage based on downloaded/total bytes
|
||||
downloaded = progress_info.get('downloaded_bytes', 0)
|
||||
total = progress_info.get('total_bytes') or progress_info.get('total_bytes_estimate', 0)
|
||||
total_bytes = (
|
||||
progress_info.get('total_bytes')
|
||||
or progress_info.get('total_bytes_estimate', 0)
|
||||
)
|
||||
|
||||
if total > 0:
|
||||
progress = (downloaded / total) * 100
|
||||
if total_bytes > 0:
|
||||
progress = (downloaded / total_bytes) * 100
|
||||
else:
|
||||
progress = 0
|
||||
|
||||
# Extract speed and ETA from yt-dlp progress dict
|
||||
speed = progress_info.get('speed', 0) # bytes/sec
|
||||
eta = progress_info.get('eta') # seconds
|
||||
|
||||
# Convert to expected format for web API callback
|
||||
# Web API expects: percent, downloaded_mb, total_mb,
|
||||
# speed_mbps, eta_seconds
|
||||
web_progress_dict = {
|
||||
'percent': progress,
|
||||
# Convert bytes to MB
|
||||
'downloaded_mb': downloaded / (1024 * 1024),
|
||||
'total_mb': (
|
||||
total_bytes / (1024 * 1024)
|
||||
if total_bytes > 0
|
||||
else None
|
||||
),
|
||||
# Convert bytes/sec to MB/sec
|
||||
'speed_mbps': (
|
||||
speed / (1024 * 1024) if speed else None
|
||||
),
|
||||
'eta_seconds': eta,
|
||||
}
|
||||
else:
|
||||
# Fallback for old-style float progress
|
||||
progress = float(progress_info)
|
||||
web_progress_dict = {
|
||||
'percent': progress,
|
||||
'downloaded_mb': 0.0,
|
||||
'total_mb': None,
|
||||
'speed_mbps': None,
|
||||
'eta_seconds': None,
|
||||
}
|
||||
|
||||
# Notify progress via new callback system
|
||||
self._callback_manager.notify_progress(
|
||||
@@ -281,13 +314,14 @@ class SeriesApp:
|
||||
)
|
||||
)
|
||||
|
||||
# Call legacy callback if provided
|
||||
# Call callback with web API format
|
||||
# (dict with detailed progress info)
|
||||
if callback:
|
||||
callback(progress)
|
||||
callback(web_progress_dict)
|
||||
|
||||
# Propagate progress into the legacy callback chain so existing
|
||||
# UI surfaces continue to receive updates without rewriting the
|
||||
# old interfaces.
|
||||
# Propagate progress into the legacy callback chain so
|
||||
# existing UI surfaces continue to receive updates without
|
||||
# rewriting the old interfaces.
|
||||
# Call legacy progress_callback if provided
|
||||
if self.progress_callback:
|
||||
self.progress_callback(ProgressInfo(
|
||||
|
||||
Reference in New Issue
Block a user