Skip to content

The only downloader you need. 下载器的集大成者。

fix: 修复任务接口重构后的兼容问题

XiaoYouChR9648a67194a8
diff --git a/features/bittorrent_pack/cards.py b/features/bittorrent_pack/cards.py
index e955a3e0..f1fde996 100644
--- a/features/bittorrent_pack/cards.py
+++ b/features/bittorrent_pack/cards.py
@@ -24,7 +24,7 @@ from app.view.components.cards import ResultCard, UniversalTaskCard
from app.view.components.dialogs import FileSelectDialog
from app.view.components.labels import IconBodyLabel
-from .task import BitTorrentFile, BitTorrentTask
+from .task import BTFile, BTTask
def _removePath(path: Path):
@@ -36,7 +36,7 @@ def _removePath(path: Path):
path.unlink(missing_ok=True)
-def _openFileSelection(task: BitTorrentTask, parent) -> set[int] | None:
+def _openFileSelection(task: BTTask, parent) -> set[int] | None:
dialog = TorrentFileSelectDialog(task, parent)
try:
if not dialog.exec():
@@ -49,19 +49,19 @@ def _openFileSelection(task: BitTorrentTask, parent) -> set[int] | None:
class TorrentFileSelectDialog(FileSelectDialog):
- def __init__(self, task: BitTorrentTask, parent=None):
+ def __init__(self, task: BTTask, parent=None):
super().__init__(task, parent)
- self.task: BitTorrentTask = task
+ self.task: BTTask = task
- def _fileDisplayPath(self, file: BitTorrentFile) -> str:
+ def _fileDisplayPath(self, file: BTFile) -> str:
return self.task.mappedRelativePath(file)
- def _fileTypePath(self, file: BitTorrentFile) -> str:
+ def _fileTypePath(self, file: BTFile) -> str:
return file.path
class BitTorrentResultCard(ResultCard):
- def __init__(self, task: BitTorrentTask, parent: QWidget = None):
+ def __init__(self, task: BTTask, parent: QWidget = None):
super().__init__(task, parent)
self.task = task
@@ -118,14 +118,14 @@ class BitTorrentResultCard(ResultCard):
if _openFileSelection(self.task, self.window()) is not None:
self._refreshSummary()
- def getTask(self) -> BitTorrentTask:
+ def getTask(self) -> BTTask:
return self.task
-class BitTorrentTaskCard(UniversalTaskCard):
- def __init__(self, task: BitTorrentTask, parent=None):
+class BTTaskCard(UniversalTaskCard):
+ def __init__(self, task: BTTask, parent=None):
super().__init__(task, parent)
- self.task: BitTorrentTask = task
+ self.task: BTTask = task
self.speedLabel.setIcon(FluentIcon.DOWNLOAD)
self.uploadRateLabel = IconBodyLabel("", FluentIcon.SHARE, self)
self.infoLayout.insertWidget(self.infoLayout.indexOf(self.leftTimeLabel), self.uploadRateLabel)
diff --git a/features/bittorrent_pack/pack.py b/features/bittorrent_pack/pack.py
index c72b098e..2890750b 100644
--- a/features/bittorrent_pack/pack.py
+++ b/features/bittorrent_pack/pack.py
@@ -6,7 +6,7 @@ from app.bases.interfaces import FeaturePack
from app.bases.models import Task
from app.services.core_service import coreService
-from .cards import BitTorrentResultCard, BitTorrentTaskCard
+from .cards import BitTorrentResultCard, BTTaskCard
from .config import bittorrentConfig, getCachedWebTrackers, refreshConfiguredWebTrackers
from .task import BTTask, parse, resolveLocalTorrentPath
@@ -48,7 +48,7 @@ class BitTorrentPack(FeaturePack):
raise NotImplementedError("Use resolve() for BitTorrent tasks")
def taskCard(self, task, parent=None):
- return BitTorrentTaskCard(task, parent)
+ return BTTaskCard(task, parent)
def resultCard(self, task, parent=None):
return BitTorrentResultCard(task, parent)
diff --git a/features/bittorrent_pack/task.py b/features/bittorrent_pack/task.py
index 59d8ea13..54cff839 100644
--- a/features/bittorrent_pack/task.py
+++ b/features/bittorrent_pack/task.py
@@ -286,8 +286,8 @@ class BTStage(TaskStage):
self.downloadRate = 0
self.uploadRate = 0
- def reset(self, notifyTask: bool = True):
- super().reset(notifyTask=notifyTask)
+ def reset(self, sync: bool = True):
+ super().reset(sync=sync)
self.stateText = ""
self.peerCount = 0
self.seedCount = 0
@@ -295,7 +295,7 @@ class BTStage(TaskStage):
self.uploadRate = 0
-@dataclass
+@dataclass(kw_only=True)
class BTTask(Task):
sourceType: str
torrentData: str
diff --git a/features/ftp_pack/task.py b/features/ftp_pack/task.py
index 78f41e3b..874dc6c9 100644
--- a/features/ftp_pack/task.py
+++ b/features/ftp_pack/task.py
@@ -127,14 +127,14 @@ class FtpTaskStage(TaskStage):
fileIndex: int
remotePath: str
fileSize: int
- resolvePath: str
+ outputFile: str
supportsRange: bool = field(default=True)
accelerated: bool = field(default=False)
- def setStatus(self, status: TaskStatus, notifyTask: bool = True):
+ def setStatus(self, status: TaskStatus, sync: bool = True):
if status == TaskStatus.COMPLETED:
self.receivedBytes = self.fileSize
- super().setStatus(status, notifyTask=notifyTask)
+ super().setStatus(status, sync=sync)
@dataclass(kw_only=True)
@@ -263,8 +263,8 @@ class FtpTask(Task):
if stage.status == TaskStatus.COMPLETED:
continue
if status == TaskStatus.RUNNING and stage.status == TaskStatus.FAILED:
- stage.reset(notifyTask=False)
- stage.setStatus(status, notifyTask=False)
+ stage.reset(sync=False)
+ stage.setStatus(status, sync=False)
return self.updateStatus()
@@ -273,7 +273,7 @@ class FtpTask(Task):
file.downloadedBytes = 0
file.completed = False
for stage in self.stages:
- stage.reset(notifyTask=False)
+ stage.reset(sync=False)
return self.updateStatus()
def reopenForAdditionalFiles(self) -> bool:
@@ -287,7 +287,7 @@ class FtpTask(Task):
return False
for stage in pendingSelectedStages:
- stage.setStatus(TaskStatus.PAUSED, notifyTask=False)
+ stage.setStatus(TaskStatus.PAUSED, sync=False)
self._syncFileProgress()
self.updateStatus()
diff --git a/features/m3u8_pack/cards.py b/features/m3u8_pack/cards.py
index a5c314d0..f745a71f 100644
--- a/features/m3u8_pack/cards.py
+++ b/features/m3u8_pack/cards.py
@@ -6,12 +6,10 @@ from PySide6.QtGui import QMouseEvent
from PySide6.QtWidgets import QFileIconProvider, QHBoxLayout, QWidget
from qfluentwidgets import BodyLabel, ImageLabel, LineEdit, StrongBodyLabel
-from app.bases.models import TaskStatus
+from app.bases.models import Task, TaskStatus
from app.supports.utils import getReadableSize, getReadableTime
from app.view.components.cards import ResultCard, UniversalTaskCard
-from .task import M3U8InstallTask, M3U8Task
-
def _removeFile(path: Path):
try:
@@ -77,11 +75,11 @@ class M3U8TaskCard(UniversalTaskCard):
task = self.task
_removeFile(Path(task.outputFolder))
- shutil.rmtree(Path(task.tempDir), ignore_errors=True)
+ shutil.rmtree(Path(task.metadata.get('tempDir', '')), ignore_errors=True)
outputDirectory = Path(task.path)
if outputDirectory.exists():
- prefix = f"{task.saveName}."
+ prefix = f"{task.title}."
for candidate in outputDirectory.iterdir():
if candidate.name == Path(task.outputFolder).name:
continue
@@ -94,15 +92,16 @@ class M3U8InstallTaskCard(UniversalTaskCard):
if not completely:
return
- if isinstance(self.task, M3U8InstallTask):
- shutil.rmtree(self.task.installFolder, ignore_errors=True)
+ installFolder = self.task.metadata.get("installFolder")
+ if installFolder:
+ shutil.rmtree(installFolder, ignore_errors=True)
return
super().onTaskDeleted(completely)
class M3U8ResultCard(ResultCard):
- def __init__(self, task: M3U8Task, parent: QWidget = None):
+ def __init__(self, task: Task, parent: QWidget = None):
super().__init__(task, parent)
self.task = task
self.iconLabel = ImageLabel(self)
@@ -133,8 +132,8 @@ class M3U8ResultCard(ResultCard):
self.mainLayout.addWidget(self.metaLabel)
def _metaText(self) -> str:
- manifestText = "DASH" if self.task.manifestType == "mpd" else "HLS"
- modeText = self.tr("直播") if self.task.isLive else self.tr("点播")
+ manifestText = "DASH" if self.task.metadata.get('manifestType', 'm3u8') == "mpd" else "HLS"
+ modeText = self.tr("直播") if self.task.metadata.get('isLive', False) else self.tr("点播")
return f"{manifestText} · {modeText}"
def _refreshIcon(self):
@@ -167,5 +166,5 @@ class M3U8ResultCard(ResultCard):
self.filenameEdit.hide()
self.filenameLabel.show()
- def getTask(self) -> M3U8Task:
+ def getTask(self) -> Task:
return self.task