fix percentage

This commit is contained in:
2025-11-01 18:46:53 +01:00
parent 0b5faeffc9
commit 9fce617949
4 changed files with 106 additions and 68 deletions

View File

@@ -245,6 +245,8 @@ class SeriesApp:
# event-driven progress reporting with the legacy callback API that
# the CLI still relies on.
def wrapped_callback(progress_info):
logger.debug(f"wrapped_callback called with: {progress_info}")
if self._is_cancelled():
raise InterruptedError("Download cancelled by user")
@@ -267,6 +269,11 @@ class SeriesApp:
speed = progress_info.get('speed', 0) # bytes/sec
eta = progress_info.get('eta') # seconds
logger.debug(
f"Progress calculation: {downloaded}/{total_bytes} = "
f"{progress:.1f}%, speed={speed}, eta={eta}"
)
# Convert to expected format for web API callback
# Web API expects: percent, downloaded_mb, total_mb,
# speed_mbps, eta_seconds
@@ -295,6 +302,7 @@ class SeriesApp:
'speed_mbps': None,
'eta_seconds': None,
}
logger.debug(f"Old-style progress: {progress}%")
# Notify progress via new callback system
self._callback_manager.notify_progress(
@@ -317,6 +325,7 @@ class SeriesApp:
# Call callback with web API format
# (dict with detailed progress info)
if callback:
logger.debug(f"Calling progress callback: {web_progress_dict}")
callback(web_progress_dict)
# Propagate progress into the legacy callback chain so

View File

@@ -261,26 +261,59 @@ class AniworldLoader(Loader):
ydl_opts['http_headers'] = header
logging.debug("Using custom headers for download")
if progress_callback:
ydl_opts['progress_hooks'] = [progress_callback]
# Wrap the callback to add logging
def logged_progress_callback(d):
logging.debug(
f"YT-DLP progress: status={d.get('status')}, "
f"downloaded={d.get('downloaded_bytes')}, "
f"total={d.get('total_bytes')}, "
f"speed={d.get('speed')}"
)
progress_callback(d)
ydl_opts['progress_hooks'] = [logged_progress_callback]
logging.debug("Progress callback registered with YT-DLP")
try:
logging.debug("Starting YoutubeDL download")
logging.debug(f"Download link: {link[:100]}...")
logging.debug(f"YDL options: {ydl_opts}")
with YoutubeDL(ydl_opts) as ydl:
ydl.download([link])
info = ydl.extract_info(link, download=True)
logging.debug(
f"Download info: "
f"title={info.get('title')}, "
f"filesize={info.get('filesize')}"
)
if os.path.exists(temp_path):
logging.debug("Moving file from temp to final destination")
shutil.copy(temp_path, output_path)
os.remove(temp_path)
logging.info(f"Download completed successfully: {output_file}")
logging.info(
f"Download completed successfully: {output_file}"
)
self.clear_cache()
return True
else:
logging.error(f"Download failed: temp file not found at {temp_path}")
logging.error(
f"Download failed: temp file not found at {temp_path}"
)
self.clear_cache()
return False
except BrokenPipeError as e:
logging.error(
f"Broken pipe error with provider {provider}: {e}. "
f"This usually means the stream connection was closed."
)
# Try next provider if available
continue
except Exception as e:
logging.error(f"YoutubeDL download failed: {e}")
logging.error(
f"YoutubeDL download failed with provider {provider}: "
f"{type(e).__name__}: {e}"
)
# Try next provider if available
continue
break