mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-07 00:16:57 +08:00
feat(event): add ResourceSelection event for update resource contexts
This commit is contained in:
+17
-1
@@ -20,7 +20,8 @@ from app.helper.message import MessageHelper
|
|||||||
from app.helper.torrent import TorrentHelper
|
from app.helper.torrent import TorrentHelper
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.schemas import ExistMediaInfo, NotExistMediaInfo, DownloadingTorrent, Notification
|
from app.schemas import ExistMediaInfo, NotExistMediaInfo, DownloadingTorrent, Notification
|
||||||
from app.schemas.types import MediaType, TorrentStatus, EventType, MessageChannel, NotificationType
|
from app.schemas.event import ResourceSelectionEventData
|
||||||
|
from app.schemas.types import MediaType, TorrentStatus, EventType, MessageChannel, NotificationType, ChainEventType
|
||||||
from app.utils.http import RequestUtils
|
from app.utils.http import RequestUtils
|
||||||
from app.utils.string import StringUtils
|
from app.utils.string import StringUtils
|
||||||
|
|
||||||
@@ -458,6 +459,21 @@ class DownloadChain(ChainBase):
|
|||||||
return 9999
|
return 9999
|
||||||
return no_exist[season].total_episode
|
return no_exist[season].total_episode
|
||||||
|
|
||||||
|
# 发送资源选择事件,允许外部修改上下文数据
|
||||||
|
logger.debug(f"Initial contexts: {len(contexts)} items, Downloader: {downloader}")
|
||||||
|
event_data = ResourceSelectionEventData(
|
||||||
|
contexts=contexts,
|
||||||
|
downloader=downloader
|
||||||
|
)
|
||||||
|
event = eventmanager.send_event(ChainEventType.ResourceSelection, event_data)
|
||||||
|
# 如果事件修改了上下文数据,使用更新后的数据
|
||||||
|
if event and event.event_data:
|
||||||
|
event_data: ResourceSelectionEventData = event.event_data
|
||||||
|
if event_data.updated and event_data.updated_contexts is not None:
|
||||||
|
logger.debug(f"Contexts updated by event: "
|
||||||
|
f"{len(event_data.updated_contexts)} items (source: {event_data.source})")
|
||||||
|
contexts = event_data.updated_contexts
|
||||||
|
|
||||||
# 分组排序
|
# 分组排序
|
||||||
contexts = TorrentHelper().sort_group_torrents(contexts)
|
contexts = TorrentHelper().sort_group_torrents(contexts)
|
||||||
|
|
||||||
|
|||||||
+27
-1
@@ -1,8 +1,10 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Dict, Any
|
from typing import Optional, Dict, Any, List
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, root_validator
|
from pydantic import BaseModel, Field, root_validator
|
||||||
|
|
||||||
|
from app.core.context import Context
|
||||||
|
|
||||||
|
|
||||||
class BaseEventData(BaseModel):
|
class BaseEventData(BaseModel):
|
||||||
"""
|
"""
|
||||||
@@ -143,3 +145,27 @@ class TransferRenameEventData(ChainEventData):
|
|||||||
updated: bool = Field(False, description="是否已更新")
|
updated: bool = Field(False, description="是否已更新")
|
||||||
updated_str: Optional[str] = Field(None, description="更新后的字符串")
|
updated_str: Optional[str] = Field(None, description="更新后的字符串")
|
||||||
source: Optional[str] = Field("未知拦截源", description="拦截源")
|
source: Optional[str] = Field("未知拦截源", description="拦截源")
|
||||||
|
|
||||||
|
|
||||||
|
class ResourceSelectionEventData(BaseModel):
|
||||||
|
"""
|
||||||
|
ResourceSelection 事件的数据模型
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
# 输入参数
|
||||||
|
contexts (List[Context]): 当前待选择的资源上下文列表
|
||||||
|
source (str): 事件源,指示事件的触发来源
|
||||||
|
|
||||||
|
# 输出参数
|
||||||
|
updated (bool): 是否已更新,默认值为 False
|
||||||
|
updated_contexts (Optional[List[Context]]): 已更新的资源上下文列表,默认值为 None
|
||||||
|
source (str): 更新源,默认值为 "未知更新源"
|
||||||
|
"""
|
||||||
|
# 输入参数
|
||||||
|
contexts: Any = Field(None, description="待选择的资源上下文列表")
|
||||||
|
downloader: Optional[str] = Field(None, description="下载器")
|
||||||
|
|
||||||
|
# 输出参数
|
||||||
|
updated: bool = Field(False, description="是否已更新")
|
||||||
|
updated_contexts: Optional[List[Context]] = Field(None, description="已更新的资源上下文列表")
|
||||||
|
source: Optional[str] = Field("未知拦截源", description="拦截源")
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ class ChainEventType(Enum):
|
|||||||
CommandRegister = "command.register"
|
CommandRegister = "command.register"
|
||||||
# 整理重命名
|
# 整理重命名
|
||||||
TransferRename = "transfer.rename"
|
TransferRename = "transfer.rename"
|
||||||
|
# 资源选择
|
||||||
|
ResourceSelection = "resource.selection"
|
||||||
|
|
||||||
|
|
||||||
# 系统配置Key字典
|
# 系统配置Key字典
|
||||||
|
|||||||
Reference in New Issue
Block a user