fix percentage
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user