Fix: Add graceful download cancellation on Ctrl+C

- Add cancellation flag to AniworldLoader with request_cancel/reset_cancel/is_cancelled methods
- Update base_provider.Loader interface with cancellation abstract methods
- Integrate cancellation check in YT-DLP progress hooks
- Add request_download_cancel method to SeriesApp and AnimeService
- Update DownloadService.stop() to request cancellation before shutdown
- Clean up temp files on cancellation
This commit is contained in:
2025-12-27 19:31:57 +01:00
parent 778d16b21a
commit 08f816a954
14 changed files with 145 additions and 900 deletions

View File

@@ -72,6 +72,21 @@ class AnimeService:
logger.exception("Failed to subscribe to SeriesApp events")
raise AnimeServiceError("Initialization failed") from e
def request_download_cancel(self) -> None:
"""Request cancellation of any ongoing download.
This method signals the underlying download provider to stop
any active downloads. The cancellation happens asynchronously
via progress hooks in the downloader.
Should be called during shutdown to stop in-progress downloads.
"""
logger.info("Requesting download cancellation via AnimeService")
try:
self._app.request_download_cancel()
except Exception as e:
logger.warning("Failed to request download cancellation: %s", e)
def _on_download_status(self, args) -> None:
"""Handle download status events from SeriesApp.

View File

@@ -1012,6 +1012,13 @@ class DownloadService:
self._is_shutting_down = True
self._is_stopped = True
# Request cancellation from AnimeService (signals the download thread)
try:
self._anime_service.request_download_cancel()
logger.info("Requested download cancellation from AnimeService")
except Exception as e:
logger.warning("Failed to request download cancellation: %s", e)
# Persist active download back to pending state if one exists
if self._active_download:
logger.info(