mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-27 11:11:07 +08:00
feat:支持文件整理存储操作事件
This commit is contained in:
@@ -198,7 +198,7 @@ def seasons(mediaid: Optional[str] = None,
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/{mediaid}", summary="查询媒体详情", response_model=schemas.MediaInfo)
|
@router.get("/{mediaid}", summary="查询媒体详情", response_model=schemas.MediaInfo)
|
||||||
def detail(mediaid: str, type_name: str, title: Optional[str] = None, year: int = None,
|
def detail(mediaid: str, type_name: str, title: Optional[str] = None, year: str = None,
|
||||||
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
"""
|
"""
|
||||||
根据媒体ID查询themoviedb或豆瓣媒体信息,type_name: 电影/电视剧
|
根据媒体ID查询themoviedb或豆瓣媒体信息,type_name: 电影/电视剧
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from app.core.config import settings
|
|||||||
from app.helper.directory import DirectoryHelper
|
from app.helper.directory import DirectoryHelper
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.schemas import MediaType
|
from app.schemas import MediaType
|
||||||
|
from helper.storage import StorageHelper
|
||||||
|
|
||||||
|
|
||||||
class StorageChain(ChainBase):
|
class StorageChain(ChainBase):
|
||||||
@@ -17,6 +18,7 @@ class StorageChain(ChainBase):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.directoryhelper = DirectoryHelper()
|
self.directoryhelper = DirectoryHelper()
|
||||||
|
self.storagehelper = StorageHelper()
|
||||||
|
|
||||||
def save_config(self, storage: str, conf: dict) -> None:
|
def save_config(self, storage: str, conf: dict) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -181,3 +183,10 @@ class StorageChain(ChainBase):
|
|||||||
return self.delete_file(dir_item)
|
return self.delete_file(dir_item)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def get_storage(self, storage: str) -> Optional[schemas.StorageConf]:
|
||||||
|
"""
|
||||||
|
获取存储对象
|
||||||
|
"""
|
||||||
|
return self.storagehelper.get_storage(storage=storage)
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,11 @@ from app.log import logger
|
|||||||
from app.schemas import TransferInfo, TransferTorrent, Notification, EpisodeFormat, FileItem, TransferDirectoryConf, \
|
from app.schemas import TransferInfo, TransferTorrent, Notification, EpisodeFormat, FileItem, TransferDirectoryConf, \
|
||||||
TransferTask, TransferQueue, TransferJob, TransferJobTask
|
TransferTask, TransferQueue, TransferJob, TransferJobTask
|
||||||
from app.schemas.types import TorrentStatus, EventType, MediaType, ProgressKey, NotificationType, MessageChannel, \
|
from app.schemas.types import TorrentStatus, EventType, MediaType, ProgressKey, NotificationType, MessageChannel, \
|
||||||
SystemConfigKey
|
SystemConfigKey, ChainEventType
|
||||||
from app.utils.singleton import Singleton
|
from app.utils.singleton import Singleton
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
|
from core.event import eventmanager
|
||||||
|
from schemas import StorageOperSelectionEventData
|
||||||
|
|
||||||
downloader_lock = threading.Lock()
|
downloader_lock = threading.Lock()
|
||||||
job_lock = threading.Lock()
|
job_lock = threading.Lock()
|
||||||
@@ -703,6 +705,32 @@ class TransferChain(ChainBase, metaclass=Singleton):
|
|||||||
# 正在处理
|
# 正在处理
|
||||||
self.jobview.running_task(task)
|
self.jobview.running_task(task)
|
||||||
|
|
||||||
|
# 广播事件,请示额外的源存储支持
|
||||||
|
source_oper = None
|
||||||
|
source_storage = self.storagechain.get_storage(task.fileitem.storage)
|
||||||
|
source_event_data = StorageOperSelectionEventData(
|
||||||
|
storage_name=source_storage.name,
|
||||||
|
)
|
||||||
|
source_event = eventmanager.send_event(ChainEventType.StorageOperSelection, source_event_data)
|
||||||
|
# 使用事件返回的上下文数据
|
||||||
|
if source_event and source_event.event_data:
|
||||||
|
source_event_data: StorageOperSelectionEventData = source_event.event_data
|
||||||
|
if source_event_data.storage_oper:
|
||||||
|
source_oper = source_event_data.storage_oper
|
||||||
|
|
||||||
|
# 广播事件,请示额外的目标存储支持
|
||||||
|
target_oper = None
|
||||||
|
target_storage = self.storagechain.get_storage(task.target_storage)
|
||||||
|
target_event_data = StorageOperSelectionEventData(
|
||||||
|
storage_name=target_storage.name,
|
||||||
|
)
|
||||||
|
target_event = eventmanager.send_event(ChainEventType.StorageOperSelection, target_event_data)
|
||||||
|
# 使用事件返回的上下文数据
|
||||||
|
if target_event and target_event.event_data:
|
||||||
|
target_event_data: StorageOperSelectionEventData = target_event.event_data
|
||||||
|
if target_event_data.storage_oper:
|
||||||
|
target_oper = target_event_data.storage_oper
|
||||||
|
|
||||||
# 执行整理
|
# 执行整理
|
||||||
transferinfo: TransferInfo = self.transfer(fileitem=task.fileitem,
|
transferinfo: TransferInfo = self.transfer(fileitem=task.fileitem,
|
||||||
meta=task.meta,
|
meta=task.meta,
|
||||||
@@ -714,7 +742,9 @@ class TransferChain(ChainBase, metaclass=Singleton):
|
|||||||
episodes_info=task.episodes_info,
|
episodes_info=task.episodes_info,
|
||||||
scrape=task.scrape,
|
scrape=task.scrape,
|
||||||
library_type_folder=task.library_type_folder,
|
library_type_folder=task.library_type_folder,
|
||||||
library_category_folder=task.library_category_folder)
|
library_category_folder=task.library_category_folder,
|
||||||
|
source_oper=source_oper,
|
||||||
|
target_oper=target_oper)
|
||||||
if not transferinfo:
|
if not transferinfo:
|
||||||
logger.error("文件整理模块运行失败")
|
logger.error("文件整理模块运行失败")
|
||||||
return False, "文件整理模块运行失败"
|
return False, "文件整理模块运行失败"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Dict, Any, List, Set
|
from typing import Optional, Dict, Any, List, Set, Callable
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, root_validator
|
from pydantic import BaseModel, Field, root_validator
|
||||||
|
|
||||||
@@ -307,3 +307,21 @@ class MediaRecognizeConvertEventData(ChainEventData):
|
|||||||
|
|
||||||
# 输出参数
|
# 输出参数
|
||||||
media_dict: dict = Field(default=dict, description="转换后的媒体信息(TheMovieDb/豆瓣)")
|
media_dict: dict = Field(default=dict, description="转换后的媒体信息(TheMovieDb/豆瓣)")
|
||||||
|
|
||||||
|
|
||||||
|
class StorageOperSelectionEventData(ChainEventData):
|
||||||
|
"""
|
||||||
|
StorageOperSelect 事件的数据模型
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
# 输入参数
|
||||||
|
storage_name (str): 存储名称
|
||||||
|
|
||||||
|
# 输出参数
|
||||||
|
storage_oper (Callable): 存储操作对象
|
||||||
|
"""
|
||||||
|
# 输入参数
|
||||||
|
storage_name: str = Field(..., description="存储名称")
|
||||||
|
|
||||||
|
# 输出参数
|
||||||
|
storage_oper: Optional[Callable] = Field(default=None, description="存储操作对象")
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ class ChainEventType(Enum):
|
|||||||
RecommendSource = "recommend.source"
|
RecommendSource = "recommend.source"
|
||||||
# 工作流执行
|
# 工作流执行
|
||||||
WorkflowExecution = "workflow.execution"
|
WorkflowExecution = "workflow.execution"
|
||||||
|
# 存储操作选择
|
||||||
|
StorageOperSelection = "storage.operation"
|
||||||
|
|
||||||
|
|
||||||
# 系统配置Key字典
|
# 系统配置Key字典
|
||||||
|
|||||||
Reference in New Issue
Block a user