fix not downloading
This commit is contained in:
@@ -244,10 +244,25 @@ class SeriesApp:
|
||||
# Wrap callback to enforce cancellation checks and bridge the new
|
||||
# event-driven progress reporting with the legacy callback API that
|
||||
# the CLI still relies on.
|
||||
def wrapped_callback(progress: float):
|
||||
def wrapped_callback(progress_info):
|
||||
if self._is_cancelled():
|
||||
raise InterruptedError("Download cancelled by user")
|
||||
|
||||
# yt-dlp passes a dict with progress information
|
||||
# Extract percentage from the dict
|
||||
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)
|
||||
|
||||
if total > 0:
|
||||
progress = (downloaded / total) * 100
|
||||
else:
|
||||
progress = 0
|
||||
else:
|
||||
# Fallback for old-style float progress
|
||||
progress = float(progress_info)
|
||||
|
||||
# Notify progress via new callback system
|
||||
self._callback_manager.notify_progress(
|
||||
ProgressContext(
|
||||
@@ -284,7 +299,7 @@ class SeriesApp:
|
||||
))
|
||||
|
||||
# Perform download
|
||||
self.loader.download(
|
||||
download_success = self.loader.download(
|
||||
self.directory_to_search,
|
||||
serieFolder,
|
||||
season,
|
||||
@@ -294,6 +309,12 @@ class SeriesApp:
|
||||
wrapped_callback
|
||||
)
|
||||
|
||||
# Check if download was successful
|
||||
if not download_success:
|
||||
raise RuntimeError(
|
||||
f"Download failed for S{season:02d}E{episode:02d}"
|
||||
)
|
||||
|
||||
self._operation_status = OperationStatus.COMPLETED
|
||||
logger.info(
|
||||
"Download completed: %s S%02dE%02d",
|
||||
|
||||
@@ -247,7 +247,7 @@ class AniworldLoader(Loader):
|
||||
link, header = self._get_direct_link_from_provider(
|
||||
season, episode, key, language
|
||||
)
|
||||
logging.debug(f"Direct link obtained from provider")
|
||||
logging.debug("Direct link obtained from provider")
|
||||
ydl_opts = {
|
||||
'fragment_retries': float('inf'),
|
||||
'outtmpl': temp_path,
|
||||
@@ -259,22 +259,36 @@ class AniworldLoader(Loader):
|
||||
|
||||
if header:
|
||||
ydl_opts['http_headers'] = header
|
||||
logging.debug(f"Using custom headers for download")
|
||||
logging.debug("Using custom headers for download")
|
||||
if progress_callback:
|
||||
ydl_opts['progress_hooks'] = [progress_callback]
|
||||
|
||||
logging.debug(f"Starting YoutubeDL download")
|
||||
with YoutubeDL(ydl_opts) as ydl:
|
||||
ydl.download([link])
|
||||
try:
|
||||
logging.debug("Starting YoutubeDL download")
|
||||
with YoutubeDL(ydl_opts) as ydl:
|
||||
ydl.download([link])
|
||||
|
||||
if os.path.exists(temp_path):
|
||||
logging.debug(f"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}")
|
||||
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}")
|
||||
self.clear_cache()
|
||||
return True
|
||||
else:
|
||||
logging.error(f"Download failed: temp file not found at {temp_path}")
|
||||
self.clear_cache()
|
||||
return False
|
||||
except Exception as e:
|
||||
logging.error(f"YoutubeDL download failed: {e}")
|
||||
# Try next provider if available
|
||||
continue
|
||||
break
|
||||
|
||||
# If we get here, all providers failed
|
||||
logging.error("All download providers failed")
|
||||
self.clear_cache()
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_site_key(self) -> str:
|
||||
"""Get the site key for this provider."""
|
||||
|
||||
Reference in New Issue
Block a user