mirror of
https://github.com/Yuvi9587/Kemono-Downloader.git
synced 2025-12-29 16:14:44 +00:00
45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
import threading
|
|
from PyQt5.QtCore import QThread, pyqtSignal
|
|
|
|
from ...core.mangadex_client import fetch_mangadex_data
|
|
|
|
|
|
class MangaDexDownloadThread(QThread):
|
|
"""A wrapper QThread for running the MangaDex client function."""
|
|
progress_signal = pyqtSignal(str)
|
|
file_progress_signal = pyqtSignal(str, object)
|
|
finished_signal = pyqtSignal(int, int, bool)
|
|
overall_progress_signal = pyqtSignal(int, int)
|
|
|
|
def __init__(self, url, output_dir, parent=None):
|
|
super().__init__(parent)
|
|
self.start_url = url
|
|
self.output_dir = output_dir
|
|
self.is_cancelled = False
|
|
self.pause_event = parent.pause_event if hasattr(parent, 'pause_event') else threading.Event()
|
|
self.cancellation_event = parent.cancellation_event if hasattr(parent, 'cancellation_event') else threading.Event()
|
|
|
|
def run(self):
|
|
downloaded = 0
|
|
skipped = 0
|
|
try:
|
|
downloaded, skipped = fetch_mangadex_data(
|
|
self.start_url,
|
|
self.output_dir,
|
|
logger_func=self.progress_signal.emit,
|
|
file_progress_callback=self.file_progress_signal,
|
|
overall_progress_callback=self.overall_progress_signal,
|
|
pause_event=self.pause_event,
|
|
cancellation_event=self.cancellation_event
|
|
)
|
|
except Exception as e:
|
|
self.progress_signal.emit(f"❌ A critical error occurred in the MangaDex thread: {e}")
|
|
skipped = 1 # Mark as skipped if there was a critical failure
|
|
finally:
|
|
self.finished_signal.emit(downloaded, skipped, self.is_cancelled)
|
|
|
|
def cancel(self):
|
|
self.is_cancelled = True
|
|
if self.cancellation_event:
|
|
self.cancellation_event.set()
|
|
self.progress_signal.emit(" Cancellation signal received by MangaDex thread.") |