mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-28 03:27:31 +08:00
fix actions
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from pydantic.main import BaseModel
|
||||
|
||||
from app.chain import ChainBase
|
||||
from app.schemas import ActionContext, ActionParams
|
||||
|
||||
@@ -10,7 +8,7 @@ class ActionChain(ChainBase):
|
||||
pass
|
||||
|
||||
|
||||
class BaseAction(BaseModel, ABC):
|
||||
class BaseAction(ABC):
|
||||
"""
|
||||
工作流动作基类
|
||||
"""
|
||||
@@ -18,10 +16,6 @@ class BaseAction(BaseModel, ABC):
|
||||
# 完成标志
|
||||
_done_flag = False
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.chain = ActionChain()
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def name(self) -> str:
|
||||
@@ -32,6 +26,11 @@ class BaseAction(BaseModel, ABC):
|
||||
def description(self) -> str:
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def data(self) -> dict:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def execute(self, params: ActionParams, context: ActionContext) -> ActionContext:
|
||||
"""
|
||||
|
||||
@@ -37,6 +37,10 @@ class AddDownloadAction(BaseAction):
|
||||
def description(self) -> str:
|
||||
return "根据资源列表添加下载任务"
|
||||
|
||||
@property
|
||||
def data(self) -> dict:
|
||||
return AddDownloadParams().dict()
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self._added_downloads else False
|
||||
|
||||
@@ -33,6 +33,10 @@ class AddSubscribeAction(BaseAction):
|
||||
def description(self) -> str:
|
||||
return "根据媒体列表添加订阅"
|
||||
|
||||
@property
|
||||
def data(self) -> dict:
|
||||
return AddSubscribeParams().dict()
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self._added_subscribes else False
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from app.actions import BaseAction
|
||||
from app.actions import BaseAction, ActionChain
|
||||
from app.schemas import ActionParams, ActionContext
|
||||
from app.log import logger
|
||||
|
||||
@@ -17,6 +17,10 @@ class FetchDownloadsAction(BaseAction):
|
||||
|
||||
_downloads = []
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.chain = ActionChain()
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return "获取下载任务"
|
||||
@@ -25,6 +29,10 @@ class FetchDownloadsAction(BaseAction):
|
||||
def description(self) -> str:
|
||||
return "获取下载任务,更新任务状态"
|
||||
|
||||
@property
|
||||
def data(self) -> dict:
|
||||
return FetchDownloadsParams().dict()
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
if not self._downloads:
|
||||
|
||||
@@ -89,6 +89,10 @@ class FetchMediasAction(BaseAction):
|
||||
def description(self) -> str:
|
||||
return "获取媒体数据"
|
||||
|
||||
@property
|
||||
def data(self) -> dict:
|
||||
return FetchMediasParams().dict()
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self.__medias else False
|
||||
|
||||
@@ -2,7 +2,7 @@ from typing import Optional
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from app.actions import BaseAction
|
||||
from app.actions import BaseAction, ActionChain
|
||||
from app.core.config import settings
|
||||
from app.core.context import Context
|
||||
from app.core.metainfo import MetaInfo
|
||||
@@ -33,6 +33,7 @@ class FetchRssAction(BaseAction):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.rsshelper = RssHelper()
|
||||
self.chain = ActionChain()
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
@@ -42,6 +43,10 @@ class FetchRssAction(BaseAction):
|
||||
def description(self) -> str:
|
||||
return "请求RSS地址获取数据,并解析为资源列表"
|
||||
|
||||
@property
|
||||
def data(self) -> dict:
|
||||
return FetchRssParams().dict()
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self._rss_torrents else False
|
||||
|
||||
@@ -38,6 +38,10 @@ class FetchTorrentsAction(BaseAction):
|
||||
def description(self) -> str:
|
||||
return "根据关键字搜索站点种子资源"
|
||||
|
||||
@property
|
||||
def data(self) -> dict:
|
||||
return FetchTorrentsParams().dict()
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self._torrents else False
|
||||
@@ -55,7 +59,7 @@ class FetchTorrentsAction(BaseAction):
|
||||
if params.season and torrent.meta_info.begin_season != params.season:
|
||||
continue
|
||||
# 识别媒体信息
|
||||
torrent.media_info = self.chain.recognize_media(torrent.meta_info)
|
||||
torrent.media_info = self.searchchain.recognize_media(torrent.meta_info)
|
||||
if not torrent.media_info:
|
||||
logger.warning(f"{torrent.torrent_info.title} 未识别到媒体信息")
|
||||
continue
|
||||
|
||||
@@ -32,6 +32,10 @@ class FilterMediasAction(BaseAction):
|
||||
def description(self) -> str:
|
||||
return "过滤媒体数据列表"
|
||||
|
||||
@property
|
||||
def data(self) -> dict:
|
||||
return FilterMediasParams().dict()
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self.__medias else False
|
||||
|
||||
@@ -2,7 +2,7 @@ from typing import Optional, List
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from app.actions import BaseAction
|
||||
from app.actions import BaseAction, ActionChain
|
||||
from app.helper.torrent import TorrentHelper
|
||||
from app.schemas import ActionParams, ActionContext
|
||||
|
||||
@@ -30,6 +30,7 @@ class FilterTorrentsAction(BaseAction):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.torrenthelper = TorrentHelper()
|
||||
self.chain = ActionChain()
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
@@ -39,6 +40,10 @@ class FilterTorrentsAction(BaseAction):
|
||||
def description(self) -> str:
|
||||
return "过滤资源数据列表"
|
||||
|
||||
@property
|
||||
def data(self) -> dict:
|
||||
return FilterTorrentsParams().dict()
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return self.done
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from pathlib import Path
|
||||
|
||||
from app.actions import BaseAction
|
||||
from app.schemas import ActionParams, ActionContext
|
||||
from app.chain.media import MediaChain
|
||||
@@ -33,6 +35,10 @@ class ScrapeFileAction(BaseAction):
|
||||
def description(self) -> str:
|
||||
return "刮削媒体信息和图片"
|
||||
|
||||
@property
|
||||
def data(self) -> dict:
|
||||
return ScrapeFileParams().dict()
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self.__scraped_files else False
|
||||
@@ -46,8 +52,8 @@ class ScrapeFileAction(BaseAction):
|
||||
continue
|
||||
if not self.storagechain.exists(fileitem):
|
||||
continue
|
||||
meta = MetaInfoPath(fileitem.path)
|
||||
mediainfo = self.chain.recognize_media(meta)
|
||||
meta = MetaInfoPath(Path(fileitem.path))
|
||||
mediainfo = self.mediachain.recognize_media(meta)
|
||||
if not mediainfo:
|
||||
logger.info(f"{fileitem.path} 未识别到媒体信息,无法刮削")
|
||||
continue
|
||||
|
||||
@@ -27,6 +27,10 @@ class SendEventAction(BaseAction):
|
||||
def description(self) -> str:
|
||||
return "发送特定事件"
|
||||
|
||||
@property
|
||||
def data(self) -> dict:
|
||||
return SendEventParams().dict()
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return self.__success
|
||||
|
||||
@@ -2,7 +2,7 @@ from typing import List, Optional, Union
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from app.actions import BaseAction
|
||||
from app.actions import BaseAction, ActionChain
|
||||
from app.schemas import ActionParams, ActionContext, MessageChannel
|
||||
|
||||
|
||||
@@ -19,6 +19,10 @@ class SendMessageAction(BaseAction):
|
||||
发送消息
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.chain = ActionChain()
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return "发送消息"
|
||||
@@ -27,6 +31,10 @@ class SendMessageAction(BaseAction):
|
||||
def description(self) -> str:
|
||||
return "发送特定消息"
|
||||
|
||||
@property
|
||||
def data(self) -> dict:
|
||||
return SendMessageParams().dict()
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return self.done
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from pathlib import Path
|
||||
|
||||
from app.actions import BaseAction
|
||||
from app.schemas import ActionParams, ActionContext
|
||||
from app.chain.storage import StorageChain
|
||||
@@ -32,6 +34,10 @@ class TransferFileAction(BaseAction):
|
||||
def description(self) -> str:
|
||||
return "整理和转移文件"
|
||||
|
||||
@property
|
||||
def data(self) -> dict:
|
||||
return TransferFileParams().dict()
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return True if self.__fileitems else False
|
||||
@@ -44,7 +50,7 @@ class TransferFileAction(BaseAction):
|
||||
if not download.completed:
|
||||
logger.info(f"下载任务 {download.download_id} 未完成")
|
||||
continue
|
||||
fileitem = self.storagechain.get_file_item(storage="local", path=download.path)
|
||||
fileitem = self.storagechain.get_file_item(storage="local", path=Path(download.path))
|
||||
if not fileitem:
|
||||
logger.info(f"文件 {download.path} 不存在")
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user