mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-06 16:07:01 +08:00
fix AddDownloadAction
This commit is contained in:
+10
-2
@@ -10,6 +10,9 @@ class BaseAction(BaseModel, ABC):
|
|||||||
工作流动作基类
|
工作流动作基类
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# 完成标志
|
||||||
|
_done_flag = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
@@ -28,12 +31,11 @@ class BaseAction(BaseModel, ABC):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
|
||||||
def done(self) -> bool:
|
def done(self) -> bool:
|
||||||
"""
|
"""
|
||||||
判断动作是否完成
|
判断动作是否完成
|
||||||
"""
|
"""
|
||||||
pass
|
return self._done_flag
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
@@ -42,3 +44,9 @@ class BaseAction(BaseModel, ABC):
|
|||||||
判断动作是否成功
|
判断动作是否成功
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def job_done(self):
|
||||||
|
"""
|
||||||
|
标记动作完成
|
||||||
|
"""
|
||||||
|
self._done_flag = True
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
|
from pydantic import Field
|
||||||
|
|
||||||
from app.actions import BaseAction
|
from app.actions import BaseAction
|
||||||
from app.schemas import ActionParams, ActionContext
|
from app.chain.download import DownloadChain
|
||||||
|
from app.chain.media import MediaChain
|
||||||
|
from app.core.metainfo import MetaInfo
|
||||||
|
from app.log import logger
|
||||||
|
from app.schemas import ActionParams, ActionContext, DownloadTask
|
||||||
|
|
||||||
|
|
||||||
class AddDownloadParams(ActionParams):
|
class AddDownloadParams(ActionParams):
|
||||||
"""
|
"""
|
||||||
添加下载资源参数
|
添加下载资源参数
|
||||||
"""
|
"""
|
||||||
pass
|
downloader: str = Field(None, description="下载器")
|
||||||
|
save_path: str = Field(None, description="保存路径")
|
||||||
|
|
||||||
|
|
||||||
class AddDownloadAction(BaseAction):
|
class AddDownloadAction(BaseAction):
|
||||||
@@ -14,6 +21,9 @@ class AddDownloadAction(BaseAction):
|
|||||||
添加下载资源
|
添加下载资源
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# 已添加的下载
|
||||||
|
_added_downloads = []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
return "添加下载资源"
|
return "添加下载资源"
|
||||||
@@ -22,13 +32,32 @@ class AddDownloadAction(BaseAction):
|
|||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
return "根据资源列表添加下载任务"
|
return "根据资源列表添加下载任务"
|
||||||
|
|
||||||
@property
|
|
||||||
def done(self) -> bool:
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return True
|
return True if self._added_downloads else False
|
||||||
|
|
||||||
async def execute(self, params: AddDownloadParams, context: ActionContext) -> ActionContext:
|
async def execute(self, params: AddDownloadParams, context: ActionContext) -> ActionContext:
|
||||||
pass
|
"""
|
||||||
|
将上下文中的torrents添加到下载任务中
|
||||||
|
"""
|
||||||
|
for t in context.torrents:
|
||||||
|
if not t.meta_info:
|
||||||
|
t.meta_info = MetaInfo(title=t.title, subtitle=t.description)
|
||||||
|
if not t.media_info:
|
||||||
|
t.media_info = MediaChain().recognize_media(meta=t.meta_info)
|
||||||
|
if not t.media_info:
|
||||||
|
logger.warning(f"{t.title} 未识别到媒体信息,无法下载")
|
||||||
|
continue
|
||||||
|
did = DownloadChain().download_single(context=t,
|
||||||
|
downloader=params.downloader,
|
||||||
|
save_path=params.save_path)
|
||||||
|
if did:
|
||||||
|
self._added_downloads.append(did)
|
||||||
|
|
||||||
|
if self._added_downloads:
|
||||||
|
logger.info(f"已添加 {len(self._added_downloads)} 个下载任务")
|
||||||
|
context.downloads.extend(
|
||||||
|
[DownloadTask(download_id=did, downloader=params.downloader) for did in self._added_downloads]
|
||||||
|
)
|
||||||
|
self.job_done()
|
||||||
|
return context
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ class AddSubscribeAction(BaseAction):
|
|||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
return "根据媒体列表添加订阅"
|
return "根据媒体列表添加订阅"
|
||||||
|
|
||||||
@property
|
|
||||||
def done(self) -> bool:
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ class FetchDownloadsAction(BaseAction):
|
|||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
return "获取下载任务,更新任务状态"
|
return "获取下载任务,更新任务状态"
|
||||||
|
|
||||||
@property
|
|
||||||
def done(self) -> bool:
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ class FetchMediasAction(BaseAction):
|
|||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
return "获取媒体数据"
|
return "获取媒体数据"
|
||||||
|
|
||||||
@property
|
|
||||||
def done(self) -> bool:
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -30,13 +30,9 @@ class FetchRssAction(BaseAction):
|
|||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
return "请求RSS地址获取数据,并解析为资源列表"
|
return "请求RSS地址获取数据,并解析为资源列表"
|
||||||
|
|
||||||
async def execute(self, params: FetchRssParams, context: ActionContext) -> ActionContext:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@property
|
|
||||||
def done(self) -> bool:
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
async def execute(self, params: FetchRssParams, context: ActionContext) -> ActionContext:
|
||||||
|
pass
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ class FilterMediasAction(BaseAction):
|
|||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
return "过滤媒体数据列表"
|
return "过滤媒体数据列表"
|
||||||
|
|
||||||
@property
|
|
||||||
def done(self) -> bool:
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ class FilterTorrentsAction(BaseAction):
|
|||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
return "过滤资源数据列表"
|
return "过滤资源数据列表"
|
||||||
|
|
||||||
@property
|
|
||||||
def done(self) -> bool:
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ class ScrapeFileAction(BaseAction):
|
|||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
return "刮削媒体信息和图片"
|
return "刮削媒体信息和图片"
|
||||||
|
|
||||||
@property
|
|
||||||
def done(self) -> bool:
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -30,10 +30,6 @@ class SearchTorrentsAction(BaseAction):
|
|||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
return "根据关键字搜索站点种子资源"
|
return "根据关键字搜索站点种子资源"
|
||||||
|
|
||||||
@property
|
|
||||||
def done(self) -> bool:
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ class SendEventAction(BaseAction):
|
|||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
return "发送特定事件"
|
return "发送特定事件"
|
||||||
|
|
||||||
@property
|
|
||||||
def done(self) -> bool:
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ class SendMessageAction(BaseAction):
|
|||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
return "发送特定消息"
|
return "发送特定消息"
|
||||||
|
|
||||||
@property
|
|
||||||
def done(self) -> bool:
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ class TransferFileAction(BaseAction):
|
|||||||
def description(self) -> str:
|
def description(self) -> str:
|
||||||
return "整理和转移文件"
|
return "整理和转移文件"
|
||||||
|
|
||||||
@property
|
|
||||||
def done(self) -> bool:
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def success(self) -> bool:
|
def success(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user