mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-11-03 22:04:57 +08:00
fix(workflow): handle absent media and unknown ratings
This commit is contained in:
@@ -4,6 +4,7 @@ from pydantic import Field
|
||||
|
||||
from app.runtime.log import logger
|
||||
from app.runtime.stop import runtime_stop_state
|
||||
from app.schemas.context import MediaInfo
|
||||
from app.schemas.workflow import ActionContext, ActionParams
|
||||
from app.workflow.actions import BaseAction
|
||||
|
||||
@@ -27,9 +28,10 @@ class FilterMediasAction(BaseAction):
|
||||
"outputs": [{"name": "medias", "label": "媒体", "kind": "list", "merge": "replace"}],
|
||||
}
|
||||
|
||||
def __init__(self, action_id: str):
|
||||
def __init__(self, action_id: str) -> None:
|
||||
"""初始化当前动作独立的执行状态。"""
|
||||
super().__init__(action_id)
|
||||
self._medias = []
|
||||
self._medias: list[MediaInfo] = []
|
||||
|
||||
name = "过滤媒体数据"
|
||||
description = "对媒体数据列表进行过滤"
|
||||
@@ -37,21 +39,24 @@ class FilterMediasAction(BaseAction):
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
"""返回当前动作是否已达到完成条件。"""
|
||||
return self.done
|
||||
|
||||
def execute(self, workflow_id: int, params: dict, context: ActionContext) -> ActionContext:
|
||||
def execute(self, workflow_id: int, params: dict[str, object], context: ActionContext) -> ActionContext:
|
||||
"""
|
||||
过滤medias中媒体数据
|
||||
"""
|
||||
params = FilterMediasParams(**params)
|
||||
for media in context.medias:
|
||||
action_params = FilterMediasParams(**params)
|
||||
for media in context.medias or []:
|
||||
if runtime_stop_state.is_workflow_stopped(workflow_id):
|
||||
break
|
||||
if params.type and media.type != params.type:
|
||||
if action_params.type and media.type != action_params.type:
|
||||
continue
|
||||
if params.vote is not None and media.vote_average < params.vote:
|
||||
if action_params.vote is not None and (
|
||||
media.vote_average is None or media.vote_average < action_params.vote
|
||||
):
|
||||
continue
|
||||
if params.year and media.year != params.year:
|
||||
if action_params.year and media.year != action_params.year:
|
||||
continue
|
||||
self._medias.append(media)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user